Skip to content
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

Store the multihash length as an uint32. #22

Closed
wants to merge 2 commits into from

Conversation

Stebalien
Copy link
Member

Some code constructs prefixes with negative lengths which means:

  1. cid1.Bytes() == cid2.Bytes() does not imply cid1.Prefix() == cid2.Prefix().
  2. Prefix.Bytes() is broken.

This commit fixes those issues by simply forbidding negative hash lengths in Prefix and providing nice constructors that lookup the default hash

Note: This also includes a 0.8.0 release to indicate that it breaks the API a bit.

Note2: It would be nice if the go-multihash used uint32 instead of int for hash lengths but fixing that is leads to a rats nest of problems stemming from the fact that:

  1. len returns an int.
  2. Sum accepts -1 as a length.

@Kubuxu Kubuxu added the status/in-progress In progress label Jun 20, 2017
@coveralls
Copy link

coveralls commented Jun 20, 2017

Coverage Status

Coverage increased (+66.3%) to 66.308% when pulling 9d756fe on Stebalien:fix/11 into 3f7f6c6 on ipfs:master.

Some code constructs prefixes with negative lengths which means:

1. `cid1.Bytes() == cid2.Bytes()` does not imply `cid1.Prefix() ==
   cid2.Prefix()`.

2. `Prefix.Bytes()` is broken.

This commit fixes those issues by simply forbidding negative hash lengths in
`Prefix` and providing nice constructors that lookup the default hash length.
This is clearly a breaking change.
@Stebalien
Copy link
Member Author

So, one problem with this solution is that not all hash functions have a reasonable default length (e.g., ID). See multiformats/go-multihash#55

@Stebalien Stebalien closed this Jul 13, 2017
@daviddias daviddias removed the status/in-progress In progress label Jul 13, 2017
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.

None yet

4 participants