summaryrefslogtreecommitdiff
path: root/Remote/Helper/Encryptable.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-04-29 14:31:34 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-04-29 14:33:07 -0400
commitbd592d1450e52a99e7507a211ad1c36414d3d869 (patch)
treeb7cb3c62ae999665e0e541784d89c7576af0a4c5 /Remote/Helper/Encryptable.hs
parent9f04367336965fcfc0b78aeacefe70970e77db19 (diff)
refactor
Diffstat (limited to 'Remote/Helper/Encryptable.hs')
-rw-r--r--Remote/Helper/Encryptable.hs19
1 files changed, 19 insertions, 0 deletions
diff --git a/Remote/Helper/Encryptable.hs b/Remote/Helper/Encryptable.hs
index a44e6e453..789a1d996 100644
--- a/Remote/Helper/Encryptable.hs
+++ b/Remote/Helper/Encryptable.hs
@@ -14,6 +14,7 @@ import Types.Remote
import Crypto
import qualified Annex
import Config
+import Utility.Base64
{- Encryption setup for a remote. The user must specify whether to use
- an encryption key, or not encrypt. An encrypted cipher is created, or is
@@ -93,3 +94,21 @@ cipherKey Nothing _ = return Nothing
cipherKey (Just c) k = maybe Nothing encrypt <$> remoteCipher c
where
encrypt ciphertext = Just (ciphertext, encryptKey ciphertext k)
+
+{- 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 ","