From 7d742f00c253b3dd916d2f18b24b5a159ebaa6ad Mon Sep 17 00:00:00 2001 From: joe Date: Fri, 29 Nov 2013 17:32:59 -0500 Subject: Re-implemented public/secret trust packet catagorization to use a Data.Map lookup structure. This will ease the transition to categorizing trust packets based on file name rather than on whether they came from public or secret keyrings. --- kiki.hs | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'kiki.hs') diff --git a/kiki.hs b/kiki.hs index 059fc50..4f79095 100644 --- a/kiki.hs +++ b/kiki.hs @@ -825,7 +825,7 @@ is40digitHex xs = ys == xs && length ys==40 scanPackets [] = [] scanPackets (p:ps) = scanl doit (doit (MarkerPacket,MarkerPacket,ret MarkerPacket) p) ps where - ret p = (p,Nothing,Nothing) + ret p = (p,Map.empty) doit (top,sub,prev) p = case p of _ | isKey p && not (is_subkey p) -> (p,MarkerPacket,ret p) @@ -834,14 +834,13 @@ scanPackets (p:ps) = scanl doit (doit (MarkerPacket,MarkerPacket,ret MarkerPacke _ | isTrust p -> (top,sub,updateTrust top sub prev p) _ | otherwise -> (top,sub,ret p) - updateTrust top (PublicKeyPacket {}) (pre,a,b) p = (pre,a,Just p) - updateTrust (PublicKeyPacket {}) _ (pre,a,b) p = (pre,a,Just p) - updateTrust _ _ (pre,a,b) p = (pre,Just p,b) + updateTrust top (PublicKeyPacket {}) (pre,t) p = (pre,Map.insert "public" p t) + updateTrust (PublicKeyPacket {}) _ (pre,t) p = (pre,Map.insert "public" p t) + updateTrust _ _ (pre,t) p = (pre,Map.insert "secret" p t) type SigAndTrust = ( Packet - , Maybe Packet -- secret trust packet - , Maybe Packet) -- public trust packet + , Map.Map FilePath Packet ) -- trust packets type KeyKey = [Char8.ByteString] data SubKey = SubKey Packet [SigAndTrust] @@ -882,7 +881,7 @@ merge db (Message ps) = foldl mergeit db qs where qs = scanPackets ps -- mergeit db (_,_,TrustPacket {}) = db -- Filter TrustPackets - mergeit db (top,sub,ptt@(p,sectrust,pubtrust)) | isKey top = Map.alter update (keykey top) db + mergeit db (top,sub,ptt@(p,trustmap)) | isKey top = Map.alter update (keykey top) db where update v | isKey p && not (is_subkey p) = case v of @@ -915,11 +914,11 @@ merge db (Message ps) = foldl mergeit db qs mergeSubkey p (Just (SubKey key sigs)) = Just $ SubKey (minimumBy subcomp [key,p]) sigs - mergeUid (UserIDPacket s,_,_) Nothing = Just [] - mergeUid (UserIDPacket s,_,_) (Just sigs) = Just sigs + mergeUid (UserIDPacket s,_) Nothing = Just [] + mergeUid (UserIDPacket s,_) (Just sigs) = Just sigs mergeUid p _ = error $ "Unable to merge into UID record: " ++whatP p - whatP (a,_,_) = concat . take 1 . words . show $ a + whatP (a,_) = concat . take 1 . words . show $ a mergeSig sig sigs = @@ -930,15 +929,14 @@ merge db (Message ps) = foldl mergeit db qs in xs ++ (mergeSameSig sig y : ys') - isSameSig (a,_,_) (b,_,_) | isSignaturePacket a && isSignaturePacket b = + isSameSig (a,_) (b,_) | isSignaturePacket a && isSignaturePacket b = a { unhashed_subpackets=[] } == b { unhashed_subpackets = [] } - isSameSig (a,_,_) (b,_,_) = a==b + isSameSig (a,_) (b,_) = a==b - mergeSameSig (a,sa,pa) (b,sb,pb) | isSignaturePacket a && isSignaturePacket b = + mergeSameSig (a,ta) (b,tb) | isSignaturePacket a && isSignaturePacket b = ( b { unhashed_subpackets = foldl mergeItem (unhashed_subpackets b) (unhashed_subpackets a) } - , sb `mplus` sa - , pb `mplus` pa ) + , tb `Map.union` ta ) where mergeItem ys x = if x `elem` ys then ys else ys++[x] @@ -964,7 +962,7 @@ flattenKeys isPublic db = Message $ concatMap flattenTop (prefilter . Map.assocs flattenSub (_,SubKey key sigs) = unk key: concatMap unsig sigs unk k = if isPublic then secretToPublic k else k - unsig (sig,sectrust,pubtrust) = [sig]++maybeToList (if isPublic then pubtrust else sectrust) + unsig (sig,trustmap) = [sig]++maybeToList (Map.lookup (if isPublic then "public" else "secret") trustmap) prefilter = if isPublic then id else filter isSecret where isSecret (_,(KeyData (SecretKeyPacket {}) _ _ _)) = True -- cgit v1.2.3