rename constructor for clariy
This commit is contained in:
parent
ac9807c887
commit
89eecd4b3b
4 changed files with 15 additions and 15 deletions
12
Crypto.hs
12
Crypto.hs
|
@ -78,8 +78,8 @@ genEncryptedCipher keyid variant highQuality = do
|
|||
encryptCipher (mkCipher random) variant ks
|
||||
where
|
||||
(mkCipher, size) = case variant of
|
||||
HybridCipher -> (Cipher, cipherSize) -- used for MAC + symmetric
|
||||
PubKeyCipher -> (MacOnlyCipher, cipherBeginning) -- only used for MAC
|
||||
Hybrid -> (Cipher, cipherSize) -- used for MAC + symmetric
|
||||
PubKey -> (MacOnlyCipher, cipherBeginning) -- only used for MAC
|
||||
|
||||
{- Creates a new, shared Cipher. -}
|
||||
genSharedCipher :: Bool -> IO StorableCipher
|
||||
|
@ -110,8 +110,8 @@ describeCipher (EncryptedCipher _ variant (KeyIds ks)) =
|
|||
scheme ++ " with gpg " ++ keys ks ++ " " ++ unwords ks
|
||||
where
|
||||
scheme = case variant of
|
||||
HybridCipher -> "hybrid cipher"
|
||||
PubKeyCipher -> "pubkey crypto"
|
||||
Hybrid -> "hybrid cipher"
|
||||
PubKey -> "pubkey crypto"
|
||||
keys [_] = "key"
|
||||
keys _ = "keys"
|
||||
|
||||
|
@ -135,8 +135,8 @@ decryptCipher (EncryptedCipher t variant _) =
|
|||
mkCipher <$> Gpg.pipeStrict [ Param "--decrypt" ] t
|
||||
where
|
||||
mkCipher = case variant of
|
||||
HybridCipher -> Cipher
|
||||
PubKeyCipher -> MacOnlyCipher
|
||||
Hybrid -> Cipher
|
||||
PubKey -> MacOnlyCipher
|
||||
|
||||
{- Generates an encrypted form of a Key. The encryption does not need to be
|
||||
- reversable, nor does it need to be the same type of encryption used
|
||||
|
|
|
@ -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 HybridCipher
|
||||
use "encryption setup" . genEncryptedCipher key Hybrid
|
||||
=<< highRandomQuality
|
||||
Just "pubkey" -> use "encryption setup" . genEncryptedCipher key PubKeyCipher
|
||||
Just "pubkey" -> use "encryption setup" . genEncryptedCipher key PubKey
|
||||
=<< highRandomQuality
|
||||
_ -> error $ "Specify " ++ intercalate " or "
|
||||
(map ("encryption=" ++)
|
||||
|
@ -52,7 +52,7 @@ encryptionSetup c = maybe genCipher updateCipher $ extractCipher c
|
|||
updateCipher v = case v of
|
||||
SharedCipher _ | maybe True (== "shared") encryption -> return c'
|
||||
EncryptedCipher _ variant _
|
||||
| maybe True (== if variant == HybridCipher then "hybrid" else "pubkey") encryption ->
|
||||
| maybe True (== if variant == Hybrid then "hybrid" else "pubkey") encryption ->
|
||||
use "encryption update" $ updateEncryptedCipher newkeys v
|
||||
_ -> cannotchange
|
||||
use m a = do
|
||||
|
@ -154,9 +154,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) HybridCipher (readkeys ks)
|
||||
Just $ EncryptedCipher (fromB64 t) Hybrid (readkeys ks)
|
||||
(Just t, Just ks, Just "pubkey") ->
|
||||
Just $ EncryptedCipher (fromB64 t) PubKeyCipher (readkeys ks)
|
||||
Just $ EncryptedCipher (fromB64 t) PubKey (readkeys ks)
|
||||
(Just t, Nothing, encryption) | maybe True (== "shared") encryption ->
|
||||
Just $ SharedCipher (fromB64 t)
|
||||
_ -> Nothing
|
||||
|
|
6
Test.hs
6
Test.hs
|
@ -930,8 +930,8 @@ test_crypto env = "git-annex crypto" ~: TestList $ flip map ["shared","hybrid","
|
|||
maybe False (\(Utility.Gpg.KeyIds ks2) ->
|
||||
sort (nub ks2) == sort (nub ks')) ks
|
||||
checkCipher encipher = Utility.Gpg.checkEncryptionStream encipher . Just
|
||||
checkScheme Types.Crypto.HybridCipher = scheme == "hybrid"
|
||||
checkScheme Types.Crypto.PubKeyCipher = scheme == "pubkey"
|
||||
checkScheme Types.Crypto.Hybrid = scheme == "hybrid"
|
||||
checkScheme Types.Crypto.PubKey = scheme == "pubkey"
|
||||
checkKeys cip mvariant = do
|
||||
cipher <- Crypto.decryptCipher cip
|
||||
files <- filterM doesFileExist $
|
||||
|
@ -939,7 +939,7 @@ test_crypto env = "git-annex crypto" ~: TestList $ flip map ["shared","hybrid","
|
|||
return (not $ null files) <&&> allM (checkFile mvariant) files
|
||||
checkFile mvariant filename =
|
||||
Utility.Gpg.checkEncryptionFile filename $
|
||||
if mvariant == Just Types.Crypto.PubKeyCipher then ks else Nothing
|
||||
if mvariant == Just Types.Crypto.PubKey then ks else Nothing
|
||||
key2files cipher = Locations.keyPaths .
|
||||
Crypto.encryptKey Types.Crypto.HmacSha1 cipher
|
||||
#else
|
||||
|
|
|
@ -28,7 +28,7 @@ data Cipher = Cipher String | MacOnlyCipher String
|
|||
data StorableCipher = EncryptedCipher String EncryptedCipherVariant KeyIds
|
||||
| SharedCipher String
|
||||
deriving (Ord, Eq)
|
||||
data EncryptedCipherVariant = HybridCipher | PubKeyCipher
|
||||
data EncryptedCipherVariant = Hybrid | PubKey
|
||||
deriving (Ord, Eq)
|
||||
|
||||
{- File names are (client-side) MAC'ed on special remotes.
|
||||
|
|
Loading…
Reference in a new issue