ensure that hash representations don't change in future
This commit is contained in:
parent
29385dc393
commit
547a18019f
3 changed files with 23 additions and 6 deletions
|
@ -136,12 +136,6 @@ hashFile hash file filesize = do
|
|||
=<< externalSHA command hashsize file
|
||||
go (SkeinHash hashsize) = skeinHasher hashsize <$> L.readFile file
|
||||
|
||||
skeinHasher :: HashSize -> (L.ByteString -> String)
|
||||
skeinHasher hashsize
|
||||
| hashsize == 256 = show . skein256
|
||||
| hashsize == 512 = show . skein512
|
||||
| otherwise = error $ "bad skein size " ++ show hashsize
|
||||
|
||||
shaCommand :: HashSize -> Integer -> Either (L.ByteString -> String) String
|
||||
shaCommand hashsize filesize
|
||||
| hashsize == 1 = use SysConfig.sha1 sha1
|
||||
|
@ -160,3 +154,9 @@ shaCommand hashsize filesize
|
|||
- process unless the file is large. -}
|
||||
| filesize < 1048576 = use Nothing hasher
|
||||
| otherwise = Right c
|
||||
|
||||
skeinHasher :: HashSize -> (L.ByteString -> String)
|
||||
skeinHasher hashsize
|
||||
| hashsize == 256 = show . skein256
|
||||
| hashsize == 512 = show . skein512
|
||||
| otherwise = error $ "bad skein size " ++ show hashsize
|
||||
|
|
2
Test.hs
2
Test.hs
|
@ -58,6 +58,7 @@ import qualified Utility.InodeCache
|
|||
import qualified Utility.Env
|
||||
import qualified Utility.Matcher
|
||||
import qualified Utility.Exception
|
||||
import qualified Utility.Hash
|
||||
#ifndef mingw32_HOST_OS
|
||||
import qualified GitAnnex
|
||||
import qualified Remote.Helper.Encryptable
|
||||
|
@ -136,6 +137,7 @@ quickcheck =
|
|||
, check "prop_parse_show_log" Logs.Presence.prop_parse_show_log
|
||||
, check "prop_read_show_TrustLevel" Types.TrustLevel.prop_read_show_TrustLevel
|
||||
, check "prop_parse_show_TrustLog" Logs.Trust.prop_parse_show_TrustLog
|
||||
, check "prop_hashes_stable" Utility.Hash.prop_hashes_stable
|
||||
]
|
||||
where
|
||||
check desc prop = do
|
||||
|
|
|
@ -6,6 +6,7 @@ module Utility.Hash where
|
|||
|
||||
import Crypto.Hash
|
||||
import qualified Data.ByteString.Lazy as L
|
||||
import qualified Data.ByteString.Char8 as C8
|
||||
|
||||
sha1 :: L.ByteString -> Digest SHA1
|
||||
sha1 = hashlazy
|
||||
|
@ -31,3 +32,17 @@ skein256 = hashlazy
|
|||
|
||||
skein512 :: L.ByteString -> Digest Skein512_512
|
||||
skein512 = hashlazy
|
||||
|
||||
{- Check that all the hashes continue to hash the same. -}
|
||||
prop_hashes_stable :: Bool
|
||||
prop_hashes_stable = all (\(hasher, result) -> hasher foo == result)
|
||||
[ (show . sha1, "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33")
|
||||
, (show . sha224, "0808f64e60d58979fcb676c96ec938270dea42445aeefcd3a4e6f8db")
|
||||
, (show . sha256, "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae")
|
||||
, (show . sha384, "98c11ffdfdd540676b1a137cb1a22b2a70350c9a44171d6b1180c6be5cbb2ee3f79d532c8a1dd9ef2e8e08e752a3babb")
|
||||
, (show . sha512, "f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7")
|
||||
, (show . skein256, "a04efd9a0aeed6ede40fe5ce0d9361ae7b7d88b524aa19917b9315f1ecf00d33")
|
||||
, (show . skein512, "fd8956898113510180aa4658e6c0ac85bd74fb47f4a4ba264a6b705d7a8e8526756e75aecda12cff4f1aca1a4c2830fbf57f458012a66b2b15a3dd7d251690a7")
|
||||
]
|
||||
where
|
||||
foo = L.fromChunks [C8.pack "foo"]
|
||||
|
|
Loading…
Add table
Reference in a new issue