summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Backend/Hash.hs10
-rw-r--r--Utility/Hash.hs5
-rw-r--r--debian/changelog1
-rw-r--r--doc/backends.mdwn4
4 files changed, 15 insertions, 5 deletions
diff --git a/Backend/Hash.hs b/Backend/Hash.hs
index 6c240638f..f1b9d592d 100644
--- a/Backend/Hash.hs
+++ b/Backend/Hash.hs
@@ -5,8 +5,6 @@
- Licensed under the GNU GPL version 3 or higher.
-}
-{-# LANGUAGE CPP #-}
-
module Backend.Hash (
backends,
testKeyBackend,
@@ -24,7 +22,7 @@ import qualified Build.SysConfig as SysConfig
import qualified Data.ByteString.Lazy as L
import Data.Char
-data Hash = SHAHash HashSize | SkeinHash HashSize
+data Hash = SHAHash HashSize | SkeinHash HashSize | MD5Hash
type HashSize = Int
{- Order is slightly significant; want SHA256 first, and more general
@@ -33,6 +31,7 @@ hashes :: [Hash]
hashes = concat
[ map SHAHash [256, 1, 512, 224, 384]
, map SkeinHash [256, 512]
+ , [MD5Hash]
]
{- The SHA256E backend is the default, so genBackendE comes first. -}
@@ -58,6 +57,7 @@ genBackendE hash = (genBackend hash)
hashName :: Hash -> String
hashName (SHAHash size) = "SHA" ++ show size
hashName (SkeinHash size) = "SKEIN" ++ show size
+hashName MD5Hash = "MD5"
hashNameE :: Hash -> String
hashNameE hash = hashName hash ++ "E"
@@ -154,6 +154,7 @@ hashFile hash file filesize = liftIO $ go hash
either error return
=<< externalSHA command hashsize file
go (SkeinHash hashsize) = skeinHasher hashsize <$> L.readFile file
+ go MD5Hash = md5Hasher <$> L.readFile file
shaHasher :: HashSize -> Integer -> Either (L.ByteString -> String) String
shaHasher hashsize filesize
@@ -180,6 +181,9 @@ skeinHasher hashsize
| hashsize == 512 = show . skein512
| otherwise = error $ "unsupported skein size " ++ show hashsize
+md5Hasher :: L.ByteString -> String
+md5Hasher = show . md5
+
{- A varient of the SHA256E backend, for testing that needs special keys
- that cannot collide with legitimate keys in the repository.
-
diff --git a/Utility/Hash.hs b/Utility/Hash.hs
index acc8a3815..9881815bd 100644
--- a/Utility/Hash.hs
+++ b/Utility/Hash.hs
@@ -8,6 +8,7 @@ module Utility.Hash (
sha512,
skein256,
skein512,
+ md5,
prop_hashes_stable
) where
@@ -42,6 +43,9 @@ skein256 = hashlazy
skein512 :: L.ByteString -> Digest Skein512_512
skein512 = hashlazy
+md5 :: L.ByteString -> Digest MD5
+md5 = hashlazy
+
{- Check that all the hashes continue to hash the same. -}
prop_hashes_stable :: Bool
prop_hashes_stable = all (\(hasher, result) -> hasher foo == result)
@@ -52,6 +56,7 @@ prop_hashes_stable = all (\(hasher, result) -> hasher foo == result)
, (show . sha512, "f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7")
, (show . skein256, "a04efd9a0aeed6ede40fe5ce0d9361ae7b7d88b524aa19917b9315f1ecf00d33")
, (show . skein512, "fd8956898113510180aa4658e6c0ac85bd74fb47f4a4ba264a6b705d7a8e8526756e75aecda12cff4f1aca1a4c2830fbf57f458012a66b2b15a3dd7d251690a7")
+ , (show . md5, "acbd18db4cc2f85cedef654fccc4a4d8")
]
where
foo = L.fromChunks [T.encodeUtf8 $ T.pack "foo"]
diff --git a/debian/changelog b/debian/changelog
index 9433a30d2..e1d62bbdd 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -29,6 +29,7 @@ git-annex (5.20150114) UNRELEASED; urgency=medium
* Support annex.tune.objecthash1, annex.tune.objecthashlower, and
annex.tune.branchhash1.
* Remove support for building without cryptohash.
+ * Added MD5 and MD5E backends.
-- Joey Hess <id@joeyh.name> Tue, 13 Jan 2015 17:03:39 -0400
diff --git a/doc/backends.mdwn b/doc/backends.mdwn
index bf6471fa7..5da053dc1 100644
--- a/doc/backends.mdwn
+++ b/doc/backends.mdwn
@@ -17,8 +17,8 @@ can use different ones for different files.
This is the least expensive backend, recommended for really large
files or slow systems.
* `SHA512`, `SHA512E` -- Best SHA-2 hash, for the very paranoid.
-* `SHA1`, `SHA1E` -- Smaller hash than `SHA256` for those who want a checksum
- but are not concerned about security.
+* `SHA1`, `SHA1E`, `MD5`, `MD5E` -- Smaller hashes than `SHA256`
+ for those who want a checksum but are not concerned about security.
* `SHA384`, `SHA384E`, `SHA224`, `SHA224E` -- Hashes for people who like
unusual sizes.
* `SKEIN512`, `SKEIN512E`, `SKEIN256`, `SKEIN256E`