2015-03-04 20:26:56 -08:00
|
|
|
package digest
|
|
|
|
|
2016-12-15 15:06:18 -08:00
|
|
|
import "hash"
|
2015-05-21 18:44:08 -07:00
|
|
|
|
|
|
|
// Digester calculates the digest of written data. Writes should go directly
|
|
|
|
// to the return value of Hash, while calling Digest will return the current
|
|
|
|
// value of the digest.
|
|
|
|
type Digester interface {
|
|
|
|
Hash() hash.Hash // provides direct access to underlying hash instance.
|
|
|
|
Digest() Digest
|
2015-03-04 20:26:56 -08:00
|
|
|
}
|
|
|
|
|
2015-05-20 23:44:08 -07:00
|
|
|
// digester provides a simple digester definition that embeds a hasher.
|
|
|
|
type digester struct {
|
2015-05-21 18:44:08 -07:00
|
|
|
alg Algorithm
|
2015-05-20 23:44:08 -07:00
|
|
|
hash hash.Hash
|
2015-03-24 00:04:45 -07:00
|
|
|
}
|
|
|
|
|
2015-05-20 23:44:08 -07:00
|
|
|
func (d *digester) Hash() hash.Hash {
|
|
|
|
return d.hash
|
2015-03-04 20:26:56 -08:00
|
|
|
}
|
|
|
|
|
2015-05-20 23:44:08 -07:00
|
|
|
func (d *digester) Digest() Digest {
|
2015-05-21 18:44:08 -07:00
|
|
|
return NewDigest(d.alg, d.hash)
|
2015-03-04 20:26:56 -08:00
|
|
|
}
|