summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-04-19 10:54:12 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-04-19 10:54:12 -0400
commit5610389a6880a82947582842db2d762a353b1f33 (patch)
treece55379c7116f293aa5eb99621c1c9a827417f66
parent42c4cf332ce09d11b66d48ed3d39df7990882ecb (diff)
switch to using cryptohash for MAC
-rw-r--r--Crypto.hs2
-rw-r--r--Types/Crypto.hs25
-rw-r--r--debian/control2
-rw-r--r--git-annex.cabal2
4 files changed, 16 insertions, 15 deletions
diff --git a/Crypto.hs b/Crypto.hs
index 4e3741715..66c27c527 100644
--- a/Crypto.hs
+++ b/Crypto.hs
@@ -34,7 +34,7 @@ module Crypto (
) where
import qualified Data.ByteString.Lazy as L
-import Data.ByteString.Lazy.UTF8 (fromString)
+import Data.ByteString.UTF8 (fromString)
import Control.Applicative
import qualified Data.Map as M
import Control.Monad.IO.Class
diff --git a/Types/Crypto.hs b/Types/Crypto.hs
index 005be4531..ec61f1c4b 100644
--- a/Types/Crypto.hs
+++ b/Types/Crypto.hs
@@ -1,6 +1,6 @@
{- git-annex crypto types
-
- - Copyright 2011-2012 Joey Hess <id@joeyh.name>
+ - Copyright 2011-2015 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -17,10 +17,11 @@ module Types.Crypto (
calcMac,
) where
-import qualified Data.ByteString.Lazy as L
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import Data.Digest.Pure.SHA
+import qualified Data.ByteString as B
+import Crypto.Hash
import Utility.Gpg (KeyIds(..))
@@ -62,17 +63,17 @@ readMac _ = Nothing
calcMac
:: Mac -- ^ MAC
- -> L.ByteString -- ^ secret key
- -> L.ByteString -- ^ message
+ -> B.ByteString -- ^ secret key
+ -> B.ByteString -- ^ message
-> String -- ^ MAC'ed message, in hexadecimal
calcMac mac = case mac of
- HmacSha1 -> showDigest $* hmacSha1
- HmacSha224 -> showDigest $* hmacSha224
- HmacSha256 -> showDigest $* hmacSha256
- HmacSha384 -> showDigest $* hmacSha384
- HmacSha512 -> showDigest $* hmacSha512
+ HmacSha1 -> use SHA1
+ HmacSha224 -> use SHA224
+ HmacSha256 -> use SHA256
+ HmacSha384 -> use SHA384
+ HmacSha512 -> use SHA512
where
- ($*) g f x y = g $ f x y
+ use alg k m = show (hmacGetDigest (hmacAlg alg k m))
-- Check that all the MACs continue to produce the same.
prop_mac_stable :: Bool
@@ -84,5 +85,5 @@ prop_mac_stable = all (\(mac, result) -> calcMac mac key msg == result)
, (HmacSha512, "114682914c5d017dfe59fdc804118b56a3a652a0b8870759cf9e792ed7426b08197076bf7d01640b1b0684df79e4b67e37485669e8ce98dbab60445f0db94fce")
]
where
- key = L.fromChunks [T.encodeUtf8 $ T.pack "foo"]
- msg = L.fromChunks [T.encodeUtf8 $ T.pack "bar"]
+ key = T.encodeUtf8 $ T.pack "foo"
+ msg = T.encodeUtf8 $ T.pack "bar"
diff --git a/debian/control b/debian/control
index 6cb4a6327..11f42a8c1 100644
--- a/debian/control
+++ b/debian/control
@@ -11,7 +11,7 @@ Build-Depends:
libghc-hslogger-dev,
libghc-pcre-light-dev,
libghc-sha-dev,
- libghc-cryptohash-dev,
+ libghc-cryptohash-dev (>= 0.11.0),
libghc-dataenc-dev,
libghc-utf8-string-dev,
libghc-aws-dev (>= 0.9.2-2~),
diff --git a/git-annex.cabal b/git-annex.cabal
index b5ddb7d79..9b0407e1a 100644
--- a/git-annex.cabal
+++ b/git-annex.cabal
@@ -110,7 +110,7 @@ Executable git-annex
IfElse, text, QuickCheck >= 2.1, bloomfilter, edit-distance,
SafeSemaphore, uuid, random, dlist, unix-compat, async, stm (>= 2.3),
data-default, case-insensitive, http-conduit, http-types,
- cryptohash (>= 0.10.0),
+ cryptohash (>= 0.11.0),
esqueleto, persistent-sqlite, persistent, persistent-template,
monad-logger, resourcet
CC-Options: -Wall