File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -150,8 +150,11 @@ newtype Digest (a :: HashAlgorithm) = Digest
150150printHashBytes32 :: BS. ByteString -> T. Text
151151printHashBytes32 c = T. pack $ concatMap char32 [nChar - 1 , nChar - 2 .. 0 ]
152152 where
153- -- The base32 encoding is 8/5's as long as the base256 digest
154- nChar = fromIntegral $ BS. length c * 8 `div` 5
153+ -- The base32 encoding is 8/5's as long as the base256 digest. This `+ 1`
154+ -- `- 1` business is a bit odd, but has always been used in C++ since the
155+ -- base32 truncation was added in was first added in
156+ -- d58a11e019813902b6c4547ca61a127938b2cc20.
157+ nChar = fromIntegral $ ((BS. length c * 8 - 1 ) `div` 5 ) + 1
155158
156159 char32 :: Integer -> [Char ]
157160 char32 i = [digits32 V. ! digitInd]
Original file line number Diff line number Diff line change @@ -31,6 +31,10 @@ spec_hash = do
3131
3232 describe " hashing parity with nix-store" $ do
3333
34+ it " produces (base32 . sha256) of \" nix-output:foo\" the same as Nix does at the moment for placeholder \" foo\" " $
35+ shouldBe (printAsBase32 (hash @ SHA256 " nix-output:foo" ))
36+ " 1x0ymrsy7yr7i9wdsqy9khmzc1yy7nvxw6rdp72yzn50285s67j5"
37+
3438 it " produces (base32 . sha1) of \" Hello World\" the same as the thesis" $
3539 shouldBe (printAsBase32 (hash @ SHA1 " Hello World" ))
3640 " s23c9fs0v32pf6bhmcph5rbqsyl5ak8a"
You can’t perform that action at this time.
0 commit comments