Skip to content

Conversation

@imalsogreg
Copy link
Collaborator

@imalsogreg imalsogreg commented Sep 12, 2018

This PR supersedes PR #14 by moving hashing operations into a module and dropping cryptonite, basement and foundation dependencies, to facilitate adding hnix-store as a dependency of hnix.

Test of string hashing still fail, and we may want StorePathHash to 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

@imalsogreg imalsogreg requested a review from shlevy September 12, 2018 14:41
Copy link
Member

@shlevy shlevy left a 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 (..)
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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

@imalsogreg imalsogreg closed this Oct 22, 2018
Anton-Latukha added a commit that referenced this pull request Jun 9, 2021
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
Anton-Latukha added a commit that referenced this pull request Jun 9, 2021
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
Anton-Latukha added a commit that referenced this pull request Jun 9, 2021
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
Anton-Latukha added a commit that referenced this pull request Jun 10, 2021
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
Anton-Latukha added a commit that referenced this pull request Jun 10, 2021
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants