mirror of
https://github.com/haskell-nix/hnix-store.git
synced 2024-11-27 18:45:57 +03:00
Merge pull request #31 from haskell-nix/je-printHashBytes32-bit-fiddling
Weird bit fiddling to make `printHashBytes32` work
This commit is contained in:
commit
8cc6595803
@ -150,8 +150,11 @@ newtype Digest (a :: HashAlgorithm) = Digest
|
||||
printHashBytes32 :: BS.ByteString -> T.Text
|
||||
printHashBytes32 c = T.pack $ concatMap char32 [nChar - 1, nChar - 2 .. 0]
|
||||
where
|
||||
-- The base32 encoding is 8/5's as long as the base256 digest
|
||||
nChar = fromIntegral $ BS.length c * 8 `div` 5
|
||||
-- The base32 encoding is 8/5's as long as the base256 digest. This `+ 1`
|
||||
-- `- 1` business is a bit odd, but has always been used in C++ since the
|
||||
-- base32 truncation was added in was first added in
|
||||
-- d58a11e019813902b6c4547ca61a127938b2cc20.
|
||||
nChar = fromIntegral $ ((BS.length c * 8 - 1) `div` 5) + 1
|
||||
|
||||
char32 :: Integer -> [Char]
|
||||
char32 i = [digits32 V.! digitInd]
|
||||
|
@ -31,6 +31,10 @@ spec_hash = do
|
||||
|
||||
describe "hashing parity with nix-store" $ do
|
||||
|
||||
it "produces (base32 . sha256) of \"nix-output:foo\" the same as Nix does at the moment for placeholder \"foo\"" $
|
||||
shouldBe (printAsBase32 (hash @SHA256 "nix-output:foo"))
|
||||
"1x0ymrsy7yr7i9wdsqy9khmzc1yy7nvxw6rdp72yzn50285s67j5"
|
||||
|
||||
it "produces (base32 . sha1) of \"Hello World\" the same as the thesis" $
|
||||
shouldBe (printAsBase32 (hash @SHA1 "Hello World"))
|
||||
"s23c9fs0v32pf6bhmcph5rbqsyl5ak8a"
|
||||
|
Loading…
Reference in New Issue
Block a user