allow building w/o cryptohash

Mostly for the debian stable autobuilds, which have a too old version
to use the Crypto.Hash module.
This commit is contained in:
Joey Hess 2013-10-03 12:33:38 -04:00
parent c34948247e
commit 20fb905bb6
5 changed files with 48 additions and 8 deletions

View file

@ -5,6 +5,8 @@
- Licensed under the GNU GPL version 3 or higher. - Licensed under the GNU GPL version 3 or higher.
-} -}
{-# LANGUAGE CPP #-}
module Backend.Hash (backends) where module Backend.Hash (backends) where
import Common.Annex import Common.Annex
@ -27,7 +29,9 @@ type HashSize = Int
hashes :: [Hash] hashes :: [Hash]
hashes = concat hashes = concat
[ map SHAHash [256, 1, 512, 224, 384] [ map SHAHash [256, 1, 512, 224, 384]
#ifdef WITH_CRYPTOHASH
, map SkeinHash [256, 512] , map SkeinHash [256, 512]
#endif
] ]
{- The SHA256E backend is the default, so genBackendE comes first. -} {- The SHA256E backend is the default, so genBackendE comes first. -}
@ -143,7 +147,7 @@ shaHasher hashsize filesize
| hashsize == 224 = use SysConfig.sha224 sha224 | hashsize == 224 = use SysConfig.sha224 sha224
| hashsize == 384 = use SysConfig.sha384 sha384 | hashsize == 384 = use SysConfig.sha384 sha384
| hashsize == 512 = use SysConfig.sha512 sha512 | hashsize == 512 = use SysConfig.sha512 sha512
| otherwise = error $ "bad sha size " ++ show hashsize | otherwise = error $ "unsupported sha size " ++ show hashsize
where where
use Nothing hasher = Left $ show . hasher use Nothing hasher = Left $ show . hasher
use (Just c) hasher use (Just c) hasher
@ -157,6 +161,8 @@ shaHasher hashsize filesize
skeinHasher :: HashSize -> (L.ByteString -> String) skeinHasher :: HashSize -> (L.ByteString -> String)
skeinHasher hashsize skeinHasher hashsize
#ifdef WITH_CRYPTOHASH
| hashsize == 256 = show . skein256 | hashsize == 256 = show . skein256
| hashsize == 512 = show . skein512 | hashsize == 512 = show . skein512
| otherwise = error $ "bad skein size " ++ show hashsize #endif
| otherwise = error $ "unsupported skein size " ++ show hashsize

View file

@ -53,5 +53,11 @@ buildFlags = filter (not . null)
#endif #endif
#ifdef WITH_QUVI #ifdef WITH_QUVI
, "Quvi" , "Quvi"
#endif
#ifdef WITH_TDFA
, "TDFA"
#endif
#ifdef WITH_CRYPTOHASH
, "CryptoHash"
#endif #endif
] ]

View file

@ -1,13 +1,30 @@
{- Convenience wrapper around cryptohash. {- Convenience wrapper around cryptohash.
- - Falls back to SHA if it's not available.
- The resulting Digests can be shown to get a canonical hash encoding. -} -}
module Utility.Hash where {-# LANGUAGE CPP #-}
module Utility.Hash (
sha1,
sha224,
sha256,
sha384,
sha512,
#ifdef WITH_CRYPTOHASH
skein256,
skein512,
#endif
prop_hashes_stable
) where
import Crypto.Hash
import qualified Data.ByteString.Lazy as L import qualified Data.ByteString.Lazy as L
import qualified Data.ByteString.Char8 as C8 import qualified Data.ByteString.Char8 as C8
#ifndef WITH_CRYPTOHASH
import Data.Digest.Pure.SHA
#else
import Crypto.Hash
sha1 :: L.ByteString -> Digest SHA1 sha1 :: L.ByteString -> Digest SHA1
sha1 = hashlazy sha1 = hashlazy
@ -33,6 +50,8 @@ skein256 = hashlazy
skein512 :: L.ByteString -> Digest Skein512_512 skein512 :: L.ByteString -> Digest Skein512_512
skein512 = hashlazy skein512 = hashlazy
#endif
{- Check that all the hashes continue to hash the same. -} {- Check that all the hashes continue to hash the same. -}
prop_hashes_stable :: Bool prop_hashes_stable :: Bool
prop_hashes_stable = all (\(hasher, result) -> hasher foo == result) prop_hashes_stable = all (\(hasher, result) -> hasher foo == result)
@ -41,8 +60,10 @@ prop_hashes_stable = all (\(hasher, result) -> hasher foo == result)
, (show . sha256, "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae") , (show . sha256, "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae")
, (show . sha384, "98c11ffdfdd540676b1a137cb1a22b2a70350c9a44171d6b1180c6be5cbb2ee3f79d532c8a1dd9ef2e8e08e752a3babb") , (show . sha384, "98c11ffdfdd540676b1a137cb1a22b2a70350c9a44171d6b1180c6be5cbb2ee3f79d532c8a1dd9ef2e8e08e752a3babb")
, (show . sha512, "f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7") , (show . sha512, "f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7")
#ifdef WITH_CRYPTOHASH
, (show . skein256, "a04efd9a0aeed6ede40fe5ce0d9361ae7b7d88b524aa19917b9315f1ecf00d33") , (show . skein256, "a04efd9a0aeed6ede40fe5ce0d9361ae7b7d88b524aa19917b9315f1ecf00d33")
, (show . skein512, "fd8956898113510180aa4658e6c0ac85bd74fb47f4a4ba264a6b705d7a8e8526756e75aecda12cff4f1aca1a4c2830fbf57f458012a66b2b15a3dd7d251690a7") , (show . skein512, "fd8956898113510180aa4658e6c0ac85bd74fb47f4a4ba264a6b705d7a8e8526756e75aecda12cff4f1aca1a4c2830fbf57f458012a66b2b15a3dd7d251690a7")
#endif
] ]
where where
foo = L.fromChunks [C8.pack "foo"] foo = L.fromChunks [C8.pack "foo"]

View file

@ -7,7 +7,7 @@ quite a lot.
* [MissingH](http://github.com/jgoerzen/missingh/wiki) * [MissingH](http://github.com/jgoerzen/missingh/wiki)
* [utf8-string](http://hackage.haskell.org/package/utf8-string) * [utf8-string](http://hackage.haskell.org/package/utf8-string)
* [SHA](http://hackage.haskell.org/package/SHA) * [SHA](http://hackage.haskell.org/package/SHA)
* [cryptohash](http://hackage.haskell.org/package/cryptohash) * [cryptohash](http://hackage.haskell.org/package/cryptohash) (optional but recommended)
* [dataenc](http://hackage.haskell.org/package/dataenc) * [dataenc](http://hackage.haskell.org/package/dataenc)
* [monad-control](http://hackage.haskell.org/package/monad-control) * [monad-control](http://hackage.haskell.org/package/monad-control)
* [QuickCheck 2](http://hackage.haskell.org/package/QuickCheck) * [QuickCheck 2](http://hackage.haskell.org/package/QuickCheck)

View file

@ -71,12 +71,15 @@ Flag Feed
Flag Quvi Flag Quvi
Description: Enable use of quvi to download videos Description: Enable use of quvi to download videos
Flag CryptoHash
Description: Enable use of cryptohash for checksumming
Executable git-annex Executable git-annex
Main-Is: git-annex.hs Main-Is: git-annex.hs
Build-Depends: MissingH, hslogger, directory, filepath, Build-Depends: MissingH, hslogger, directory, filepath,
containers, utf8-string, network (>= 2.0), mtl (>= 2), containers, utf8-string, network (>= 2.0), mtl (>= 2),
bytestring, old-locale, time, HTTP, bytestring, old-locale, time, HTTP,
extensible-exceptions, dataenc, SHA, cryptohash, process, json, extensible-exceptions, dataenc, SHA, process, json,
base (>= 4.5 && < 4.8), monad-control, MonadCatchIO-transformers, base (>= 4.5 && < 4.8), monad-control, MonadCatchIO-transformers,
IfElse, text, QuickCheck >= 2.1, bloomfilter, edit-distance, process, IfElse, text, QuickCheck >= 2.1, bloomfilter, edit-distance, process,
SafeSemaphore, uuid, random, dlist, unix-compat SafeSemaphore, uuid, random, dlist, unix-compat
@ -107,6 +110,10 @@ Executable git-annex
Build-Depends: regex-tdfa Build-Depends: regex-tdfa
CPP-Options: -DWITH_TDFA CPP-Options: -DWITH_TDFA
if flag(CryptoHash)
Build-Depends: cryptohash (>= 0.10.0)
CPP-Options: -DWITH_CRYPTOHASH
if flag(S3) if flag(S3)
Build-Depends: hS3 Build-Depends: hS3
CPP-Options: -DWITH_S3 CPP-Options: -DWITH_S3