diff options
author | joe <joe@jerkface.net> | 2013-11-29 17:32:59 -0500 |
---|---|---|
committer | joe <joe@jerkface.net> | 2013-11-29 17:32:59 -0500 |
commit | 7d742f00c253b3dd916d2f18b24b5a159ebaa6ad (patch) | |
tree | c724102a726dbfe3cdff0d18dce406ce627db055 | |
parent | fedc150af98d7ba9f29aa3307952580079ac8646 (diff) |
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.
-rw-r--r-- | kiki.hs | 30 |
1 files changed, 14 insertions, 16 deletions
@@ -825,7 +825,7 @@ is40digitHex xs = ys == xs && length ys==40 | |||
825 | scanPackets [] = [] | 825 | scanPackets [] = [] |
826 | scanPackets (p:ps) = scanl doit (doit (MarkerPacket,MarkerPacket,ret MarkerPacket) p) ps | 826 | scanPackets (p:ps) = scanl doit (doit (MarkerPacket,MarkerPacket,ret MarkerPacket) p) ps |
827 | where | 827 | where |
828 | ret p = (p,Nothing,Nothing) | 828 | ret p = (p,Map.empty) |
829 | doit (top,sub,prev) p = | 829 | doit (top,sub,prev) p = |
830 | case p of | 830 | case p of |
831 | _ | isKey p && not (is_subkey p) -> (p,MarkerPacket,ret p) | 831 | _ | isKey p && not (is_subkey p) -> (p,MarkerPacket,ret p) |
@@ -834,14 +834,13 @@ scanPackets (p:ps) = scanl doit (doit (MarkerPacket,MarkerPacket,ret MarkerPacke | |||
834 | _ | isTrust p -> (top,sub,updateTrust top sub prev p) | 834 | _ | isTrust p -> (top,sub,updateTrust top sub prev p) |
835 | _ | otherwise -> (top,sub,ret p) | 835 | _ | otherwise -> (top,sub,ret p) |
836 | 836 | ||
837 | updateTrust top (PublicKeyPacket {}) (pre,a,b) p = (pre,a,Just p) | 837 | updateTrust top (PublicKeyPacket {}) (pre,t) p = (pre,Map.insert "public" p t) |
838 | updateTrust (PublicKeyPacket {}) _ (pre,a,b) p = (pre,a,Just p) | 838 | updateTrust (PublicKeyPacket {}) _ (pre,t) p = (pre,Map.insert "public" p t) |
839 | updateTrust _ _ (pre,a,b) p = (pre,Just p,b) | 839 | updateTrust _ _ (pre,t) p = (pre,Map.insert "secret" p t) |
840 | 840 | ||
841 | 841 | ||
842 | type SigAndTrust = ( Packet | 842 | type SigAndTrust = ( Packet |
843 | , Maybe Packet -- secret trust packet | 843 | , Map.Map FilePath Packet ) -- trust packets |
844 | , Maybe Packet) -- public trust packet | ||
845 | 844 | ||
846 | type KeyKey = [Char8.ByteString] | 845 | type KeyKey = [Char8.ByteString] |
847 | data SubKey = SubKey Packet [SigAndTrust] | 846 | data SubKey = SubKey Packet [SigAndTrust] |
@@ -882,7 +881,7 @@ merge db (Message ps) = foldl mergeit db qs | |||
882 | where | 881 | where |
883 | qs = scanPackets ps | 882 | qs = scanPackets ps |
884 | -- mergeit db (_,_,TrustPacket {}) = db -- Filter TrustPackets | 883 | -- mergeit db (_,_,TrustPacket {}) = db -- Filter TrustPackets |
885 | mergeit db (top,sub,ptt@(p,sectrust,pubtrust)) | isKey top = Map.alter update (keykey top) db | 884 | mergeit db (top,sub,ptt@(p,trustmap)) | isKey top = Map.alter update (keykey top) db |
886 | where | 885 | where |
887 | update v | isKey p && not (is_subkey p) | 886 | update v | isKey p && not (is_subkey p) |
888 | = case v of | 887 | = case v of |
@@ -915,11 +914,11 @@ merge db (Message ps) = foldl mergeit db qs | |||
915 | mergeSubkey p (Just (SubKey key sigs)) = Just $ | 914 | mergeSubkey p (Just (SubKey key sigs)) = Just $ |
916 | SubKey (minimumBy subcomp [key,p]) sigs | 915 | SubKey (minimumBy subcomp [key,p]) sigs |
917 | 916 | ||
918 | mergeUid (UserIDPacket s,_,_) Nothing = Just [] | 917 | mergeUid (UserIDPacket s,_) Nothing = Just [] |
919 | mergeUid (UserIDPacket s,_,_) (Just sigs) = Just sigs | 918 | mergeUid (UserIDPacket s,_) (Just sigs) = Just sigs |
920 | mergeUid p _ = error $ "Unable to merge into UID record: " ++whatP p | 919 | mergeUid p _ = error $ "Unable to merge into UID record: " ++whatP p |
921 | 920 | ||
922 | whatP (a,_,_) = concat . take 1 . words . show $ a | 921 | whatP (a,_) = concat . take 1 . words . show $ a |
923 | 922 | ||
924 | 923 | ||
925 | mergeSig sig sigs = | 924 | mergeSig sig sigs = |
@@ -930,15 +929,14 @@ merge db (Message ps) = foldl mergeit db qs | |||
930 | in xs ++ (mergeSameSig sig y : ys') | 929 | in xs ++ (mergeSameSig sig y : ys') |
931 | 930 | ||
932 | 931 | ||
933 | isSameSig (a,_,_) (b,_,_) | isSignaturePacket a && isSignaturePacket b = | 932 | isSameSig (a,_) (b,_) | isSignaturePacket a && isSignaturePacket b = |
934 | a { unhashed_subpackets=[] } == b { unhashed_subpackets = [] } | 933 | a { unhashed_subpackets=[] } == b { unhashed_subpackets = [] } |
935 | isSameSig (a,_,_) (b,_,_) = a==b | 934 | isSameSig (a,_) (b,_) = a==b |
936 | 935 | ||
937 | mergeSameSig (a,sa,pa) (b,sb,pb) | isSignaturePacket a && isSignaturePacket b = | 936 | mergeSameSig (a,ta) (b,tb) | isSignaturePacket a && isSignaturePacket b = |
938 | ( b { unhashed_subpackets = | 937 | ( b { unhashed_subpackets = |
939 | foldl mergeItem (unhashed_subpackets b) (unhashed_subpackets a) } | 938 | foldl mergeItem (unhashed_subpackets b) (unhashed_subpackets a) } |
940 | , sb `mplus` sa | 939 | , tb `Map.union` ta ) |
941 | , pb `mplus` pa ) | ||
942 | 940 | ||
943 | where | 941 | where |
944 | mergeItem ys x = if x `elem` ys then ys else ys++[x] | 942 | 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 | |||
964 | flattenSub (_,SubKey key sigs) = unk key: concatMap unsig sigs | 962 | flattenSub (_,SubKey key sigs) = unk key: concatMap unsig sigs |
965 | 963 | ||
966 | unk k = if isPublic then secretToPublic k else k | 964 | unk k = if isPublic then secretToPublic k else k |
967 | unsig (sig,sectrust,pubtrust) = [sig]++maybeToList (if isPublic then pubtrust else sectrust) | 965 | unsig (sig,trustmap) = [sig]++maybeToList (Map.lookup (if isPublic then "public" else "secret") trustmap) |
968 | 966 | ||
969 | prefilter = if isPublic then id else filter isSecret | 967 | prefilter = if isPublic then id else filter isSecret |
970 | where isSecret (_,(KeyData (SecretKeyPacket {}) _ _ _)) = True | 968 | where isSecret (_,(KeyData (SecretKeyPacket {}) _ _ _)) = True |