summaryrefslogtreecommitdiff
path: root/lib/KeyDB.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/KeyDB.hs')
-rw-r--r--lib/KeyDB.hs27
1 files changed, 19 insertions, 8 deletions
diff --git a/lib/KeyDB.hs b/lib/KeyDB.hs
index fd0a9ce..fc20b91 100644
--- a/lib/KeyDB.hs
+++ b/lib/KeyDB.hs
@@ -4,7 +4,7 @@ module KeyDB
4 , SigAndTrust 4 , SigAndTrust
5 , SubKey(..) 5 , SubKey(..)
6 , KeyData(..) 6 , KeyData(..)
7 , KeyDB 7 , KeyDB(..)
8 , KeyGrip(..) 8 , KeyGrip(..)
9 , emptyKeyDB 9 , emptyKeyDB
10 , keyData 10 , keyData
@@ -68,6 +68,7 @@ data KeyData = KeyData
68 68
69 69
70newtype KeyGrip = KeyInt Int 70newtype KeyGrip = KeyInt Int
71 deriving Eq
71 72
72fingerprintGrip :: Fingerprint -> KeyGrip 73fingerprintGrip :: Fingerprint -> KeyGrip
73fingerprintGrip (Fingerprint bs) = 74fingerprintGrip (Fingerprint bs) =
@@ -109,10 +110,20 @@ kkData db = Map.toList (byKeyKey db)
109lookupKeyData :: KeyKey -> KeyDB -> Maybe KeyData 110lookupKeyData :: KeyKey -> KeyDB -> Maybe KeyData
110lookupKeyData kk db = Map.lookup kk (byKeyKey db) 111lookupKeyData kk db = Map.lookup kk (byKeyKey db)
111 112
112lookupByGrip :: KeyGrip -> KeyDB -> [KeyData] 113lookupByGrip :: KeyGrip -> KeyDB -> [(MappedPacket,KeyData)]
113lookupByGrip k db = mapMaybe (`Map.lookup` byKeyKey db) 114lookupByGrip k db = do
114 $ concat . maybeToList 115 kk <- concat $ maybeToList $ I.lookup k (byGrip db)
115 $ I.lookup k (byGrip db) 116 case Map.lookup kk (byKeyKey db) of
117 Just kd | fingerprintGrip (fingerprint (packet $ keyMappedPacket kd)) == k -> [(keyMappedPacket kd, kd)]
118 | otherwise -> do
119 sub <- associatedKeys kd
120 guard (mpGrip sub == k)
121 [ (sub, kd) ]
122 Nothing -> do
123 kd <- Map.elems (byKeyKey db)
124 sub <- associatedKeys kd
125 guard (mpGrip sub == k)
126 [ (sub, kd) ]
116 127
117transmute :: (Monad m, Monad kiki, Traversable kiki) => 128transmute :: (Monad m, Monad kiki, Traversable kiki) =>
118 ((KeyData, [info]) -> opcode -> m (kiki (KeyData, [info]))) -- ^ interpreter 129 ((KeyData, [info]) -> opcode -> m (kiki (KeyData, [info]))) -- ^ interpreter
@@ -137,14 +148,14 @@ associatedKeys kd = keyMappedPacket kd : [ k | SubKey k _ <- Map.elems (keySubKe
137alterKeyDB :: (Maybe KeyData -> Maybe KeyData) -> KeyKey -> KeyDB -> KeyDB 148alterKeyDB :: (Maybe KeyData -> Maybe KeyData) -> KeyKey -> KeyDB -> KeyDB
138alterKeyDB update kk db = db 149alterKeyDB update kk db = db
139 { byKeyKey = Map.alter update kk (byKeyKey db) 150 { byKeyKey = Map.alter update kk (byKeyKey db)
140 , byGrip = case Map.lookup kk (byKeyKey db) of 151 , byGrip = {- case Map.lookup kk (byKeyKey db) of
141 Just _ -> byGrip db 152 Just _ -> byGrip db
142 Nothing -> case update Nothing of 153 Nothing -> -} case update Nothing of
143 Just kd -> let go g m = I.alter (\case Nothing -> Just [kk] 154 Just kd -> let go g m = I.alter (\case Nothing -> Just [kk]
144 Just kks -> Just $ mergeL [kk] kks) 155 Just kks -> Just $ mergeL [kk] kks)
145 g 156 g
146 m 157 m
147 in foldr go (byGrip db) $ map mpGrip $ associatedKeys kd 158 in foldr go (byGrip db) $ map mpGrip $ filter (isKey . packet) $ associatedKeys kd
148 Nothing -> byGrip db 159 Nothing -> byGrip db
149 } 160 }
150 161