Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hash: allow Hash to implement encoding.BinaryMarshaler, encoding.BinaryUnmarshaler #20573

Closed
Capstan opened this issue Jun 4, 2017 · 4 comments

Comments

@Capstan
Copy link

Capstan commented Jun 4, 2017

There are some use cases that aren't met by current hashing functions

  • Serialize state of a partial byte stream processing for later work; recalculating the hash from the beginning is inefficient and, in our case, infeasible due to the size of the data and legacy compatibility requirements that inhibit use of, say, a Merkle tree.
  • Sharing calculation of common prefix hashes; this only requires in-memory copying rather than serialization.
  • Conditional append based on hash matches, which is a corollary of the previous.

Previous thread on golang-dev.

In my specific case, I'm looking for MD5 [de]serialization.

/cc @jlhawn

@bradfitz
Copy link
Contributor

bradfitz commented Jun 5, 2017

Seems like we could make the concrete types implement https://golang.org/pkg/encoding/#BinaryMarshaler and https://golang.org/pkg/encoding/#BinaryUnmarshaler at least.

We can't change the signature of e.g. https://golang.org/pkg/crypto/md5/#New but we could document in an Example that you can type-assert that the returned hash.Hash is also an encoding.BinaryUnmarshaler etc.

@bradfitz bradfitz changed the title FR: Serializable intermediate hash state proposal: Serializable intermediate hash state Jun 5, 2017
@gopherbot gopherbot added this to the Proposal milestone Jun 5, 2017
@rsc
Copy link
Contributor

rsc commented Jun 5, 2017

Any objections to hashes implementing BinaryMarshaler and BinaryUnmarshaler? Will leave this open for a week.

@bradfitz bradfitz changed the title proposal: Serializable intermediate hash state proposal: hash: Serializable intermediate hash state Jun 5, 2017
@rsc rsc changed the title proposal: hash: Serializable intermediate hash state hash: allow Hash to implement encoding.BinaryMarshaler, encoding.BinaryUnmarshaler Jun 12, 2017
@rsc rsc modified the milestones: Go1.10, Proposal Jun 12, 2017
@rsc
Copy link
Contributor

rsc commented Jun 12, 2017

Proposal accepted. CLs welcome for the Go 1.10 cycle for

  • Updating hash.Hash docs to document the convention.
  • Updating hash/* and crypto/* hashes to implement it.

@gopherbot
Copy link

Change https://golang.org/cl/66710 mentions this issue: crypto, hash: implement BinaryMarshaler, BinaryUnmarshaler in hash implementations

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants