David K. Bainbridge | 215e024 | 2017-09-05 23:18:24 -0700 | [diff] [blame] | 1 | package digest |
| 2 | |
| 3 | import "hash" |
| 4 | |
| 5 | // Digester calculates the digest of written data. Writes should go directly |
| 6 | // to the return value of Hash, while calling Digest will return the current |
| 7 | // value of the digest. |
| 8 | type Digester interface { |
| 9 | Hash() hash.Hash // provides direct access to underlying hash instance. |
| 10 | Digest() Digest |
| 11 | } |
| 12 | |
| 13 | // digester provides a simple digester definition that embeds a hasher. |
| 14 | type digester struct { |
| 15 | alg Algorithm |
| 16 | hash hash.Hash |
| 17 | } |
| 18 | |
| 19 | func (d *digester) Hash() hash.Hash { |
| 20 | return d.hash |
| 21 | } |
| 22 | |
| 23 | func (d *digester) Digest() Digest { |
| 24 | return NewDigest(d.alg, d.hash) |
| 25 | } |