From e1db68cc5f63b7fb05cc55dfdd1895320f7062e1 Mon Sep 17 00:00:00 2001 From: joe Date: Tue, 29 Apr 2014 20:44:50 -0400 Subject: allow non-filepath keyring input. --- KeyRing.hs | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'KeyRing.hs') diff --git a/KeyRing.hs b/KeyRing.hs index 8c57d96..0cdb36f 100644 --- a/KeyRing.hs +++ b/KeyRing.hs @@ -855,6 +855,12 @@ getInputFileTime ctx (resolveInputFile ctx -> [fname]) = do handleIO_ (error $ fname++": modificaiton time?") $ modificationTime <$> getFileStatus fname +doesInputFileExist :: InputFileContext -> InputFile -> IO Bool +doesInputFileExist ctx f = do + case resolveInputFile ctx f of + [n] -> doesFileExist n + _ -> return True + cachedContents :: InputFileContext -> InputFile -> IO (IO S.ByteString) cachedContents ctx fd = do @@ -1004,12 +1010,12 @@ buildKeyDB doDecrypt ctx grip0 keyring = do filesAccs isring = do (f,stream) <- Map.toList (kFiles keyring) guard (isring $ typ stream) - n <- resolveInputFile ctx f - return (n, access stream) + -- n <- resolveInputFile ctx f + return (f, access stream) - readp (n,acc) = fmap readp0 $ readPacketsFromFile ctx (ArgFile n) + readp (f,acc) = fmap readp0 $ readPacketsFromFile ctx f where - readp0 ps = ((n,acc'),ps) + readp0 ps = ((f,acc'),ps) where acc' = case acc of AutoAccess -> case ps of @@ -1037,17 +1043,17 @@ buildKeyDB doDecrypt ctx grip0 keyring = do let grip = grip0 `mplus` (fingerprint <$> fstkey) where fstkey = listToMaybe $ mapMaybe isSecringKey ms - where isSecringKey ((fn,_),Message ps) - | fn==homesecPath ctx = listToMaybe ps - isSecringKey _ = Nothing - db_rings = foldl' (\db ((fname,_),ps) -> merge db fname ps) Map.empty ms - + where isSecringKey ((HomeSec,_),Message ps) + = listToMaybe ps + isSecringKey _ = Nothing + db_rings = foldl' mergeIt Map.empty ms + where mergeIt db ((f,_),ps) = merge db f ps wk = listToMaybe $ do fp <- maybeToList grip elm <- Map.toList db_rings guard $ matchSpec (KeyGrip fp) elm return $ keyMappedPacket (snd elm) - accs = map fst ms + accs = map (first (concat . resolveInputFile ctx) . fst) ms return (db_rings,wk,grip,Map.fromList accs) let wk = fmap packet mwk @@ -2224,9 +2230,11 @@ keykey key = uidkey :: Packet -> String uidkey (UserIDPacket str) = str -merge :: KeyDB -> FilePath -> Message -> KeyDB -merge db filename (Message ps) = merge_ db filename qs +merge :: KeyDB -> InputFile -> Message -> KeyDB +merge db inputfile (Message ps) = merge_ db filename qs where + filename = concat $ resolveInputFile (InputFileContext "&secret" "&public") inputfile + qs = scanPackets filename ps scanPackets :: FilePath -> [Packet] -> [(Packet,Packet,(Packet,Map.Map FilePath Packet))] -- cgit v1.2.3