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