cleanup
This commit is contained in:
parent
e8a94d914b
commit
d9690a9b5d
2 changed files with 16 additions and 15 deletions
29
Crypto.hs
29
Crypto.hs
|
@ -17,7 +17,8 @@ module Crypto (
|
||||||
extractCipher,
|
extractCipher,
|
||||||
decryptCipher,
|
decryptCipher,
|
||||||
encryptKey,
|
encryptKey,
|
||||||
withEncryptedContentHandle,
|
withEncryptedHandle,
|
||||||
|
withDecryptedHandle,
|
||||||
withEncryptedContent,
|
withEncryptedContent,
|
||||||
withDecryptedContent,
|
withDecryptedContent,
|
||||||
) where
|
) where
|
||||||
|
@ -141,19 +142,27 @@ encryptKey c k =
|
||||||
keyMtime = Nothing -- to avoid leaking data
|
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. -}
|
- stream encrypted content. -}
|
||||||
withEncryptedContentHandle :: Cipher -> L.ByteString -> (Handle -> IO a) -> IO a
|
withEncryptedHandle :: Cipher -> L.ByteString -> (Handle -> IO a) -> IO a
|
||||||
withEncryptedContentHandle = gpgCipherHandle [Params "--symmetric --force-mdc"]
|
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. -}
|
{- Streams encrypted content to an action. -}
|
||||||
withEncryptedContent :: Cipher -> L.ByteString -> (L.ByteString -> IO a) -> IO a
|
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. -}
|
{- Streams decrypted content to an action. -}
|
||||||
withDecryptedContent :: Cipher -> L.ByteString -> (L.ByteString -> IO a) -> IO a
|
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 :: [CommandParam] -> [String]
|
||||||
gpgParams params =
|
gpgParams params =
|
||||||
|
@ -199,14 +208,6 @@ gpgCipherHandle params c input a = do
|
||||||
closeFd frompipe
|
closeFd frompipe
|
||||||
return ret
|
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 :: RemoteConfig -> IO KeyIds
|
||||||
configKeyIds c = do
|
configKeyIds c = do
|
||||||
let k = configGet c "encryption"
|
let k = configGet c "encryption"
|
||||||
|
|
|
@ -127,7 +127,7 @@ storeEncrypted r buprepo (cipher, enck) k = do
|
||||||
params <- bupSplitParams r buprepo enck (Param "-")
|
params <- bupSplitParams r buprepo enck (Param "-")
|
||||||
liftIO $ catchBool $ do
|
liftIO $ catchBool $ do
|
||||||
content <- L.readFile src
|
content <- L.readFile src
|
||||||
withEncryptedContentHandle cipher content $ \h -> do
|
withEncryptedHandle cipher content $ \h -> do
|
||||||
pipeBup params (Just h) Nothing
|
pipeBup params (Just h) Nothing
|
||||||
|
|
||||||
retrieve :: BupRepo -> Key -> FilePath -> Annex Bool
|
retrieve :: BupRepo -> Key -> FilePath -> Annex Bool
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue