blob: f1db6cda8427dfc79816171b6676445d7cdfb448 [file] [log] [blame]
David K. Bainbridge215e0242017-09-05 23:18:24 -07001package digest
2
3import (
4 "hash"
5 "io"
6)
7
8// Verifier presents a general verification interface to be used with message
9// digests and other byte stream verifications. Users instantiate a Verifier
10// from one of the various methods, write the data under test to it then check
11// the result with the Verified method.
12type Verifier interface {
13 io.Writer
14
15 // Verified will return true if the content written to Verifier matches
16 // the digest.
17 Verified() bool
18}
19
20type hashVerifier struct {
21 digest Digest
22 hash hash.Hash
23}
24
25func (hv hashVerifier) Write(p []byte) (n int, err error) {
26 return hv.hash.Write(p)
27}
28
29func (hv hashVerifier) Verified() bool {
30 return hv.digest == NewDigest(hv.digest.Algorithm(), hv.hash)
31}