diff options
author | joe <joe@jerkface.net> | 2016-08-29 01:15:25 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2016-08-29 01:15:25 -0400 |
commit | 1eff837423de69ece2a85430a7ad433b7c1a504a (patch) | |
tree | c2c7d6e83e9589de72b29924f6cb2354107d0d0e /lib/Types.hs | |
parent | 7a579e7b82a2f5707af77f4a7101ce72e57635ac (diff) |
Better gpg-agent support.
Diffstat (limited to 'lib/Types.hs')
-rw-r--r-- | lib/Types.hs | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/lib/Types.hs b/lib/Types.hs index 9aa0340..767ee98 100644 --- a/lib/Types.hs +++ b/lib/Types.hs | |||
@@ -1,12 +1,13 @@ | |||
1 | {-# LANGUAGE DeriveFunctor #-} | 1 | {-# LANGUAGE DeriveFunctor #-} |
2 | module Types where | 2 | module Types where |
3 | 3 | ||
4 | import Data.Map as Map (Map) | 4 | import Data.Map as Map (Map) |
5 | import qualified Data.Map as Map | ||
5 | import Data.OpenPGP | 6 | import Data.OpenPGP |
6 | import Data.OpenPGP.Util | 7 | import Data.OpenPGP.Util |
7 | import FunctorToMaybe | 8 | import FunctorToMaybe |
8 | import qualified System.Posix.Types as Posix | ||
9 | import qualified Data.ByteString.Lazy as L | 9 | import qualified Data.ByteString.Lazy as L |
10 | import qualified System.Posix.Types as Posix | ||
10 | 11 | ||
11 | -- | This type describes an idempotent transformation (merge or import) on a | 12 | -- | This type describes an idempotent transformation (merge or import) on a |
12 | -- set of GnuPG keyrings and other key files. | 13 | -- set of GnuPG keyrings and other key files. |
@@ -199,6 +200,26 @@ data OriginMapped a = MappedPacket | |||
199 | instance Functor OriginMapped where | 200 | instance Functor OriginMapped where |
200 | fmap f (MappedPacket x ls) = MappedPacket (f x) ls | 201 | fmap f (MappedPacket x ls) = MappedPacket (f x) ls |
201 | 202 | ||
203 | origin :: Packet -> Int -> OriginFlags | ||
204 | origin p n = OriginFlags ispub n | ||
205 | where | ||
206 | ispub = case p of | ||
207 | SecretKeyPacket {} -> False | ||
208 | _ -> True | ||
209 | |||
210 | mappedPacket :: FilePath -> Packet -> MappedPacket | ||
211 | mappedPacket filename p = MappedPacket | ||
212 | { packet = p | ||
213 | , locations = Map.singleton filename (origin p (-1)) | ||
214 | } | ||
215 | |||
216 | mappedPacketWithHint :: FilePath -> Packet -> Int -> MappedPacket | ||
217 | mappedPacketWithHint filename p hint = MappedPacket | ||
218 | { packet = p | ||
219 | , locations = Map.singleton filename (origin p hint) | ||
220 | } | ||
221 | |||
222 | |||
202 | -- | This type is used to indicate success or failure | 223 | -- | This type is used to indicate success or failure |
203 | -- and in the case of success, return the computed object. | 224 | -- and in the case of success, return the computed object. |
204 | -- The 'FunctorToMaybe' class is implemented to facilitate | 225 | -- The 'FunctorToMaybe' class is implemented to facilitate |
@@ -252,6 +273,11 @@ isKey (PublicKeyPacket {}) = True | |||
252 | isKey (SecretKeyPacket {}) = True | 273 | isKey (SecretKeyPacket {}) = True |
253 | isKey _ = False | 274 | isKey _ = False |
254 | 275 | ||
276 | isSecretKey :: Packet -> Bool | ||
277 | isSecretKey (SecretKeyPacket {}) = True | ||
278 | isSecretKey _ = False | ||
279 | |||
280 | |||
255 | isUserID :: Packet -> Bool | 281 | isUserID :: Packet -> Bool |
256 | isUserID (UserIDPacket {}) = True | 282 | isUserID (UserIDPacket {}) = True |
257 | isUserID _ = False | 283 | isUserID _ = False |
@@ -260,4 +286,12 @@ isTrust :: Packet -> Bool | |||
260 | isTrust (TrustPacket {}) = True | 286 | isTrust (TrustPacket {}) = True |
261 | isTrust _ = False | 287 | isTrust _ = False |
262 | 288 | ||
289 | -- matchpr computes the fingerprint of the given key truncated to | ||
290 | -- be the same lenght as the given fingerprint for comparison. | ||
291 | -- | ||
292 | -- matchpr fp = Data.List.Extra.takeEnd (length fp) | ||
293 | -- | ||
294 | matchpr :: String -> Packet -> String | ||
295 | matchpr fp k = reverse $ zipWith const (reverse (fingerprint k)) fp | ||
296 | |||
263 | 297 | ||