Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrDigestMismatch = errors.Errorf("verified reader digest mismatch") ErrSizeMismatch = errors.Errorf("verified reader size mismatch") )
Exported errors for verification issues that occur during processing within VerifiedReadCloser. Note that you will need to use "github.com/pkg/errors".Cause to get these exported errors in most cases.
Functions ¶
This section is empty.
Types ¶
type VerifiedReadCloser ¶
type VerifiedReadCloser struct { // Reader is the underlying reader. Reader io.ReadCloser // ExpectedDigest is the expected digest. When the underlying reader // returns an EOF, the entire stream's sum will be compared to this hash // and an error will be returned if they don't match. ExpectedDigest digest.Digest // ExpectedSize is the expected amount of data to be read overall. If the // underlying reader hasn't returned an EOF by the time this value is // exceeded, an error is returned and no further reads will occur. ExpectedSize int64 // contains filtered or unexported fields }
VerifiedReadCloser is a basic io.ReadCloser which allows for simple verification that a stream matches an expected hash. The entire stream is hashed while being passed through this reader, and on EOF it will verify that the hash matches the expected hash. If not, an error is returned. Note that this means you need to read all input to EOF in order to find verification errors.
If Reader is a VerifiedReadCloser (with the same ExpectedDigest), all of the methods are just piped to the underlying methods (with no verification in the upper layer).
func (*VerifiedReadCloser) Close ¶
func (v *VerifiedReadCloser) Close() error
Close is a wrapper around VerifiedReadCloser.Reader, but with a digest check which will return an error if the underlying Close() didn't.