summaryrefslogtreecommitdiff
path: root/Remote
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-09-04 22:18:33 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-09-04 22:18:33 -0400
commit4c96f460a7ad615f344d1b2e88d037d7a0259776 (patch)
tree1c24b37d33946d6d5079156271c8ef8b5a3eb712 /Remote
parent17a5f70ed26b14a15a50d237f47eb68eb9c2753d (diff)
replace an over-explained Bool with a data type
This also highlights several places where a Read/Show or similar for the new data type could avoid redundant strings.
Diffstat (limited to 'Remote')
-rw-r--r--Remote/Helper/Encryptable.hs15
1 files changed, 7 insertions, 8 deletions
diff --git a/Remote/Helper/Encryptable.hs b/Remote/Helper/Encryptable.hs
index 13e8a6b77..01cefe858 100644
--- a/Remote/Helper/Encryptable.hs
+++ b/Remote/Helper/Encryptable.hs
@@ -36,9 +36,9 @@ encryptionSetup c = maybe genCipher updateCipher $ extractCipher c
-- hybrid encryption is the default when a keyid is
-- specified but no encryption
_ | maybe (M.member "keyid" c) (== "hybrid") encryption ->
- use "encryption setup" . genEncryptedCipher key True
+ use "encryption setup" . genEncryptedCipher key HybridCipher
=<< highRandomQuality
- Just "pubkey" -> use "encryption setup" . genEncryptedCipher key False
+ Just "pubkey" -> use "encryption setup" . genEncryptedCipher key PubKeyCipher
=<< highRandomQuality
_ -> error $ "Specify " ++ intercalate " or "
(map ("encryption=" ++)
@@ -51,10 +51,9 @@ encryptionSetup c = maybe genCipher updateCipher $ extractCipher c
-- Update an existing cipher if possible.
updateCipher v = case v of
SharedCipher{} | maybe True (== "shared") encryption -> return c'
- EncryptedCipher _ symmetric _
- | maybe True (== if symmetric then "hybrid" else "pubkey")
- encryption ->
- use "encryption update" $ updateEncryptedCipher newkeys v
+ EncryptedCipher _ variant _
+ | maybe True (== if variant == HybridCipher then "hybrid" else "pubkey") encryption ->
+ use "encryption update" $ updateEncryptedCipher newkeys v
_ -> cannotchange
use m a = do
showNote m
@@ -162,9 +161,9 @@ extractCipher c = case (M.lookup "cipher" c,
M.lookup "cipherkeys" c,
M.lookup "encryption" c) of
(Just t, Just ks, encryption) | maybe True (== "hybrid") encryption ->
- Just $ EncryptedCipher (fromB64 t) True (readkeys ks)
+ Just $ EncryptedCipher (fromB64 t) HybridCipher (readkeys ks)
(Just t, Just ks, Just "pubkey") ->
- Just $ EncryptedCipher (fromB64 t) False (readkeys ks)
+ Just $ EncryptedCipher (fromB64 t) PubKeyCipher (readkeys ks)
(Just t, Nothing, encryption) | maybe True (== "shared") encryption ->
Just $ SharedCipher (fromB64 t)
_ -> Nothing