summaryrefslogtreecommitdiff
path: root/Creds.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-11-18 15:27:44 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-11-18 15:27:44 -0400
commit677aab525a7023642f4b2e9d96db3c3481e8f0b1 (patch)
treee6584a8f1663f364001ad452fe8d09b83fda11a4 /Creds.hs
parentcb2ec900ae8aa60b4ccf35adeb287823d976be07 (diff)
better streaming while encrypting/decrypting
Both the directory and webdav special remotes used to have to buffer the whole file contents before it could be decrypted, as they read from chunks. Now the chunks are streamed through gpg with no buffering.
Diffstat (limited to 'Creds.hs')
-rw-r--r--Creds.hs13
1 files changed, 6 insertions, 7 deletions
diff --git a/Creds.hs b/Creds.hs
index b907073f5..0c69fc7a5 100644
--- a/Creds.hs
+++ b/Creds.hs
@@ -40,9 +40,9 @@ setRemoteCredPair c storage = go =<< getRemoteCredPair c storage
mcipher <- remoteCipher c
case (mcipher, credPairRemoteKey storage) of
(Just cipher, Just key) | isTrustedCipher c -> do
- s <- liftIO $ withEncryptedContent cipher
- (return $ L.pack $ encodeCredPair creds)
- (return . L.unpack)
+ s <- liftIO $ encrypt cipher
+ (feedBytes $ L.pack $ encodeCredPair creds)
+ (readBytes $ return . L.unpack)
return $ M.insert key (toB64 s) c
_ -> do
writeCacheCredPair creds storage
@@ -62,7 +62,9 @@ getRemoteCredPair c storage = maybe fromcache (return . Just) =<< fromenv
mcipher <- remoteCipher c
case (M.lookup key c, mcipher) of
(Just enccreds, Just cipher) -> do
- creds <- liftIO $ decrypt enccreds cipher
+ creds <- liftIO $ decrypt cipher
+ (feedBytes $ L.pack $ fromB64 enccreds)
+ (readBytes $ return . L.unpack)
case decodeCredPair creds of
Just credpair -> do
writeCacheCredPair credpair storage
@@ -70,9 +72,6 @@ getRemoteCredPair c storage = maybe fromcache (return . Just) =<< fromenv
_ -> do error $ "bad " ++ key
_ -> return Nothing
Nothing -> return Nothing
- decrypt enccreds cipher = withDecryptedContent cipher
- (return $ L.pack $ fromB64 enccreds)
- (return . L.unpack)
{- Gets a CredPair from the environment. -}
getEnvCredPair :: CredPairStorage -> IO (Maybe CredPair)