hash

package
v0.0.0-...-9fdd194 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0, MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BadDigest

type BadDigest struct {
	ExpectedMD5   string
	CalculatedMD5 string
}

BadDigest - Content-MD5 you specified did not match what we received.

func (BadDigest) Error

func (e BadDigest) Error() string

type ErrSizeMismatch

type ErrSizeMismatch struct {
	Want int64
	Got  int64
}

ErrSizeMismatch error size mismatch

func (ErrSizeMismatch) Error

func (e ErrSizeMismatch) Error() string

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

A Reader wraps an io.Reader and computes the MD5 checksum of the read content as ETag. Optionally, it also computes the SHA256 checksum of the content.

If the reference values for the ETag and content SHA26 are not empty then it will check whether the computed match the reference values.

func NewReader

func NewReader(src io.Reader, size int64, md5Hex, sha256Hex string, actualSize int64) (*Reader, error)

NewReader returns a new Reader that wraps src and computes MD5 checksum of everything it reads as ETag.

It also computes the SHA256 checksum of everything it reads if sha256Hex is not the empty string.

If size resp. actualSize is unknown at the time of calling NewReader then it should be set to -1.

NewReader may try merge the given size, MD5 and SHA256 values into src - if src is a Reader - to avoid computing the same checksums multiple times.

func (*Reader) ActualSize

func (r *Reader) ActualSize() int64

ActualSize returns the pre-modified size of the object. DecompressedSize - For compressed objects.

func (*Reader) Close

func (r *Reader) Close() error

Close and release resources.

func (*Reader) ETag

func (r *Reader) ETag() etag.ETag

ETag returns the ETag computed by an underlying etag.Tagger. If the underlying io.Reader does not implement etag.Tagger it returns nil.

func (*Reader) MD5

func (r *Reader) MD5() []byte

MD5 returns the MD5 checksum set as reference value.

It corresponds to the checksum that is expected and not the actual MD5 checksum of the content. Therefore, refer to MD5Current.

func (*Reader) MD5Base64String

func (r *Reader) MD5Base64String() string

MD5Base64String returns a hex representation of the MD5.

func (*Reader) MD5Current

func (r *Reader) MD5Current() []byte

MD5Current returns the MD5 checksum of the content that has been read so far.

Calling MD5Current again after reading more data may result in a different checksum.

func (*Reader) MD5HexString

func (r *Reader) MD5HexString() string

MD5HexString returns a hex representation of the MD5.

func (*Reader) Read

func (r *Reader) Read(p []byte) (int, error)

func (*Reader) SHA256

func (r *Reader) SHA256() []byte

SHA256 returns the SHA256 checksum set as reference value.

It corresponds to the checksum that is expected and not the actual SHA256 checksum of the content.

func (*Reader) SHA256HexString

func (r *Reader) SHA256HexString() string

SHA256HexString returns a hex representation of the SHA256.

func (*Reader) Size

func (r *Reader) Size() int64

Size returns the absolute number of bytes the Reader will return during reading. It returns -1 for unlimited data.

type SHA256Mismatch

type SHA256Mismatch struct {
	ExpectedSHA256   string
	CalculatedSHA256 string
}

SHA256Mismatch - when content sha256 does not match with what was sent from client.

func (SHA256Mismatch) Error

func (e SHA256Mismatch) Error() string

Jump to

Keyboard shortcuts

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