-
Notifications
You must be signed in to change notification settings - Fork 24
Refactor System.Nix.Hash to drop cryptonite dependency #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Cleanup haddock parse errors
shlevy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seem to be a few confusions around base32 handling
| , finalize | ||
|
|
||
| -- * Internal | ||
| , StorePathHash (..) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to export these, let's have a System.Nix.Hash.Internal. For a non-internal module, I'd expect to be able to look at the types and assume it's safe to use these to construct my hashes
|
|
||
|
|
||
| hash :: BS.ByteString -> StorePathHash | ||
| hash bs = StorePathHash . BSL.toStrict . toNixBase32 . BSL.fromStrict . truncate' $ SHA.hash bs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, base32 stuff definitely doesn't belong here. Hashes are just numbers, they're not character strings. The result of SHA.hash viewed as a bytestring is a "base-256" representation of that number, not an ascii-based hex encoding.
| deriving (Eq, Hashable.Hashable, Ord, Show) | ||
|
|
||
|
|
||
| init :: SHA.Ctx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we encapsulate the context type here?
|
|
||
|
|
||
| -- | Import and validate a store path hash | ||
| fromBase32 :: BS.ByteString -> Maybe StorePathHash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
base 32/base 16 questions should just be about presentation, not about internal represenation
| spec_hashBase32truncateParity = describe "hashBase32" $ | ||
| for_ testCases $ \(testCase, expectation) -> | ||
| it ("computes correct base32 hash for string " <> BSC.unpack testCase) $ | ||
| getTruncatedHash (hash testCase) `shouldBe` expectation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it shouldn't 😉
| queryPathFromHashPart d = do | ||
| runOpArgs QueryPathFromHashPart $ | ||
| putByteStringLen $ LBS.fromStrict $ convert d | ||
| putByteStringLen $ LBS.fromStrict $ getTruncatedHash d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we do need to convert to base32, since we're talking to the daemon.
| type PathFilter = Path -> Bool | ||
| addToStore :: LBS.ByteString -> Path -> Bool -> PathHashAlgo -> PathFilter -> RepairFlag -> MonadStore Path | ||
| addToStore name pth recursive hashAlgo pfilter repair = undefined -- XXX | ||
| addToStore :: LBS.ByteString -> Path -> Bool -> PathFilter -> RepairFlag -> MonadStore Path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this argument dropped? We should be able to pass different hash algorithms to this operation, we can add things to the store based on e.g. md5 or sha512 hash
Reference: Main cause: haskell-hvr/cryptohash-sha512#7 The whole `cryptohash-*` package family is abandoned, there is no signs of maintainer activity there, so it stopped following Haskell ecosystem & `base` releases. Knowing the human history & situation around it - it would not be reviwed, which gives experience to not hardcode on the (specifically when emotional) dependency. Experience I drawn from this story is to keep things simplier when possible & have more flexible systems as a result code. It was "a bit too much" for what hashing is, for the code to have 2 hashing type systems (external & internal) & reinventment of `HashAlgorithm` type duplicate. The whole code was really rigid with a lot of type applicating the data kinds, those are dependent type features & should be used cautiously, since interface became rigid to changes, so afterwards it is easier to dismantle and recreate the subsystem then to evolve it. Previous hashing history: #156 #142 #93 #92 #90 #83 #64 #38 #32 #31 #28 #27 #25 #18 #14
Reference: Main cause: haskell-hvr/cryptohash-sha512#7 The whole `cryptohash-*` package family is abandoned, there is no signs of maintainer activity there, so it stopped following Haskell ecosystem & `base` releases. Knowing the human history & situation around it - it would not be reviwed, which gives experience to not hardcode on the (specifically when emotional) dependency. Experience I drawn from this story is to keep things simplier when possible & have more flexible systems as a result code. It was "a bit too much" for what hashing is, for the code to have 2 hashing type systems (external & internal) & reinventment of `HashAlgorithm` type duplicate. The whole code was really rigid with a lot of type applicating the data kinds, those are dependent type features & should be used cautiously, since interface became rigid to changes, so afterwards it is easier & effective to dismantle and recreate the subsystem then to evolve it. Previous hashing history: #156 #142 #93 #92 #90 #83 #64 #38 #32 #31 #28 #27 #25 #18 #14
Reference: Main cause: haskell-hvr/cryptohash-sha512#7 The whole `cryptohash-*` package family is abandoned, there is no signs of maintainer activity there, so it stopped following Haskell ecosystem & `base` releases. Knowing the human history & situation around it - it would not be reviwed, which gives experience to not hardcode on the (specifically when emotional) dependency. Experience I drawn from this story is to keep things simplier when possible & have more flexible systems as a result code. It was "a bit too much" for what hashing is, for the code to have 2 hashing type systems (external & internal) & reinventment of `HashAlgorithm` type duplicate. The whole code was really rigid with a lot of type applicating the data kinds, those are dependent type features & should be used cautiously, since interface became rigid to changes, so afterwards it is easier & effective to dismantle and recreate the subsystem then to evolve it. Previous hashing history: #156 #142 #93 #92 #90 #83 #64 #38 #32 #31 #28 #27 #25 #18 #14
Reference: Main cause: haskell-hvr/cryptohash-sha512#7 The whole `cryptohash-*` package family is abandoned, there is no signs of maintainer activity there, so it stopped following Haskell ecosystem & `base` releases. Knowing the human history & situation around it - it would not be reviwed, which gives experience to not hardcode on the (specifically when emotional) dependency. Experience I drawn from this story is to keep things simplier when possible & have more flexible systems as a result code. It was "a bit too much" for what hashing is, for the code to have 2 hashing type systems (external & internal) & reinventment of `HashAlgorithm` type duplicate. The whole code was really rigid with a lot of type applicating the data kinds, those are dependent type features & should be used cautiously, since interface became rigid to changes, so afterwards it is easier & effective to dismantle and recreate the subsystem then to evolve it. Previous hashing history: #156 #142 #93 #92 #90 #83 #64 #38 #32 #31 #28 #27 #25 #18 #14
Reference: Main cause: haskell-hvr/cryptohash-sha512#7 The whole `cryptohash-*` package family is abandoned, there is no signs of maintainer activity there, so it stopped following Haskell ecosystem & `base` releases. Knowing the human history & situation around it - it would not be reviwed, which gives experience to not hardcode on the (specifically when emotional) dependency. Experience I drawn from this story is to keep things simplier when possible & have more flexible systems as a result code. It was "a bit too much" for what hashing is, for the code to have 2 hashing type systems (external & internal) & reinventment of `HashAlgorithm` type duplicate. The whole code was really rigid with a lot of type applicating the data kinds, those are dependent type features & should be used cautiously, since interface became rigid to changes, so afterwards it is easier & effective to dismantle and recreate the subsystem then to evolve it. Previous hashing history: #156 #142 #93 #92 #90 #83 #64 #38 #32 #31 #28 #27 #25 #18 #14
This PR supersedes PR #14 by moving hashing operations into a module and dropping
cryptonite,basementandfoundationdependencies, to facilitate addinghnix-storeas a dependency ofhnix.Test of string hashing still fail, and we may want
StorePathHashto encapsulate a raw bytestring, rather than the truncated, base32 encoded version - but maybe we should make those changes together in a new PR?String hashing test failure is tracked in #24