multiformats / ruby-multihash

A simple multihash (https://github.com/multiformats/multihash) implementation for ruby.
MIT License
22 stars 13 forks source link

Fix Multihash.decode <all zeros> #8

Closed singpolyma closed 4 years ago

singpolyma commented 4 years ago

Previously a bytestring of all zeros would result in an exception being raised about the length being wrong, even with a correct length.

kvdenden commented 4 years ago

:+1:

I encountered the same issue when trying to decode this IPFS hash QmSdDyfTcVXHsqawjWBirhTU2rpPiDEVvPXgxfGeUD7Tqh

multihash_binary_string = Base58.base58_to_binary(ipfs_hash, :bitcoin)
multihash = Multihashes.decode(multihash_binary_string)

The digest has a trailing zero which causes Multihashes.decode to raise a Multihashes::DigestLengthError exception.

kyledrake commented 4 years ago

Thank you! (tests pass, Travis had an issue).