integrity

package
v0.0.0-...-15e90fc Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SupportedAlgorithms

func SupportedAlgorithms() iter.Seq[Algorithm]

Types

type Algorithm

type Algorithm struct {
	// contains filtered or unexported fields
}
var (
	SHA256 Algorithm = Algorithm{"sha256"}
	SHA384 Algorithm = Algorithm{"sha384"}
	SHA512 Algorithm = Algorithm{"sha512"}
	Blake3 Algorithm = Algorithm{"blake3"}
)

func AlgorithmFromString

func AlgorithmFromString(name string) (Algorithm, bool)

func (Algorithm) CalculateDigest

func (a Algorithm) CalculateDigest(r io.Reader) (Digest, error)

func (Algorithm) Hasher

func (a Algorithm) Hasher() hash.Hash

func (Algorithm) Identifier

func (a Algorithm) Identifier() byte

Identifier returns a unique byte identifier for the algorithm. It is used internally to identify the algorithm for caching.

func (Algorithm) SizeBytes

func (a Algorithm) SizeBytes() int

func (Algorithm) String

func (a Algorithm) String() string

type Checksum

type Checksum struct {
	Algorithm Algorithm
	Hash      []byte
}

Checksum represents a single checksum of an artifact for a specific algorithm. It doesn't contain the size of the contents.

func ChecksumFromDigest

func ChecksumFromDigest(digest Digest, algorithm Algorithm) Checksum

func (Checksum) Empty

func (c Checksum) Empty() bool

Empty returns true if the checksum is empty.

func (Checksum) Equals

func (c Checksum) Equals(other Checksum) bool

func (Checksum) Hex

func (c Checksum) Hex() string

func (Checksum) ToSRI

func (c Checksum) ToSRI() string

func (Checksum) ZeroSized

func (c Checksum) ZeroSized() bool

ZeroSized returns true if the checksum is well-known to represent a zero-sized file.

type ChecksumCache

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

checksumCache contains a map of checksums to digests. The key can be of any hash function, as long as it can be padded to 64 bytes. One byte is reserved for the identifier of the checksum. The value is a digest (for the main digest function "--digest_function").

func NewCache

func NewCache() *ChecksumCache

func (*ChecksumCache) FromChecksum

func (c *ChecksumCache) FromChecksum(checksum Checksum) (Digest, bool)

func (*ChecksumCache) FromIntegrity

func (c *ChecksumCache) FromIntegrity(integrity Integrity) map[Algorithm]Digest

func (*ChecksumCache) FromIntegrityWithAlgorithm

func (c *ChecksumCache) FromIntegrityWithAlgorithm(integrity Integrity, digestFunction Algorithm) (Digest, bool)

func (*ChecksumCache) GetSlice

func (c *ChecksumCache) GetSlice(hash []byte, identifier byte) (Digest, bool)

func (*ChecksumCache) PutIntegrity

func (c *ChecksumCache) PutIntegrity(integrity Integrity, digest Digest)

func (*ChecksumCache) PutSlice

func (c *ChecksumCache) PutSlice(hash []byte, identifier byte, digest Digest)

type Digest

type Digest struct {

	// Size of the content in bytes.
	SizeBytes int64
	// contains filtered or unexported fields
}

Digest represents the digest of a blob in the Content Addressable Storage (CAS), as specified in the remote execution API, including the hash and content size (in bytes). Unlike the remote execution API, the hash is encoded as a byte array.

func DigestFromHex

func DigestFromHex(hexDigest string, sizeBytes int64, algorithm Algorithm) (Digest, error)

func NewDigest

func NewDigest(hash []byte, sizeBytes int64, algorithm Algorithm) Digest

func (Digest) CheckContent

func (d Digest) CheckContent(r io.Reader, algorithm Algorithm) error

func (Digest) CopyHashInto

func (d Digest) CopyHashInto(dest []byte, algorithm Algorithm) error

CopyHashInto copies the hash into the destination buffer. The destination buffer must be at least the size of the hash.

func (Digest) Equals

func (d Digest) Equals(other Digest, algorithm Algorithm) bool

func (Digest) Hex

func (d Digest) Hex(algorithm Algorithm) string

func (Digest) Uninitialized

func (d Digest) Uninitialized() bool

func (Digest) ZeroSized

func (d Digest) ZeroSized(algorithm Algorithm) bool

type Integrity

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

Integrity represents the integrity of an artifact, including checksums for multiple algorithms. This representation is not space-efficient, but it doesn't require additional allocations for each checksum. If the number of supported algorithms increases, this representation should be changed to a map.

func EmptyBlobIntegrity

func EmptyBlobIntegrity() Integrity

func IntegrityFromChecksums

func IntegrityFromChecksums(checksums ...Checksum) Integrity

func IntegrityFromContent

func IntegrityFromContent(r io.Reader, algorithms ...Algorithm) (Integrity, int64, error)

func IntegrityFromString

func IntegrityFromString(integrity ...string) (Integrity, error)

func (Integrity) BestSingleChecksum

func (i Integrity) BestSingleChecksum(alg Algorithm) (Checksum, bool)

BestSingleChecksum returns the best single checksum (with preferrence for the given algorithm). Alternatively, other algorithms are allowed.

func (Integrity) ChecksumForAlgorithm

func (i Integrity) ChecksumForAlgorithm(alg Algorithm) (Checksum, bool)

func (Integrity) Empty

func (i Integrity) Empty() bool

func (Integrity) Equivalent

func (i Integrity) Equivalent(other Integrity) bool

Equivalent returns true if the two Integrity objects are equivalent. This means: for each algorithm that has a checksum in both objects, the checksums are equal. We also require that at least one checksum is present in both objects. Additionally, any object with no checksums is considered unequal to any other object.

func (Integrity) Items

func (i Integrity) Items() iter.Seq[Checksum]

func (Integrity) ToSRIList

func (i Integrity) ToSRIList() []string

ToSRIList returns a list of Subresource Integrity (SRI) strings for the integrity. Each SRI string contains a single checksum.

func (Integrity) ToSRIString

func (i Integrity) ToSRIString() string

ToSRIString returns a single string with all Subresource Integrity (SRI) strings for the integrity. The checksums are separated by whitespace.

Jump to

Keyboard shortcuts

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