summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-04-29 20:44:50 -0400
committerjoe <joe@jerkface.net>2014-04-29 20:44:50 -0400
commite1db68cc5f63b7fb05cc55dfdd1895320f7062e1 (patch)
tree8417ce6193ba77957630950d1fbdd007a7adad82
parent616b0bf9d80258b9b7f10d7777a6043a4b5be3be (diff)
allow non-filepath keyring input.
-rw-r--r--KeyRing.hs32
1 files changed, 20 insertions, 12 deletions
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
855 handleIO_ (error $ fname++": modificaiton time?") $ 855 handleIO_ (error $ fname++": modificaiton time?") $
856 modificationTime <$> getFileStatus fname 856 modificationTime <$> getFileStatus fname
857 857
858doesInputFileExist :: InputFileContext -> InputFile -> IO Bool
859doesInputFileExist ctx f = do
860 case resolveInputFile ctx f of
861 [n] -> doesFileExist n
862 _ -> return True
863
858 864
859cachedContents :: InputFileContext -> InputFile -> IO (IO S.ByteString) 865cachedContents :: InputFileContext -> InputFile -> IO (IO S.ByteString)
860cachedContents ctx fd = do 866cachedContents ctx fd = do
@@ -1004,12 +1010,12 @@ buildKeyDB doDecrypt ctx grip0 keyring = do
1004 filesAccs isring = do 1010 filesAccs isring = do
1005 (f,stream) <- Map.toList (kFiles keyring) 1011 (f,stream) <- Map.toList (kFiles keyring)
1006 guard (isring $ typ stream) 1012 guard (isring $ typ stream)
1007 n <- resolveInputFile ctx f 1013 -- n <- resolveInputFile ctx f
1008 return (n, access stream) 1014 return (f, access stream)
1009 1015
1010 readp (n,acc) = fmap readp0 $ readPacketsFromFile ctx (ArgFile n) 1016 readp (f,acc) = fmap readp0 $ readPacketsFromFile ctx f
1011 where 1017 where
1012 readp0 ps = ((n,acc'),ps) 1018 readp0 ps = ((f,acc'),ps)
1013 where acc' = case acc of 1019 where acc' = case acc of
1014 AutoAccess -> 1020 AutoAccess ->
1015 case ps of 1021 case ps of
@@ -1037,17 +1043,17 @@ buildKeyDB doDecrypt ctx grip0 keyring = do
1037 let grip = grip0 `mplus` (fingerprint <$> fstkey) 1043 let grip = grip0 `mplus` (fingerprint <$> fstkey)
1038 where 1044 where
1039 fstkey = listToMaybe $ mapMaybe isSecringKey ms 1045 fstkey = listToMaybe $ mapMaybe isSecringKey ms
1040 where isSecringKey ((fn,_),Message ps) 1046 where isSecringKey ((HomeSec,_),Message ps)
1041 | fn==homesecPath ctx = listToMaybe ps 1047 = listToMaybe ps
1042 isSecringKey _ = Nothing 1048 isSecringKey _ = Nothing
1043 db_rings = foldl' (\db ((fname,_),ps) -> merge db fname ps) Map.empty ms 1049 db_rings = foldl' mergeIt Map.empty ms
1044 1050 where mergeIt db ((f,_),ps) = merge db f ps
1045 wk = listToMaybe $ do 1051 wk = listToMaybe $ do
1046 fp <- maybeToList grip 1052 fp <- maybeToList grip
1047 elm <- Map.toList db_rings 1053 elm <- Map.toList db_rings
1048 guard $ matchSpec (KeyGrip fp) elm 1054 guard $ matchSpec (KeyGrip fp) elm
1049 return $ keyMappedPacket (snd elm) 1055 return $ keyMappedPacket (snd elm)
1050 accs = map fst ms 1056 accs = map (first (concat . resolveInputFile ctx) . fst) ms
1051 return (db_rings,wk,grip,Map.fromList accs) 1057 return (db_rings,wk,grip,Map.fromList accs)
1052 1058
1053 let wk = fmap packet mwk 1059 let wk = fmap packet mwk
@@ -2224,9 +2230,11 @@ keykey key =
2224uidkey :: Packet -> String 2230uidkey :: Packet -> String
2225uidkey (UserIDPacket str) = str 2231uidkey (UserIDPacket str) = str
2226 2232
2227merge :: KeyDB -> FilePath -> Message -> KeyDB 2233merge :: KeyDB -> InputFile -> Message -> KeyDB
2228merge db filename (Message ps) = merge_ db filename qs 2234merge db inputfile (Message ps) = merge_ db filename qs
2229 where 2235 where
2236 filename = concat $ resolveInputFile (InputFileContext "&secret" "&public") inputfile
2237
2230 qs = scanPackets filename ps 2238 qs = scanPackets filename ps
2231 2239
2232 scanPackets :: FilePath -> [Packet] -> [(Packet,Packet,(Packet,Map.Map FilePath Packet))] 2240 scanPackets :: FilePath -> [Packet] -> [(Packet,Packet,(Packet,Map.Map FilePath Packet))]