2015-03-05 04:26:56 +00:00
|
|
|
package digest
|
|
|
|
|
2016-12-15 23:06:18 +00:00
|
|
|
import "hash"
|
2015-05-22 01:44:08 +00: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-05 04:26:56 +00:00
|
|
|
}
|
|
|
|
|
2015-05-21 06:44:08 +00:00
|
|
|
// digester provides a simple digester definition that embeds a hasher.
|
|
|
|
type digester struct {
|
2015-05-22 01:44:08 +00:00
|
|
|
alg Algorithm
|
2015-05-21 06:44:08 +00:00
|
|
|
hash hash.Hash
|
2015-03-24 07:04:45 +00:00
|
|
|
}
|
|
|
|
|
2015-05-21 06:44:08 +00:00
|
|
|
func (d *digester) Hash() hash.Hash {
|
|
|
|
return d.hash
|
2015-03-05 04:26:56 +00:00
|
|
|
}
|
|
|
|
|
2015-05-21 06:44:08 +00:00
|
|
|
func (d *digester) Digest() Digest {
|
2015-05-22 01:44:08 +00:00
|
|
|
return NewDigest(d.alg, d.hash)
|
2015-03-05 04:26:56 +00:00
|
|
|
}
|