Skip to content

Support for variable-length hashes #45

Description

@odisseus

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions