From bd592d1450e52a99e7507a211ad1c36414d3d869 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 29 Apr 2012 14:31:34 -0400 Subject: refactor --- Crypto.hs | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) (limited to 'Crypto.hs') diff --git a/Crypto.hs b/Crypto.hs index e530bd0e6..58c0e6d00 100644 --- a/Crypto.hs +++ b/Crypto.hs @@ -10,13 +10,12 @@ module Crypto ( Cipher, + KeyIds(..), StorableCipher(..), genEncryptedCipher, genSharedCipher, updateEncryptedCipher, describeCipher, - storeCipher, - extractCipher, decryptCipher, encryptKey, withEncryptedHandle, @@ -28,7 +27,6 @@ module Crypto ( ) where import qualified Data.ByteString.Lazy.Char8 as L -import qualified Data.Map as M import Data.ByteString.Lazy.UTF8 (fromString) import Data.Digest.Pure.SHA import Control.Applicative @@ -36,8 +34,6 @@ import Control.Applicative import Common.Annex import qualified Utility.Gpg as Gpg import Types.Key -import Types.Remote -import Utility.Base64 import Types.Crypto {- The first half of a Cipher is used for HMAC; the remainder @@ -90,24 +86,6 @@ describeCipher (EncryptedCipher _ (KeyIds ks)) = keys [_] = "key" keys _ = "keys" -{- Stores an StorableCipher in a remote's configuration. -} -storeCipher :: RemoteConfig -> StorableCipher -> RemoteConfig -storeCipher c (SharedCipher t) = M.insert "cipher" (toB64 t) c -storeCipher c (EncryptedCipher t ks) = - M.insert "cipher" (toB64 t) $ M.insert "cipherkeys" (showkeys ks) c - where - showkeys (KeyIds l) = join "," l - -{- Extracts an StorableCipher from a remote's configuration. -} -extractCipher :: RemoteConfig -> Maybe StorableCipher -extractCipher c = - case (M.lookup "cipher" c, M.lookup "cipherkeys" c) of - (Just t, Just ks) -> Just $ EncryptedCipher (fromB64 t) (readkeys ks) - (Just t, Nothing) -> Just $ SharedCipher (fromB64 t) - _ -> Nothing - where - readkeys = KeyIds . split "," - {- Encrypts a Cipher to the specified KeyIds. -} encryptCipher :: Cipher -> KeyIds -> IO StorableCipher encryptCipher (Cipher c) (KeyIds ks) = do @@ -160,7 +138,7 @@ withDecryptedContent = pass withDecryptedHandle pass :: (Cipher -> IO L.ByteString -> (Handle -> IO a) -> IO a) -> Cipher -> IO L.ByteString -> (L.ByteString -> IO a) -> IO a -pass to c i a = to c i $ \h -> a =<< L.hGetContents h +pass to n s a = to n s $ \h -> a =<< L.hGetContents h hmacWithCipher :: Cipher -> String -> String hmacWithCipher c = hmacWithCipher' (cipherHmac c) -- cgit v1.2.3