aboutsummaryrefslogtreecommitdiff
path: root/src/hash
diff options
context:
space:
mode:
authorRoger Peppe <rogpeppe@gmail.com>2017-11-12 22:19:11 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2017-11-15 00:06:24 +0000
commitbd926e1c65557870d152c42265af7533981fae8a (patch)
treef9ec95231ac9bbb27b4fd9d9519ddbf0a6000b5a /src/hash
parenta158382b1c9c0b95a7d41865a405736be6bc585f (diff)
downloadgo-bd926e1c65557870d152c42265af7533981fae8a.tar.gz
go-bd926e1c65557870d152c42265af7533981fae8a.zip
crypto, hash: document marshal/unmarshal implementation
Unless you go back and read the hash package documentation, it's not clear that all the hash packages implement marshaling and unmarshaling. Document the behaviour specifically in each package that implements it as it this is hidden behaviour and easy to miss. Change-Id: Id9d3508909362f1a3e53872d0319298359e50a94 Reviewed-on: https://go-review.googlesource.com/77251 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Diffstat (limited to 'src/hash')
-rw-r--r--src/hash/adler32/adler32.go7
-rw-r--r--src/hash/crc32/crc32.go16
-rw-r--r--src/hash/crc64/crc64.go8
-rw-r--r--src/hash/fnv/fnv.go4
4 files changed, 24 insertions, 11 deletions
diff --git a/src/hash/adler32/adler32.go b/src/hash/adler32/adler32.go
index 149a6b889e..e8783e4c39 100644
--- a/src/hash/adler32/adler32.go
+++ b/src/hash/adler32/adler32.go
@@ -35,8 +35,11 @@ type digest uint32
func (d *digest) Reset() { *d = 1 }
-// New returns a new hash.Hash32 computing the Adler-32 checksum.
-// Its Sum method will lay the value out in big-endian byte order.
+// New returns a new hash.Hash32 computing the Adler-32 checksum. Its
+// Sum method will lay the value out in big-endian byte order. The
+// returned Hash32 also implements encoding.BinaryMarshaler and
+// encoding.BinaryUnmarshaler to marshal and unmarshal the internal
+// state of the hash.
func New() hash.Hash32 {
d := new(digest)
d.Reset()
diff --git a/src/hash/crc32/crc32.go b/src/hash/crc32/crc32.go
index db05f124c4..1912caa212 100644
--- a/src/hash/crc32/crc32.go
+++ b/src/hash/crc32/crc32.go
@@ -139,9 +139,11 @@ type digest struct {
tab *Table
}
-// New creates a new hash.Hash32 computing the CRC-32 checksum
-// using the polynomial represented by the Table.
-// Its Sum method will lay the value out in big-endian byte order.
+// New creates a new hash.Hash32 computing the CRC-32 checksum using the
+// polynomial represented by the Table. Its Sum method will lay the
+// value out in big-endian byte order. The returned Hash32 also
+// implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler to
+// marshal and unmarshal the internal state of the hash.
func New(tab *Table) hash.Hash32 {
if tab == IEEETable {
ieeeOnce.Do(ieeeInit)
@@ -149,9 +151,11 @@ func New(tab *Table) hash.Hash32 {
return &digest{0, tab}
}
-// NewIEEE creates a new hash.Hash32 computing the CRC-32 checksum
-// using the IEEE polynomial.
-// Its Sum method will lay the value out in big-endian byte order.
+// NewIEEE creates a new hash.Hash32 computing the CRC-32 checksum using
+// the IEEE polynomial. Its Sum method will lay the value out in
+// big-endian byte order. The returned Hash32 also implements
+// encoding.BinaryMarshaler and encoding.BinaryUnmarshaler to marshal
+// and unmarshal the internal state of the hash.
func NewIEEE() hash.Hash32 { return New(IEEETable) }
func (d *digest) Size() int { return Size }
diff --git a/src/hash/crc64/crc64.go b/src/hash/crc64/crc64.go
index 54c942c97a..3b24c24406 100644
--- a/src/hash/crc64/crc64.go
+++ b/src/hash/crc64/crc64.go
@@ -80,9 +80,11 @@ type digest struct {
tab *Table
}
-// New creates a new hash.Hash64 computing the CRC-64 checksum
-// using the polynomial represented by the Table.
-// Its Sum method will lay the value out in big-endian byte order.
+// New creates a new hash.Hash64 computing the CRC-64 checksum using the
+// polynomial represented by the Table. Its Sum method will lay the
+// value out in big-endian byte order. The returned Hash64 also
+// implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler to
+// marshal and unmarshal the internal state of the hash.
func New(tab *Table) hash.Hash64 { return &digest{0, tab} }
func (d *digest) Size() int { return Size }
diff --git a/src/hash/fnv/fnv.go b/src/hash/fnv/fnv.go
index 99c892000b..7662315d43 100644
--- a/src/hash/fnv/fnv.go
+++ b/src/hash/fnv/fnv.go
@@ -6,6 +6,10 @@
// created by Glenn Fowler, Landon Curt Noll, and Phong Vo.
// See
// https://en.wikipedia.org/wiki/Fowler-Noll-Vo_hash_function.
+//
+// All the hash.Hash implementations returned by this package also
+// implement encoding.BinaryMarshaler and encoding.BinaryUnmarshaler to
+// marshal and unmarshal the internal state of the hash.
package fnv
import (