java-multihash icon indicating copy to clipboard operation
java-multihash copied to clipboard

Support for variable-length hashes

Open odisseus opened this issue 1 year ago • 0 comments

Some algorithms (such as SHAKE128) can generate an output of arbitrary length. For example, the following are all valid SHAKE128 hashes of the string hello in UTF-8:

8eb4
8eb4b6a932f28033
8eb4b6a932f280335ee1a279f8c208a3
8eb4b6a932f280335ee1a279f8c208a349e7bc65daf831d302

(generated by the online hash calculator)

In particular, this code should work:

Multihash m = Multihash.fromHex("18028eb4");

Whereas it currently fails with this exception:

java.lang.IllegalStateException: Incorrect hash length: 2 != 32

	at io.ipfs.multihash.Multihash.<init>(Multihash.java:162)
	at io.ipfs.multihash.Multihash.deserialize(Multihash.java:218)
	at io.ipfs.multihash.Multihash.deserialize(Multihash.java:223)
	at io.ipfs.multihash.Multihash.fromHex(Multihash.java:273)

odisseus avatar Jan 07 '25 08:01 odisseus