Documentation
¶
Index ¶
- Constants
- Variables
- func AddChecksumHeader(w http.ResponseWriter, c map[string]string)
- func IsChecksumMismatch(err error) bool
- func ReadCheckSums(b []byte, part int) (cs map[string]string, isMP bool)
- func ReadPartCheckSums(b []byte) (res []map[string]string)
- func TransferChecksumHeader(w http.ResponseWriter, r *http.Request)
- type BadDigest
- type Checker
- type Checksum
- type ChecksumMismatch
- type ChecksumType
- func (c ChecksumType) Base() ChecksumType
- func (c ChecksumType) CanMerge() bool
- func (c ChecksumType) FullObjectRequested() bool
- func (c ChecksumType) Hasher() hash.Hash
- func (c ChecksumType) Is(t ChecksumType) bool
- func (c ChecksumType) IsMultipartComposite() bool
- func (c ChecksumType) IsSet() bool
- func (c ChecksumType) Key() string
- func (c ChecksumType) ObjType() string
- func (c ChecksumType) RawByteLen() int
- func (c ChecksumType) String() string
- func (c ChecksumType) StringFull() string
- func (c ChecksumType) Trailing() bool
- type Options
- type Reader
- func (r *Reader) ActualSize() int64
- func (r *Reader) AddChecksum(req *http.Request, ignoreValue bool) error
- func (r *Reader) AddChecksumNoTrailer(headers http.Header, ignoreValue bool) error
- func (r *Reader) AddNonTrailingChecksum(cs *Checksum, ignoreValue bool) error
- func (r *Reader) AddServerSideChecksumHasher(t ChecksumType)
- func (r *Reader) Checksum() *Checksum
- func (r *Reader) Close() error
- func (r *Reader) ContentCRC() map[string]string
- func (r *Reader) ContentCRCType() ChecksumType
- func (r *Reader) ETag() etag.ETag
- func (r *Reader) MD5Current() []byte
- func (r *Reader) Read(p []byte) (int, error)
- func (r *Reader) SHA256() []byte
- func (r *Reader) SHA256HexString() string
- func (r *Reader) SetExpectedMax(expectedMax int64)
- func (r *Reader) SetExpectedMin(expectedMin int64)
- func (r *Reader) Size() int64
- type SHA256Mismatch
- type SizeMismatch
- type SizeTooLarge
- type SizeTooSmall
Constants ¶
const MinIOMultipartChecksum = "x-minio-multipart-checksum"
MinIOMultipartChecksum is as metadata on multipart uploads to indicate checksum type.
const MinIOMultipartChecksumType = "x-minio-multipart-checksum-type"
MinIOMultipartChecksumType is as metadata on multipart uploads to indicate checksum type.
Variables ¶
var BaseChecksumTypes = []ChecksumType{ChecksumSHA256, ChecksumSHA1, ChecksumCRC32, ChecksumCRC64NVME, ChecksumCRC32C}
BaseChecksumTypes is a list of all the base checksum types.
var ErrInvalidChecksum = errors.New("invalid checksum")
ErrInvalidChecksum is returned when an invalid checksum is provided in headers.
Functions ¶
func AddChecksumHeader ¶
func AddChecksumHeader(w http.ResponseWriter, c map[string]string)
AddChecksumHeader will transfer any checksum value that has been checked.
func IsChecksumMismatch ¶
IsChecksumMismatch matches if 'err' is hash.ChecksumMismatch
func ReadCheckSums ¶
ReadCheckSums will read checksums from b and return them. Returns whether this is (part of) a multipart checksum.
func ReadPartCheckSums ¶
ReadPartCheckSums will read all part checksums from b and return them.
func TransferChecksumHeader ¶
func TransferChecksumHeader(w http.ResponseWriter, r *http.Request)
TransferChecksumHeader will transfer any checksum value that has been checked. If checksum was trailing, they must have been added to r.Trailer.
Types ¶
type Checker ¶
type Checker struct {
// contains filtered or unexported fields
}
Checker allows to verify the checksum of a reader.
func NewChecker ¶
NewChecker ensures that content with the specified length is read from rc. Calling Close on this will close upstream.
type Checksum ¶
type Checksum struct {
Type ChecksumType
Encoded string
Raw []byte
WantParts int
}
Checksum is a type and base 64 encoded value.
func ChecksumFromBytes ¶
ChecksumFromBytes reconstructs a Checksum struct from the serialized bytes created in AppendTo() Returns nil if the bytes are invalid or empty. AppendTo() can append a serialized Checksum to another already-serialized Checksum, however, in practice, we only use one at a time. ChecksumFromBytes only returns the first one and no part checksums.
func GetContentChecksum ¶
GetContentChecksum returns content checksum. Returns ErrInvalidChecksum if so. Returns nil, nil if no checksum.
func NewChecksumFromData ¶
func NewChecksumFromData(t ChecksumType, data []byte) *Checksum
NewChecksumFromData returns a new Checksum, using specified algorithm type on data.
func NewChecksumString ¶
NewChecksumString returns a new checksum from specified algorithm and base64 encoded value.
func NewChecksumWithType ¶
func NewChecksumWithType(alg ChecksumType, value string) *Checksum
NewChecksumWithType is similar to NewChecksumString but expects input algo of ChecksumType.
func (*Checksum) AddPart ¶
AddPart will merge a part checksum into the current, as if the content of each was appended. The size of the content that produced the second checksum must be provided. Not all checksum types can be merged, use the CanMerge method to check. Checksum types must match.
func (*Checksum) AppendTo ¶
AppendTo will append the checksum to b. 'parts' is used when checksum has ChecksumMultipart set. ReadCheckSums reads the values back.
type ChecksumMismatch ¶
ChecksumMismatch - when content checksum does not match with what was sent from client.
func (ChecksumMismatch) Error ¶
func (e ChecksumMismatch) Error() string
type ChecksumType ¶
type ChecksumType uint32
ChecksumType contains information about the checksum type.
const ( // ChecksumTrailing indicates the checksum will be sent in the trailing header. // Another checksum type will be set. ChecksumTrailing ChecksumType = 1 << iota // ChecksumSHA256 indicates a SHA256 checksum. ChecksumSHA256 // ChecksumSHA1 indicates a SHA-1 checksum. ChecksumSHA1 // ChecksumCRC32 indicates a CRC32 checksum with IEEE table. ChecksumCRC32 // ChecksumCRC32C indicates a CRC32 checksum with Castagnoli table. ChecksumCRC32C // ChecksumInvalid indicates an invalid checksum. ChecksumInvalid // ChecksumMultipart indicates the checksum is from a multipart upload. ChecksumMultipart // ChecksumIncludesMultipart indicates the checksum also contains part checksums. ChecksumIncludesMultipart // ChecksumCRC64NVME indicates CRC64 with 0xad93d23594c93659 polynomial. ChecksumCRC64NVME // ChecksumFullObject indicates the checksum is of the full object, // not checksum of checksums. Should only be set on ChecksumMultipart ChecksumFullObject // ChecksumNone indicates no checksum. ChecksumNone ChecksumType = 0 )
func ChecksumStringToType ¶
func ChecksumStringToType(alg string) ChecksumType
ChecksumStringToType is like NewChecksumType but without the `mode`
func NewChecksumHeader ¶
func NewChecksumHeader(h http.Header) ChecksumType
NewChecksumHeader returns a checksum type based on the algorithm string.
func NewChecksumType ¶
func NewChecksumType(alg, objType string) ChecksumType
NewChecksumType returns a checksum type based on the algorithm string and obj type.
func (ChecksumType) Base ¶
func (c ChecksumType) Base() ChecksumType
Base returns the base checksum (if any)
func (ChecksumType) CanMerge ¶
func (c ChecksumType) CanMerge() bool
CanMerge will return if the checksum type indicates that checksums can be merged.
func (ChecksumType) FullObjectRequested ¶
func (c ChecksumType) FullObjectRequested() bool
FullObjectRequested will return if the checksum type indicates full object checksum was requested.
func (ChecksumType) Hasher ¶
func (c ChecksumType) Hasher() hash.Hash
Hasher returns a hasher corresponding to the checksum type. Returns nil if no checksum.
func (ChecksumType) IsMultipartComposite ¶
func (c ChecksumType) IsMultipartComposite() bool
IsMultipartComposite returns true if the checksum is multipart and full object was not requested.
func (ChecksumType) IsSet ¶
func (c ChecksumType) IsSet() bool
IsSet returns whether the type is valid and known.
func (ChecksumType) Key ¶
func (c ChecksumType) Key() string
Key returns the header key. returns empty string if invalid or none.
func (ChecksumType) ObjType ¶
func (c ChecksumType) ObjType() string
ObjType returns a string to return as x-amz-checksum-type.
func (ChecksumType) RawByteLen ¶
func (c ChecksumType) RawByteLen() int
RawByteLen returns the size of the un-encoded checksum.
func (ChecksumType) String ¶
func (c ChecksumType) String() string
String returns the type as a string.
func (ChecksumType) StringFull ¶
func (c ChecksumType) StringFull() string
StringFull returns the type and all flags as a string.
func (ChecksumType) Trailing ¶
func (c ChecksumType) Trailing() bool
Trailing return whether the checksum is trailing.
type Options ¶
type Options struct {
MD5Hex string
SHA256Hex string
Size int64
ActualSize int64
DisableMD5 bool
ForceMD5 []byte
}
Options are optional arguments to NewReaderWithOpts, Options simply converts positional arguments to NewReader() into a more flexible way to provide optional inputs. This is currently used by the FanOut API call mostly to disable expensive md5sum calculation repeatedly under hash.Reader.
type Reader ¶
type Reader struct {
// Server side computed checksum. In some cases, like CopyObject, a new checksum
// needs to be computed and saved on the destination object, but the client
// does not provide it. Not calculated if client-side contentHash is set.
ServerSideChecksumType ChecksumType
ServerSideHasher hash.Hash
ServerSideChecksumResult *Checksum
// 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(ctx context.Context, 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. When size is >=0 it *must* match the amount of data provided by r.
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. NewReader enforces S3 compatibility strictly by ensuring caller does not send more content than specified size.
func NewReaderWithOpts ¶
NewReaderWithOpts is like NewReader but takes `Options` as argument, allowing callers to indicate if they want to disable md5sum checksum.
func (*Reader) ActualSize ¶
ActualSize returns the pre-modified size of the object. DecompressedSize - For compressed objects.
func (*Reader) AddChecksum ¶
AddChecksum will add checksum checks as specified in https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html Returns ErrInvalidChecksum if a problem with the checksum is found.
func (*Reader) AddChecksumNoTrailer ¶
AddChecksumNoTrailer will add checksum checks as specified in https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html Returns ErrInvalidChecksum if a problem with the checksum is found.
func (*Reader) AddNonTrailingChecksum ¶
AddNonTrailingChecksum will add a checksum to the reader. The checksum cannot be trailing.
func (*Reader) AddServerSideChecksumHasher ¶
func (r *Reader) AddServerSideChecksumHasher(t ChecksumType)
AddServerSideChecksumHasher adds a new hasher for computing the server-side checksum.
func (*Reader) ContentCRC ¶
ContentCRC returns the content crc if set.
func (*Reader) ContentCRCType ¶
func (r *Reader) ContentCRCType() ChecksumType
ContentCRCType returns the content checksum type.
func (*Reader) 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) MD5Current ¶
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) SHA256 ¶
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 ¶
SHA256HexString returns a hex representation of the SHA256.
func (*Reader) SetExpectedMax ¶
SetExpectedMax set expected max data expected from reader
func (*Reader) SetExpectedMin ¶
SetExpectedMin set expected minimum data expected from reader
type SHA256Mismatch ¶
SHA256Mismatch - when content sha256 does not match with what was sent from client.
func (SHA256Mismatch) Error ¶
func (e SHA256Mismatch) Error() string
type SizeMismatch ¶
SizeMismatch error size mismatch
func (SizeMismatch) Error ¶
func (e SizeMismatch) Error() string
type SizeTooLarge ¶
SizeTooLarge reader size too large
func (SizeTooLarge) Error ¶
func (e SizeTooLarge) Error() string
type SizeTooSmall ¶
SizeTooSmall reader size too small
func (SizeTooSmall) Error ¶
func (e SizeTooSmall) Error() string