subject

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
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

func LooksLikeDigest(s string) bool

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) AddFlags

func (so *Options) AddFlags(cmd *cobra.Command)

AddFlags adds the subject flags to a command.

func (*Options) Config

func (so *Options) Config() *command.OptionsSetConfig

Config returns the flag configuration for the subject options.

func (*Options) Digests

func (so *Options) Digests() (map[string]hasher.HashSet, error)

Digests returns the subjects given as digests, keyed by their raw string.

func (*Options) Files

func (so *Options) Files() []string

Files returns the subjects that are not digests, ie the paths to hash.

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.

func (*Options) Validate

func (so *Options) Validate() error

Validate checks that every subject is either a well formed digest or an existing file. Strings shaped like a digest are never looked up as files.

Jump to

Keyboard shortcuts

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