summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-04-17 13:11:38 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-04-17 13:11:38 -0400
commitd9690a9b5d6e706abe41fd76800ce9c526ad0b4e (patch)
tree2dc9735e3fb6bfd7ef38d37f959d7fdec2cc1ea0
parente8a94d914b2bcf96a2a2d7d5016fb72a231e9b48 (diff)
cleanup
-rw-r--r--Crypto.hs29
-rw-r--r--Remote/Bup.hs2
2 files changed, 16 insertions, 15 deletions
diff --git a/Crypto.hs b/Crypto.hs
index 25a87c3ad..bbe8a6f4c 100644
--- a/Crypto.hs
+++ b/Crypto.hs
@@ -17,7 +17,8 @@ module Crypto (
extractCipher,
decryptCipher,
encryptKey,
- withEncryptedContentHandle,
+ withEncryptedHandle,
+ withDecryptedHandle,
withEncryptedContent,
withDecryptedContent,
) where
@@ -141,19 +142,27 @@ encryptKey c k =
keyMtime = Nothing -- to avoid leaking data
}
-{- Runs an action passing it a handle from which it can
+{- Runs an action, passing it a handle from which it can
- stream encrypted content. -}
-withEncryptedContentHandle :: Cipher -> L.ByteString -> (Handle -> IO a) -> IO a
-withEncryptedContentHandle = gpgCipherHandle [Params "--symmetric --force-mdc"]
+withEncryptedHandle :: Cipher -> L.ByteString -> (Handle -> IO a) -> IO a
+withEncryptedHandle = gpgCipherHandle [Params "--symmetric --force-mdc"]
+
+{- Runs an action, passing it a handle from which it can
+ - stream decrypted content. -}
+withDecryptedHandle :: Cipher -> L.ByteString -> (Handle -> IO a) -> IO a
+withDecryptedHandle = gpgCipherHandle [Param "--decrypt"]
{- Streams encrypted content to an action. -}
withEncryptedContent :: Cipher -> L.ByteString -> (L.ByteString -> IO a) -> IO a
-withEncryptedContent = gpgCipher [Params "--symmetric --force-mdc"]
+withEncryptedContent = pass withEncryptedHandle
{- Streams decrypted content to an action. -}
withDecryptedContent :: Cipher -> L.ByteString -> (L.ByteString -> IO a) -> IO a
-withDecryptedContent = gpgCipher [Param "--decrypt"]
+withDecryptedContent = pass withDecryptedHandle
+pass :: (Cipher -> L.ByteString -> (Handle -> IO a) -> IO a)
+ -> Cipher -> L.ByteString -> (L.ByteString -> IO a) -> IO a
+pass to c i a = to c i $ \h -> a =<< L.hGetContents h
gpgParams :: [CommandParam] -> [String]
gpgParams params =
@@ -199,14 +208,6 @@ gpgCipherHandle params c input a = do
closeFd frompipe
return ret
-{- Runs gpg with a cipher and some parameters, feeding it an input,
- - and piping its output lazily to an action. -}
-gpgCipher :: [CommandParam] -> Cipher -> L.ByteString -> (L.ByteString -> IO a) -> IO a
-gpgCipher params c input a = do
- gpgCipherHandle params c input $ \h -> do
- content <- L.hGetContents h
- a content
-
configKeyIds :: RemoteConfig -> IO KeyIds
configKeyIds c = do
let k = configGet c "encryption"
diff --git a/Remote/Bup.hs b/Remote/Bup.hs
index 0edb33ba8..16e1bbdcb 100644
--- a/Remote/Bup.hs
+++ b/Remote/Bup.hs
@@ -127,7 +127,7 @@ storeEncrypted r buprepo (cipher, enck) k = do
params <- bupSplitParams r buprepo enck (Param "-")
liftIO $ catchBool $ do
content <- L.readFile src
- withEncryptedContentHandle cipher content $ \h -> do
+ withEncryptedHandle cipher content $ \h -> do
pipeBup params (Just h) Nothing
retrieve :: BupRepo -> Key -> FilePath -> Annex Bool