Fix: validate multihash in CIDv0 constructor (fixes #63)#74
Open
sumanjeet0012 wants to merge 2 commits into
Open
Fix: validate multihash in CIDv0 constructor (fixes #63)#74sumanjeet0012 wants to merge 2 commits into
sumanjeet0012 wants to merge 2 commits into
Conversation
5d1e9f4 to
5ed18b1
Compare
bfe9ff5 to
76d1c8b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes issue #63 by adding validation to the
CIDv0constructor to ensure the provided multihash uses thesha2-256algorithm and has a 32-byte digest, as required by the CID specification.Changes
CIDv0.__init__to decode and validate the multihash code (must be0x12forsha2-256) and length (must be32). Raises aValueErrorif the multihash is invalid.test_cidv0_rejects_non_sha256andtest_cidv0_rejects_truncated_digestintests/test_cid.py.test_cid.pyandtest_new_features.pythat were improperly creatingCIDv0objects using non-compliant hashes or raw byte strings (which now fail due to the new strict validation).