From f908a784c9a077e18ea9ea50d13e65b4233def7e Mon Sep 17 00:00:00 2001 From: joe Date: Mon, 28 Apr 2014 23:09:19 -0400 Subject: grok usage form spill/fill. Obsoletes the UsageTag paramter of PEMFile --- KeyRing.hs | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'KeyRing.hs') 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 , initializer :: Maybe String } +spillable :: StreamInfo -> Bool +spillable (spill -> KF_None) = False +spillable _ = True + isMutable :: StreamInfo -> Bool isMutable (fill -> KF_None) = False isMutable _ = True @@ -195,6 +199,10 @@ isring :: FileType -> Bool isring (KeyRingFile {}) = True isring _ = False +ispem :: FileType -> Bool +ispem (PEMFile {}) = True +ispem _ = False + pwfile :: FileType -> Maybe PassWordFile pwfile (KeyRingFile f) = f pwfile _ = Nothing @@ -203,11 +211,9 @@ iswallet :: FileType -> Bool iswallet (WalletFile {}) = True iswallet _ = False -getUsage :: - MonadPlus m => FileType -> m UsageTag -getUsage (PEMFile usage) = return usage -getUsage _ = mzero - +usageFromFilter :: MonadPlus m => KeyFilter -> m String +usageFromFilter (KF_Match usage) = return usage +usageFromFilter _ = mzero data KeyRingRuntime = KeyRingRuntime { rtPubring :: FilePath @@ -1023,9 +1029,14 @@ buildKeyDB doDecrypt secring pubring grip0 keyring = do let pems = do (n,stream) <- Map.toList $ kFiles keyring grip <- maybeToList grip - (topspec,subspec) <- fmap (parseSpec grip) $ getUsage (typ stream) n <- resolveInputFile secring pubring n - let ms = map fst $ filterMatches topspec (Map.toList db) + guard $ spillable stream && ispem (typ stream) + let us = mapMaybe usageFromFilter [fill stream,spill stream] + usage <- take 1 us + guard $ all (==usage) $ drop 1 us + -- TODO: KikiCondition for spill/fill usage mismatch? + let (topspec,subspec) = parseSpec grip usage + ms = map fst $ filterMatches topspec (Map.toList db) cmd = initializer stream return (n,subspec,ms,cmd) imports <- filterM (\(n,_,_,_) -> doesFileExist n) pems @@ -1609,11 +1620,12 @@ initializeMissingPEMFiles operation secring pubring grip decrypt db = do let (missing,notmissing) = partition (\(_,_,ns,_)->null (ns >>= snd)) $ do (fname,stream) <- nonexistents guard $ isMutable stream - (topspec,subspec) <- fmap (parseSpec $ fromMaybe "" grip) - $ getUsage $ typ stream - -- ms will contain duplicates if a top key has multiple matching - -- subkeys. This is intentional. - let -- ms = map (keykey . fst) $ selectAll True (topspec,subspec) db + guard $ ispem (typ stream) + usage <- usageFromFilter (fill stream) -- TODO: Error if no result? + let (topspec,subspec) = parseSpec (fromMaybe "" grip) usage + -- ms will contain duplicates if a top key has multiple matching + -- subkeys. This is intentional. + -- ms = map (keykey . fst) $ selectAll True (topspec,subspec) db -- ms = filterMatches topspec $ Map.toList db ns = do (kk,kd) <- filterMatches topspec $ Map.toList db -- cgit v1.2.3