Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNilReader = errors.New("unable to hash: reader is nil")
ErrNilReader is returned when asked to hash a reader that is nil.
var HasherFactory = HasherFactoryMap{ intoto.AlgorithmMD5: md5.New, intoto.AlgorithmSHA1: sha1.New, intoto.AlgorithmSHA224: crypto.SHA224.New, intoto.AlgorithmSHA512_224: crypto.SHA512_224.New, intoto.AlgorithmSHA256: sha256.New, intoto.AlgorithmSHA512_256: crypto.SHA512_256.New, intoto.AlgorithmSHA384: crypto.SHA384.New, intoto.AlgorithmSHA512: crypto.SHA512.New, intoto.AlgorithmSHA3_224: crypto.SHA3_224.New, intoto.AlgorithmSHA3_256: crypto.SHA3_256.New, intoto.AlgorithmSHA3_384: sha3.New384, intoto.AlgorithmSHA3_512: sha3.New512, intoto.AlgorithmGitBlob: newGitBlob, }
HasherFactory is a preconfigured hasher map with the algorithms of the in-toto catalog that are computed from a stream of bytes.
The rest of the catalog is left out, as the bytes of a file are not what they are computed from: gitCommit, gitTag and gitTree name git objects built from other objects and dirHash is computed over a directory.
Functions ¶
This section is empty.
Types ¶
type FileHashSet ¶
FileHashSet captures a set of hashes of the same artifact indexed by its path.
func (*FileHashSet) ToResourceDescriptors ¶
func (fhs *FileHashSet) ToResourceDescriptors() []*intoto.ResourceDescriptor
ToResourceDescriptors returns a resource descriptor for each file of the set, with its hashes, its path as the URI and its base name as the name. The descriptors are sorted by path, so the same set always gives the same list.
type HashSet ¶
type HashSet map[intoto.HashAlgorithm]string
HashSet captures a set of hashes of the same artifact.
func NewHashSet ¶ added in v0.2.1
NewHashSet returns a new hashset from any map of string-like things
func (*HashSet) ToResourceDescriptor ¶
func (hs *HashSet) ToResourceDescriptor() *intoto.ResourceDescriptor
ToResourceDescriptor returns a resource descriptor with the hashes of the set as its digest.
type HashSetList ¶
type HashSetList []HashSet
HashSetList is an array of HashSets.
func (*HashSetList) ToResourceDescriptors ¶
func (hsl *HashSetList) ToResourceDescriptors() []*intoto.ResourceDescriptor
ToResourceDescriptors returns a resource descriptor with the hashes of each set of the list, in the same order.
type Hasher ¶
type Hasher struct {
Options Options
}
Hasher is an object that has methods to hash data.
func (*Hasher) CheckReader ¶ added in v0.3.0
CheckReader hashes the data read from r in the algorithms of the set and compares the results with it. It returns nil when every hash matches and a *MismatchError naming the algorithms that do not when some differ.
Any other error means the data could not be checked: the set is empty, it has an algorithm the hasher cannot compute or reading failed.
Hashes are compared ignoring case. A gitBlob hash of the size of a SHA-256 is compared with the name of the blob in the sha256 object format of git.
func (*Hasher) HashFiles ¶
func (h *Hasher) HashFiles(paths []string) (*FileHashSet, error)
HashFiles gets a list of paths and returns the hashes of the files indexed by path. A path repeated in the list is hashed each time it appears and included once in the result.
Each file is opened when its turn to be hashed comes and closed when it is done, so no more than Options.MaxParallel files are open at a time.
func (*Hasher) HashReaders ¶
func (h *Hasher) HashReaders(readers []io.Reader) (*HashSetList, error)
HashReaders hashes the data of a list of readers and returns their hashes in the same order. Up to Options.MaxParallel readers are read at a time.
func (*Hasher) VerifyReader ¶ added in v0.2.0
VerifyReader compares a set of hashes against a reader data. If all match then it returns true. If a hash mismatches, it returns false. To learn which hashes did not match use CheckReader.
type HasherFactoryMap ¶
type HasherFactoryMap map[intoto.HashAlgorithm]func() hash.Hash
HasherFactoryMap is a map that can create hash.Hash objects for all the recognized algorithm types.
func (*HasherFactoryMap) GetHasher ¶
func (hf *HasherFactoryMap) GetHasher(algo intoto.HashAlgorithm) hash.Hash
type MismatchError ¶ added in v0.3.0
type MismatchError struct {
// Algorithms lists the algorithms whose hash did not match, sorted.
Algorithms []intoto.HashAlgorithm
// Expected and Computed hold, for each of those algorithms, the hash
// that was expected and the one the data has.
Expected HashSet
Computed HashSet
}
MismatchError is returned by CheckReader when the data does not have one or more of the expected hashes.
func (*MismatchError) Error ¶ added in v0.3.0
func (e *MismatchError) Error() string
type OptFn ¶ added in v0.2.0
func WithAlgorithms ¶ added in v0.2.0
func WithGitSHA256 ¶ added in v0.3.0
WithGitSHA256 sets the object format gitBlob is computed in: SHA-256 when true, SHA-1, the format of most repositories, when false.