Documentation
¶
Overview ¶
Package rustbinary implements the artifact decomposer for Rust executables built with cargo-auditable. Such binaries carry a zlib-compressed JSON record of the crates linked into them, with versions, sources, kinds and the edges among them, in a linker section named .dep-v0. The decomposer reads that record and renders it with the Rust source decomposer's node conventions, so a binary and the Cargo project it came from produce the same shape of graph.
Index ¶
- Constants
- func BuildNodeList(info *VersionInfo, opts *api.DecomposerOptions) (*sbom.NodeList, map[rust.PackageKey]*sbom.Node, error)
- type Decomposer
- func (d *Decomposer) DefaultOptions() any
- func (d *Decomposer) DefaultSubjects() []string
- func (d *Decomposer) Extract(opts *api.DecomposerOptions) (*sbom.NodeList, error)
- func (d *Decomposer) ExtractArtifact(ra io.ReaderAt, path string, opts *api.DecomposerOptions) (*sbom.NodeList, error)
- func (d *Decomposer) ExtractArtifactWithContext(ctx context.Context, ra io.ReaderAt, _ string, opts *api.DecomposerOptions) (*sbom.NodeList, error)
- func (d *Decomposer) GenerationContext() api.GenerationContext
- func (d *Decomposer) Matches(_ fs.FileInfo, header []byte) bool
- func (d *Decomposer) Name() string
- func (d *Decomposer) Requirements(*api.DecomposerOptions) []api.Requirement
- type Package
- type VersionInfo
Constants ¶
const ( SourceCratesIO = "crates.io" SourceLocal = "local" )
Sources as cargo-auditable records them.
const ( // PropertySource is set on packages not from crates.io: "git", // "local", "registry" or another source cargo-auditable records. PropertySource = "cargo:source" // PropertyFormat is set on the root with the record's format revision. PropertyFormat = "cargo-auditable:format" )
Property names recorded on nodes.
const Name = "rustbinary"
Name is the name the decomposer is registered under in the artifact unpacker, and the key options refer to it by.
const SectionName = ".dep-v0"
SectionName is the linker section cargo-auditable stores the dependency record in, in every object format.
Variables ¶
This section is empty.
Functions ¶
func BuildNodeList ¶
func BuildNodeList(info *VersionInfo, opts *api.DecomposerOptions) (*sbom.NodeList, map[rust.PackageKey]*sbom.Node, error)
BuildNodeList renders a record as a protobom NodeList rooted at the crate the binary was built from, and returns the crates.io packages by key for enrichment. Every crate reachable from the root becomes a node, related to what requires it with dependsOn, or buildDependency for the crates cargo-auditable marks as build dependencies. Build dependencies, and everything only they pull in, are left out unless opts.IncludeBuild is set: they are what built the binary, not what runs in it.
Types ¶
type Decomposer ¶
type Decomposer struct{}
Decomposer reads dependency data out of cargo-auditable Rust executables.
func (*Decomposer) DefaultOptions ¶
func (d *Decomposer) DefaultOptions() any
DefaultOptions returns the Rust source decomposer's options, which the crates.io enrichment reads: set them as this decomposer's driver options to control the request concurrency.
func (*Decomposer) DefaultSubjects ¶
func (d *Decomposer) DefaultSubjects() []string
DefaultSubjects lists the parents the decomposer runs under by default: a container image or a system root, where executables are the payload, and not a codebase.
func (*Decomposer) Extract ¶
func (d *Decomposer) Extract(opts *api.DecomposerOptions) (*sbom.NodeList, error)
Extract reads the executable at opts.WorkDir. It is the plain api.Decomposer entry point; the artifact unpacker uses ExtractArtifact.
func (*Decomposer) ExtractArtifact ¶
func (d *Decomposer) ExtractArtifact(ra io.ReaderAt, path string, opts *api.DecomposerOptions) (*sbom.NodeList, error)
ExtractArtifact is ExtractArtifactWithContext with a background context, for a caller that has none to give.
func (*Decomposer) ExtractArtifactWithContext ¶ added in v0.4.1
func (d *Decomposer) ExtractArtifactWithContext( ctx context.Context, ra io.ReaderAt, _ string, opts *api.DecomposerOptions, ) (*sbom.NodeList, error)
ExtractArtifactWithContext reads the cargo-auditable record in the executable and returns the crate graph: the root crate the binary was built from, with the crates linked into it as its descendants. Returns (nil, nil) when the file carries no record, which is what every executable not built with cargo-auditable looks like. A record that is present but unreadable is an error: the file is one of ours and it is broken.
func (*Decomposer) GenerationContext ¶ added in v0.4.1
func (d *Decomposer) GenerationContext() api.GenerationContext
GenerationContext says in what context the decomposer's data is read: the dependency record embedded in a binary already built.
func (*Decomposer) Matches ¶
func (d *Decomposer) Matches(_ fs.FileInfo, header []byte) bool
Matches reports whether the file looks like an executable in a format the section reader understands: ELF, PE or Mach-O. Whether it carries a cargo-auditable record is settled by ExtractArtifact.
func (*Decomposer) Name ¶
func (d *Decomposer) Name() string
Name returns the decomposer's registration name.
func (*Decomposer) Requirements ¶
func (d *Decomposer) Requirements(*api.DecomposerOptions) []api.Requirement
Requirements returns nothing: the decomposer is pure Go.
type Package ¶
type Package struct {
Name string `json:"name"`
Version string `json:"version"`
// Source is where the crate came from: "crates.io", "git", "local",
// "registry" or a free-form value.
Source string `json:"source"`
// Kind is "runtime" (the default, omitted) or "build". A build
// dependency's own dependencies are recorded as build too.
Kind string `json:"kind,omitempty"`
// Dependencies indexes the packages this one depends on.
Dependencies []int `json:"dependencies,omitempty"`
// Root marks the crate the binary was built from.
Root bool `json:"root,omitempty"`
}
Package is one crate in the record.
type VersionInfo ¶
type VersionInfo struct {
// Packages lists every crate in the build, in an order Dependencies
// indexes into.
Packages []Package `json:"packages"`
// Format is the record's format revision.
Format int `json:"format"`
}
VersionInfo is the dependency record cargo-auditable embeds, as the auditable-serde crate defines it.
func DecodeRecord ¶
func DecodeRecord(data []byte) (*VersionInfo, error)
DecodeRecord inflates and parses the contents of the .dep-v0 section.