multiformats / go-multihash

Multihash implementation in Go
MIT License
239 stars 57 forks source link

feat: add support for variable length hash functions #159

Closed Stebalien closed 2 years ago

Stebalien commented 2 years ago

This makes it possible to register hasher factories that take a size hint. Such hashers should produce at least the requested number of bytes, but may:

  1. Produce fewer bytes in some cases (e.g., not enough input is available).
  2. May produce more bytes (the usual case).

The caller should check the size of the produced digest to determine if it's sufficient for the caller's use-case (likely truncating it if it's too large).

NOTE: the convenience Sum function will handle size verification and truncation internally.

TODO:

I'm posting this as a "here's how to do it", but someone else will have to take it to completion if we want to merge this.

laudiacay commented 2 years ago

160 accomplishes all those to-dos, I think!