cbergoon / merkletree

A Merkle Tree implementation written in Go.
MIT License
495 stars 125 forks source link

Allow a configurable hash function #9

Closed absfox closed 5 years ago

absfox commented 5 years ago

I was wondering if you would be open to supporting a configurable hash function.

In other words pass the hash function as an argument along with the content list when building the tree. Something like:

merkle.NewTree(list, sha256.New)

cbergoon commented 5 years ago

Sounds like a great idea. I'd like to preserve the original API and create a new "New" function (e.g. NewTreeWithHashStrategy(list, sha256.New)). The original NewTree(list) function could set the default to the hash function that is currently used.

Cam

cbergoon commented 5 years ago

@absfox

I added the below function to allow the hash function to be configurable.

func NewTreeWithHashStrategy(cs []Content, hashStrategy func() hash.Hash) (*MerkleTree, error)

The default hash remains sha256.