aboutsummaryrefslogtreecommitdiff
path: root/Crypto.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-11-07 23:21:22 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-11-08 00:17:54 -0400
commitb11a63a860e8446cf3a4b35a5d8ef76329d5135c (patch)
treec8ae0c94d6473a3ccc7b15bdbc72d5b5c6ae96b3 /Crypto.hs
parentfdf988be6d2b3bb931a9eb3dcf3fbb83b1fb8c17 (diff)
clean up read/show abuse
Avoid ever using read to parse a non-haskell formatted input string. show :: Key is arguably still show abuse, but displaying Keys as filenames is just too useful to give up.
Diffstat (limited to 'Crypto.hs')
-rw-r--r--Crypto.hs8
1 files changed, 6 insertions, 2 deletions
diff --git a/Crypto.hs b/Crypto.hs
index ced7c144c..b3acb30a6 100644
--- a/Crypto.hs
+++ b/Crypto.hs
@@ -102,14 +102,18 @@ describeCipher (EncryptedCipher _ (KeyIds ks)) =
{- Stores an EncryptedCipher in a remote's configuration. -}
storeCipher :: RemoteConfig -> EncryptedCipher -> RemoteConfig
storeCipher c (EncryptedCipher t ks) =
- M.insert "cipher" (toB64 t) $ M.insert "cipherkeys" (show ks) c
+ M.insert "cipher" (toB64 t) $ M.insert "cipherkeys" (showkeys ks) c
+ where
+ showkeys (KeyIds l) = join "," l
{- Extracts an EncryptedCipher from a remote's configuration. -}
extractCipher :: RemoteConfig -> Maybe EncryptedCipher
extractCipher c =
case (M.lookup "cipher" c, M.lookup "cipherkeys" c) of
- (Just t, Just ks) -> Just $ EncryptedCipher (fromB64 t) (read ks)
+ (Just t, Just ks) -> Just $ EncryptedCipher (fromB64 t) (readkeys ks)
_ -> Nothing
+ where
+ readkeys = KeyIds . split ","
{- Encrypts a Cipher to the specified KeyIds. -}
encryptCipher :: Cipher -> KeyIds -> IO EncryptedCipher