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
|
encryptCipher (mkCipher random) variant ks
|
||||||
where
|
where
|
||||||
(mkCipher, size) = case variant of
|
(mkCipher, size) = case variant of
|
||||||
HybridCipher -> (Cipher, cipherSize) -- used for MAC + symmetric
|
Hybrid -> (Cipher, cipherSize) -- used for MAC + symmetric
|
||||||
PubKeyCipher -> (MacOnlyCipher, cipherBeginning) -- only used for MAC
|
PubKey -> (MacOnlyCipher, cipherBeginning) -- only used for MAC
|
||||||
|
|
||||||
{- Creates a new, shared Cipher. -}
|
{- Creates a new, shared Cipher. -}
|
||||||
genSharedCipher :: Bool -> IO StorableCipher
|
genSharedCipher :: Bool -> IO StorableCipher
|
||||||
|
@ -110,8 +110,8 @@ describeCipher (EncryptedCipher _ variant (KeyIds ks)) =
|
||||||
scheme ++ " with gpg " ++ keys ks ++ " " ++ unwords ks
|
scheme ++ " with gpg " ++ keys ks ++ " " ++ unwords ks
|
||||||
where
|
where
|
||||||
scheme = case variant of
|
scheme = case variant of
|
||||||
HybridCipher -> "hybrid cipher"
|
Hybrid -> "hybrid cipher"
|
||||||
PubKeyCipher -> "pubkey crypto"
|
PubKey -> "pubkey crypto"
|
||||||
keys [_] = "key"
|
keys [_] = "key"
|
||||||
keys _ = "keys"
|
keys _ = "keys"
|
||||||
|
|
||||||
|
@ -135,8 +135,8 @@ decryptCipher (EncryptedCipher t variant _) =
|
||||||
mkCipher <$> Gpg.pipeStrict [ Param "--decrypt" ] t
|
mkCipher <$> Gpg.pipeStrict [ Param "--decrypt" ] t
|
||||||
where
|
where
|
||||||
mkCipher = case variant of
|
mkCipher = case variant of
|
||||||
HybridCipher -> Cipher
|
Hybrid -> Cipher
|
||||||
PubKeyCipher -> MacOnlyCipher
|
PubKey -> MacOnlyCipher
|
||||||
|
|
||||||
{- Generates an encrypted form of a Key. The encryption does not need to be
|
{- 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
|
- 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
|
-- hybrid encryption is the default when a keyid is
|
||||||
-- specified but no encryption
|
-- specified but no encryption
|
||||||
_ | maybe (M.member "keyid" c) (== "hybrid") encryption ->
|
_ | maybe (M.member "keyid" c) (== "hybrid") encryption ->
|
||||||
use "encryption setup" . genEncryptedCipher key HybridCipher
|
use "encryption setup" . genEncryptedCipher key Hybrid
|
||||||
=<< highRandomQuality
|
=<< highRandomQuality
|
||||||
Just "pubkey" -> use "encryption setup" . genEncryptedCipher key PubKeyCipher
|
Just "pubkey" -> use "encryption setup" . genEncryptedCipher key PubKey
|
||||||
=<< highRandomQuality
|
=<< highRandomQuality
|
||||||
_ -> error $ "Specify " ++ intercalate " or "
|
_ -> error $ "Specify " ++ intercalate " or "
|
||||||
(map ("encryption=" ++)
|
(map ("encryption=" ++)
|
||||||
|
@ -52,7 +52,7 @@ encryptionSetup c = maybe genCipher updateCipher $ extractCipher c
|
||||||
updateCipher v = case v of
|
updateCipher v = case v of
|
||||||
SharedCipher _ | maybe True (== "shared") encryption -> return c'
|
SharedCipher _ | maybe True (== "shared") encryption -> return c'
|
||||||
EncryptedCipher _ variant _
|
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
|
use "encryption update" $ updateEncryptedCipher newkeys v
|
||||||
_ -> cannotchange
|
_ -> cannotchange
|
||||||
use m a = do
|
use m a = do
|
||||||
|
@ -154,9 +154,9 @@ extractCipher c = case (M.lookup "cipher" c,
|
||||||
M.lookup "cipherkeys" c,
|
M.lookup "cipherkeys" c,
|
||||||
M.lookup "encryption" c) of
|
M.lookup "encryption" c) of
|
||||||
(Just t, Just ks, encryption) | maybe True (== "hybrid") encryption ->
|
(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 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 t, Nothing, encryption) | maybe True (== "shared") encryption ->
|
||||||
Just $ SharedCipher (fromB64 t)
|
Just $ SharedCipher (fromB64 t)
|
||||||
_ -> Nothing
|
_ -> 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) ->
|
maybe False (\(Utility.Gpg.KeyIds ks2) ->
|
||||||
sort (nub ks2) == sort (nub ks')) ks
|
sort (nub ks2) == sort (nub ks')) ks
|
||||||
checkCipher encipher = Utility.Gpg.checkEncryptionStream encipher . Just
|
checkCipher encipher = Utility.Gpg.checkEncryptionStream encipher . Just
|
||||||
checkScheme Types.Crypto.HybridCipher = scheme == "hybrid"
|
checkScheme Types.Crypto.Hybrid = scheme == "hybrid"
|
||||||
checkScheme Types.Crypto.PubKeyCipher = scheme == "pubkey"
|
checkScheme Types.Crypto.PubKey = scheme == "pubkey"
|
||||||
checkKeys cip mvariant = do
|
checkKeys cip mvariant = do
|
||||||
cipher <- Crypto.decryptCipher cip
|
cipher <- Crypto.decryptCipher cip
|
||||||
files <- filterM doesFileExist $
|
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
|
return (not $ null files) <&&> allM (checkFile mvariant) files
|
||||||
checkFile mvariant filename =
|
checkFile mvariant filename =
|
||||||
Utility.Gpg.checkEncryptionFile 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 .
|
key2files cipher = Locations.keyPaths .
|
||||||
Crypto.encryptKey Types.Crypto.HmacSha1 cipher
|
Crypto.encryptKey Types.Crypto.HmacSha1 cipher
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -28,7 +28,7 @@ data Cipher = Cipher String | MacOnlyCipher String
|
||||||
data StorableCipher = EncryptedCipher String EncryptedCipherVariant KeyIds
|
data StorableCipher = EncryptedCipher String EncryptedCipherVariant KeyIds
|
||||||
| SharedCipher String
|
| SharedCipher String
|
||||||
deriving (Ord, Eq)
|
deriving (Ord, Eq)
|
||||||
data EncryptedCipherVariant = HybridCipher | PubKeyCipher
|
data EncryptedCipherVariant = Hybrid | PubKey
|
||||||
deriving (Ord, Eq)
|
deriving (Ord, Eq)
|
||||||
|
|
||||||
{- File names are (client-side) MAC'ed on special remotes.
|
{- File names are (client-side) MAC'ed on special remotes.
|
||||||
|
|
Loading…
Reference in a new issue