From ecf4d991f92b1d2607ad392fc91befd1cfa13ed3 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sun, 10 Mar 2019 13:09:45 -0400 Subject: [PATCH] Add comment to the mysterious order of the `+ 1` `- 1` in `printHashBytes32` --- hnix-store-core/src/System/Nix/Internal/Hash.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hnix-store-core/src/System/Nix/Internal/Hash.hs b/hnix-store-core/src/System/Nix/Internal/Hash.hs index d91095e..eef68cf 100644 --- a/hnix-store-core/src/System/Nix/Internal/Hash.hs +++ b/hnix-store-core/src/System/Nix/Internal/Hash.hs @@ -125,7 +125,10 @@ 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 + -- 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]