diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-02-04 13:47:54 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-02-04 13:47:54 -0400 |
commit | befd1be4e0a5505a3600ea36b9d5834d1379719d (patch) | |
tree | 0208be9992e23defd415df7127850f42d3a3280e /Backend | |
parent | bc4016065f00af1b77c6fa1dedb5c4c22158b9d8 (diff) |
Added MD5 and MD5E backends.
Diffstat (limited to 'Backend')
-rw-r--r-- | Backend/Hash.hs | 10 |
1 files changed, 7 insertions, 3 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. - |