git-annex/Types/Crypto.hs

51 lines
1.2 KiB
Haskell
Raw Normal View History

2011-04-16 20:41:46 +00:00
{- git-annex crypto types
-
2015-04-19 14:54:12 +00:00
- Copyright 2011-2015 Joey Hess <id@joeyh.name>
2011-04-16 20:41:46 +00:00
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Types.Crypto (
Cipher(..),
StorableCipher(..),
EncryptedCipherVariant(..),
KeyIds(..),
Mac(..),
readMac,
showMac,
defaultMac,
calcMac,
) where
2015-04-19 14:57:14 +00:00
import Utility.Hash
import Utility.Gpg (KeyIds(..))
2011-04-16 20:41:46 +00:00
-- XXX ideally, this would be a locked memory region
data Cipher = Cipher String | MacOnlyCipher String
2011-04-16 20:41:46 +00:00
data StorableCipher = EncryptedCipher String EncryptedCipherVariant KeyIds
| SharedCipher String
deriving (Ord, Eq)
2013-09-05 15:12:01 +00:00
data EncryptedCipherVariant = Hybrid | PubKey
deriving (Ord, Eq)
defaultMac :: Mac
defaultMac = HmacSha1
-- MAC algorithms are shown as follows in the file names.
showMac :: Mac -> String
showMac HmacSha1 = "HMACSHA1"
showMac HmacSha224 = "HMACSHA224"
showMac HmacSha256 = "HMACSHA256"
showMac HmacSha384 = "HMACSHA384"
showMac HmacSha512 = "HMACSHA512"
-- Read the MAC algorithm from the remote config.
readMac :: String -> Maybe Mac
readMac "HMACSHA1" = Just HmacSha1
readMac "HMACSHA224" = Just HmacSha224
readMac "HMACSHA256" = Just HmacSha256
readMac "HMACSHA384" = Just HmacSha384
readMac "HMACSHA512" = Just HmacSha512
readMac _ = Nothing