From 5d281f525da310b0d2b5039232f25d6211a76ae6 Mon Sep 17 00:00:00 2001 From: joe Date: Sun, 20 Apr 2014 13:36:50 -0400 Subject: minor refactor --- KeyRing.hs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/KeyRing.hs b/KeyRing.hs index 36477c0..49ddec4 100644 --- a/KeyRing.hs +++ b/KeyRing.hs @@ -1286,19 +1286,20 @@ runKeyRing operation = do then return $ KikiResult (FailedToLock failed_locks) [] else do - pws <- - -- TODO: head will throw an exception if a File Descriptor operation - -- file is present. We probably should change OriginMap to use InputFile - -- instead of FilePath. - Traversable.mapM (cachedContents secring pubring . fromJust . pwfile . snd) - (Map.mapKeys (head . resolveInputFile secring pubring) - $ Map.filter (isJust . pwfile . snd) $ kFiles operation) - - unkeysRef <- newIORef Map.empty + -- memoizing decrypter + decrypt <- do + pws <- + -- TODO: head will throw an exception if a File Descriptor operation + -- file is present. We probably should change OriginMap to use InputFile + -- instead of FilePath. + Traversable.mapM (cachedContents secring pubring . fromJust . pwfile . snd) + (Map.mapKeys (head . resolveInputFile secring pubring) + $ Map.filter (isJust . pwfile . snd) $ kFiles operation) + unkeysRef <- newIORef Map.empty + return $ doDecrypt unkeysRef pws -- merge all keyrings, PEM files, and wallets - bresult <- buildKeyDB (doDecrypt unkeysRef pws) secring pubring grip0 operation - + bresult <- buildKeyDB decrypt secring pubring grip0 operation try' bresult $ \((db,grip,wk),report_imports) -> do nonexistents <- @@ -1348,7 +1349,7 @@ runKeyRing operation = do ExitFailure num -> return (tup,FailedExternal num) ExitSuccess -> return (tup,ExternallyGeneratedFile) - v <- foldM (importPEMKey $ doDecrypt unkeysRef pws) + v <- foldM (importPEMKey decrypt) (KikiSuccess (db,[])) $ do ((f,subspec,ms,cmd),r) <- rs guard $ case r of @@ -1371,7 +1372,7 @@ runKeyRing operation = do try' externals_ret $ \(db,report_externals) -> do - r <- performManipulations (doDecrypt unkeysRef pws) + r <- performManipulations decrypt operation rt wk @@ -1384,7 +1385,7 @@ runKeyRing operation = do r <- writeRingKeys operation rt -- db wk secring pubring try' r $ \report_rings -> do - r <- writePEMKeys (doDecrypt unkeysRef pws) db exports + r <- writePEMKeys decrypt db exports try' r $ \report_pems -> do return $ KikiResult (KikiSuccess rt) -- cgit v1.2.3