hardening

package
v0.4.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

func (*VerifiedReadCloser) Read

func (v *VerifiedReadCloser) Read(p []byte) (n int, err error)

Read is a wrapper around VerifiedReadCloser.Reader, with a digest check on EOF. Make sure that you always check for EOF and read-to-the-end for all files.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL