Documentation
¶
Overview ¶
Package subject provides a reusable options set to read attestation subjects from the command line. A subject can be given as a digest (`algorithm:value`, using any algorithm name from the in-toto DigestSet spec) or as the path to a file, which is hashed.
Index ¶
- Variables
- func Algorithm(name string) (intoto.HashAlgorithm, bool)
- func LooksLikeDigest(s string) bool
- func ParseDigest(s string) (intoto.HashAlgorithm, string, error)
- type Options
- func (so *Options) AddFlags(cmd *cobra.Command)
- func (so *Options) Config() *command.OptionsSetConfig
- func (so *Options) Digests() (map[string]hasher.HashSet, error)
- func (so *Options) Files() []string
- func (so *Options) HashSets() (hasher.FileHashSet, error)
- func (so *Options) ResourceDescriptors() ([]*intoto.ResourceDescriptor, error)
- func (so *Options) Validate() error
Constants ¶
This section is empty.
Variables ¶
var ErrNotDigest = errors.New("string is not an algorithm:value digest")
ErrNotDigest is returned by ParseDigest when the string does not have the shape of a digest (`algorithm:hex`) with a known algorithm. Callers use it to tell "this is not a digest at all" apart from "this is a broken digest".
Functions ¶
func Algorithm ¶
func Algorithm(name string) (intoto.HashAlgorithm, bool)
Algorithm looks up an algorithm name case-insensitively and returns its canonical in-toto spelling. The boolean is false when the name is not part of the DigestSet spec.
func LooksLikeDigest ¶
LooksLikeDigest reports whether s has the shape `algorithm:value` with an algorithm from the in-toto DigestSet spec. It says nothing about whether the value is a valid digest: strings that look like digests are never treated as file paths, so a malformed digest is reported as such instead of silently falling through to a filesystem lookup.
func ParseDigest ¶
func ParseDigest(s string) (intoto.HashAlgorithm, string, error)
ParseDigest parses a digest string in `algorithm:value` form. The algorithm must be one of the names defined in the in-toto DigestSet spec (matched case-insensitively) and the value must be hex encoded. For algorithms with a fixed digest size the value length is checked too.
The returned algorithm is the canonical spec name and the value is lowercased, so digests parsed here compare equal regardless of how the user typed them.
Types ¶
type Options ¶
type Options struct {
// Subjects holds the raw values read from the flag: digests in
// `algorithm:value` form or paths to files.
Subjects []string
// Algorithms lists the algorithms used to hash subjects given as files.
// When empty, the hasher's defaults are used.
Algorithms []intoto.HashAlgorithm
// contains filtered or unexported fields
}
Options reads subjects from the command line.
func (*Options) Config ¶
func (so *Options) Config() *command.OptionsSetConfig
Config returns the flag configuration for the subject options.
func (*Options) HashSets ¶
func (so *Options) HashSets() (hasher.FileHashSet, error)
HashSets resolves all subjects into a hasher.FileHashSet keyed by the raw subject string: digests are parsed and files are hashed.
func (*Options) ResourceDescriptors ¶
func (so *Options) ResourceDescriptors() ([]*intoto.ResourceDescriptor, error)
ResourceDescriptors resolves all subjects into in-toto resource descriptors, in the order they were given on the command line.