summaryrefslogtreecommitdiff
path: root/KeyRing.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-04-28 23:09:19 -0400
committerjoe <joe@jerkface.net>2014-04-28 23:09:19 -0400
commitf908a784c9a077e18ea9ea50d13e65b4233def7e (patch)
treefd47a21d6011de73b805754472ce870bc1b1b2a9 /KeyRing.hs
parent7ce285bc7d22866b5ac9955cd9de8b83a83e6677 (diff)
grok usage form spill/fill. Obsoletes the UsageTag paramter of PEMFile
Diffstat (limited to 'KeyRing.hs')
-rw-r--r--KeyRing.hs36
1 files changed, 24 insertions, 12 deletions
diff --git a/KeyRing.hs b/KeyRing.hs
index 4f6ee46..c14343f 100644
--- a/KeyRing.hs
+++ b/KeyRing.hs
@@ -187,6 +187,10 @@ data StreamInfo = StreamInfo
187 , initializer :: Maybe String } 187 , initializer :: Maybe String }
188 188
189 189
190spillable :: StreamInfo -> Bool
191spillable (spill -> KF_None) = False
192spillable _ = True
193
190isMutable :: StreamInfo -> Bool 194isMutable :: StreamInfo -> Bool
191isMutable (fill -> KF_None) = False 195isMutable (fill -> KF_None) = False
192isMutable _ = True 196isMutable _ = True
@@ -195,6 +199,10 @@ isring :: FileType -> Bool
195isring (KeyRingFile {}) = True 199isring (KeyRingFile {}) = True
196isring _ = False 200isring _ = False
197 201
202ispem :: FileType -> Bool
203ispem (PEMFile {}) = True
204ispem _ = False
205
198pwfile :: FileType -> Maybe PassWordFile 206pwfile :: FileType -> Maybe PassWordFile
199pwfile (KeyRingFile f) = f 207pwfile (KeyRingFile f) = f
200pwfile _ = Nothing 208pwfile _ = Nothing
@@ -203,11 +211,9 @@ iswallet :: FileType -> Bool
203iswallet (WalletFile {}) = True 211iswallet (WalletFile {}) = True
204iswallet _ = False 212iswallet _ = False
205 213
206getUsage :: 214usageFromFilter :: MonadPlus m => KeyFilter -> m String
207 MonadPlus m => FileType -> m UsageTag 215usageFromFilter (KF_Match usage) = return usage
208getUsage (PEMFile usage) = return usage 216usageFromFilter _ = mzero
209getUsage _ = mzero
210
211 217
212data KeyRingRuntime = KeyRingRuntime 218data KeyRingRuntime = KeyRingRuntime
213 { rtPubring :: FilePath 219 { rtPubring :: FilePath
@@ -1023,9 +1029,14 @@ buildKeyDB doDecrypt secring pubring grip0 keyring = do
1023 let pems = do 1029 let pems = do
1024 (n,stream) <- Map.toList $ kFiles keyring 1030 (n,stream) <- Map.toList $ kFiles keyring
1025 grip <- maybeToList grip 1031 grip <- maybeToList grip
1026 (topspec,subspec) <- fmap (parseSpec grip) $ getUsage (typ stream)
1027 n <- resolveInputFile secring pubring n 1032 n <- resolveInputFile secring pubring n
1028 let ms = map fst $ filterMatches topspec (Map.toList db) 1033 guard $ spillable stream && ispem (typ stream)
1034 let us = mapMaybe usageFromFilter [fill stream,spill stream]
1035 usage <- take 1 us
1036 guard $ all (==usage) $ drop 1 us
1037 -- TODO: KikiCondition for spill/fill usage mismatch?
1038 let (topspec,subspec) = parseSpec grip usage
1039 ms = map fst $ filterMatches topspec (Map.toList db)
1029 cmd = initializer stream 1040 cmd = initializer stream
1030 return (n,subspec,ms,cmd) 1041 return (n,subspec,ms,cmd)
1031 imports <- filterM (\(n,_,_,_) -> doesFileExist n) pems 1042 imports <- filterM (\(n,_,_,_) -> doesFileExist n) pems
@@ -1609,11 +1620,12 @@ initializeMissingPEMFiles operation secring pubring grip decrypt db = do
1609 let (missing,notmissing) = partition (\(_,_,ns,_)->null (ns >>= snd)) $ do 1620 let (missing,notmissing) = partition (\(_,_,ns,_)->null (ns >>= snd)) $ do
1610 (fname,stream) <- nonexistents 1621 (fname,stream) <- nonexistents
1611 guard $ isMutable stream 1622 guard $ isMutable stream
1612 (topspec,subspec) <- fmap (parseSpec $ fromMaybe "" grip) 1623 guard $ ispem (typ stream)
1613 $ getUsage $ typ stream 1624 usage <- usageFromFilter (fill stream) -- TODO: Error if no result?
1614 -- ms will contain duplicates if a top key has multiple matching 1625 let (topspec,subspec) = parseSpec (fromMaybe "" grip) usage
1615 -- subkeys. This is intentional. 1626 -- ms will contain duplicates if a top key has multiple matching
1616 let -- ms = map (keykey . fst) $ selectAll True (topspec,subspec) db 1627 -- subkeys. This is intentional.
1628 -- ms = map (keykey . fst) $ selectAll True (topspec,subspec) db
1617 -- ms = filterMatches topspec $ Map.toList db 1629 -- ms = filterMatches topspec $ Map.toList db
1618 ns = do 1630 ns = do
1619 (kk,kd) <- filterMatches topspec $ Map.toList db 1631 (kk,kd) <- filterMatches topspec $ Map.toList db