This commit is contained in:
Joey Hess 2011-04-17 13:11:38 -04:00
parent e8a94d914b
commit d9690a9b5d
2 changed files with 16 additions and 15 deletions

View file

@ -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"

View file

@ -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