rustbinary

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 13 Imported by: 1 module, 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 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

View Source
const (
	SourceCratesIO = "crates.io"
	SourceLocal    = "local"
)

Sources as cargo-auditable records them.

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

View Source
const Name = "rustbinary"

Name is the name the decomposer is registered under in the artifact unpacker, and the key options refer to it by.

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

func New() *Decomposer

New returns a Rust binary decomposer.

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, _ string, opts *api.DecomposerOptions) (*sbom.NodeList, error)

ExtractArtifact 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) 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.

Jump to

Keyboard shortcuts

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