You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most hashers in the standard library implement encoding.BinaryMarshaler and encoding.BinaryUnmarshaler. Using those interfaces does make sense in some situations, with the drawback that they won't work with hashers that don't implement them and that it is using encoding methods to clone feels hacky. For example, the Go team at Microsoft maintain some Go bindings for Windows CNG (see repo), and CNG doesn't support serializing the hash internal state.
After analyzing the code of the projects in the list, we found that the encoding.BinaryMarshaler interface is mostly used in the following ways:
To serialize the hasher state to disk or to a network connection so that it can be restored later.
To clone a hasher so that the cloned hasher does not have to recompute the hash over the same data, which might be expensive or even impossible due to the data not being available anymore.
I propose to define an interface that is easier to implement by hash providers:
This reads a bit like your message was truncated accidentally (?). Did you happen to collect up a real-world set of examples where this is beneficial?
This is a half-backed proposal. It got submitted by mistake after a network connection glitch. I've updated the description with some more details I had in mind. Hope it helps.
I'll not reopen this issue, though. I like how #69521 is heading.
Most hashers in the standard library implement encoding.BinaryMarshaler and encoding.BinaryUnmarshaler. Using those interfaces does make sense in some situations, with the drawback that they won't work with hashers that don't implement them and that it is using encoding methods to clone feels hacky. For example, the Go team at Microsoft maintain some Go bindings for Windows CNG (see repo), and CNG doesn't support serializing the hash internal state.
See https://github.com/search?q=language%3AGo+h.%28encoding.BinaryMarshaler%29&type=code for a none-exhaustive list of projects that use the
encoding.BinaryMarshaler
interface.After analyzing the code of the projects in the list, we found that the
encoding.BinaryMarshaler
interface is mostly used in the following ways:I propose to define an interface that is easier to implement by hash providers:
In addition to the above, we would update all hashers in the stdlib that implement
hash.Cloner
.Examples of projects cloning a hash:
go/src/crypto/tls/handshake_server_tls13.go
Line 436 in 2707d42
The text was updated successfully, but these errors were encountered: