summaryrefslogtreecommitdiff
path: root/lib/Types.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Types.hs')
-rw-r--r--lib/Types.hs38
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 #-}
2module Types where 2module Types where
3 3
4import Data.Map as Map (Map) 4import Data.Map as Map (Map)
5import qualified Data.Map as Map
5import Data.OpenPGP 6import Data.OpenPGP
6import Data.OpenPGP.Util 7import Data.OpenPGP.Util
7import FunctorToMaybe 8import FunctorToMaybe
8import qualified System.Posix.Types as Posix
9import qualified Data.ByteString.Lazy as L 9import qualified Data.ByteString.Lazy as L
10import 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
199instance Functor OriginMapped where 200instance 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
203origin :: Packet -> Int -> OriginFlags
204origin p n = OriginFlags ispub n
205 where
206 ispub = case p of
207 SecretKeyPacket {} -> False
208 _ -> True
209
210mappedPacket :: FilePath -> Packet -> MappedPacket
211mappedPacket filename p = MappedPacket
212 { packet = p
213 , locations = Map.singleton filename (origin p (-1))
214 }
215
216mappedPacketWithHint :: FilePath -> Packet -> Int -> MappedPacket
217mappedPacketWithHint 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
252isKey (SecretKeyPacket {}) = True 273isKey (SecretKeyPacket {}) = True
253isKey _ = False 274isKey _ = False
254 275
276isSecretKey :: Packet -> Bool
277isSecretKey (SecretKeyPacket {}) = True
278isSecretKey _ = False
279
280
255isUserID :: Packet -> Bool 281isUserID :: Packet -> Bool
256isUserID (UserIDPacket {}) = True 282isUserID (UserIDPacket {}) = True
257isUserID _ = False 283isUserID _ = False
@@ -260,4 +286,12 @@ isTrust :: Packet -> Bool
260isTrust (TrustPacket {}) = True 286isTrust (TrustPacket {}) = True
261isTrust _ = False 287isTrust _ = 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--
294matchpr :: String -> Packet -> String
295matchpr fp k = reverse $ zipWith const (reverse (fingerprint k)) fp
296
263 297