Fix: validate multihash in CIDv0 constructor#74
Conversation
5d1e9f4 to
5ed18b1
Compare
bfe9ff5 to
76d1c8b
Compare
|
@sumanjeet0012 : Excellent work on this PR. Wish to share that I particularly like that you not only implemented the validation logic in It is also great to see that 23 out of 24 CI checks are already passing across multiple Python versions and Windows. The remaining documentation check appears to be an environment/configuration issue ( Sharing the logs of 1 CI/CD issue, which can be resolved quickly. Run python -m tox run -r Good job, and thank you for putting together such a thoughtful fix along with comprehensive test coverage. @acul71: We will do a py-cid release this Wednesday once this PR and others are ready for merge. CCing @johannamoran and @mishmosh. |
|
LGTM :) |
Closes #63
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).