stitch

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 11 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 stitch enriches dependency graphs with supplemental bills of materials. A catalog indexes the components the supplements describe by hash and purl; the stitcher matches every node of an extraction against it and grafts each describing supplement onto the node, merged into it or hung below it, using protobom's graft, absorb and dedupe operations.

Index

Constants

View Source
const PropertyStitchedFrom = "unpack:stitched-from"

PropertyStitchedFrom is set on every node a supplement was stitched onto, naming the source the supplement was loaded from.

Variables

This section is empty.

Functions

This section is empty.

Types

type Catalog

type Catalog struct {
	// contains filtered or unexported fields
}

Catalog holds supplements and finds the entries describing a node by its hashes or purl.

func NewCatalog

func NewCatalog() *Catalog

NewCatalog returns an empty catalog.

func (*Catalog) Add

func (c *Catalog) Add(source string, doc *protosbom.Document) *Supplement

Add registers a parsed document as a supplement, indexing the components it describes. A document that describes nothing is kept but can never match.

func (*Catalog) Entries

func (c *Catalog) Entries() []*Entry

Entries returns every entry of every supplement in catalog order.

func (*Catalog) Load

func (c *Catalog) Load(paths ...string) error

Load reads supplements from the given paths. A path naming a file must parse as a bill of materials, bare or enveloped. A path naming a directory is walked, and every regular file in it that parses is added; the rest are skipped and listed by Unparsed, since a directory of documents may hold a README next to them.

func (*Catalog) LoadFile

func (c *Catalog) LoadFile(path string) error

LoadFile reads one supplement from a file.

func (*Catalog) Match

func (c *Catalog) Match(n *protosbom.Node) []*Entry

Match returns the entries describing the node, in catalog order. An entry describes a node under sbom.SameComponent's rule, minus the node type: they share a hash under some algorithm and disagree under none, or, when they share no hash algorithm, they carry the same purl. A package in a document may well describe a file found on disk, and the stitcher decides what that means.

func (*Catalog) Supplements

func (c *Catalog) Supplements() []*Supplement

Supplements returns the loaded supplements in load order.

func (*Catalog) Unparsed

func (c *Catalog) Unparsed() []string

Unparsed returns the files a directory walk skipped because they did not parse as a bill of materials.

func (*Catalog) Unused

func (c *Catalog) Unused() []*Entry

Unused returns the entries that matched nothing, so the caller can tell the user which supplements went unused.

type Entry

type Entry struct {
	Supplement *Supplement

	// Node is the described component as the supplement states it.
	Node *protosbom.Node

	// Used records that the entry matched something during stitching, so
	// supplements nobody asked for can be reported.
	Used bool
}

Entry is one component a supplement describes: a root element of its document, which the catalog matches against nodes found in an extraction. The graph below it is what gets stitched under the match.

func (*Entry) ID

func (e *Entry) ID() string

ID returns the id of the described component in the supplement's list.

type Options

type Options struct {
	// Identity decides which nodes the dedupe pass collapses. Nil means
	// sbom.SameComponent.
	Identity sbom.NodeIdentity

	// NoDedupe leaves duplicate nodes in place after stitching. By
	// default, nodes that two supplements, or a supplement and the
	// extraction, both describe are collapsed into one.
	NoDedupe bool
}

Options configures a Stitcher.

type Report

type Report struct {
	// Stitched lists every entry applied, in the order it was applied.
	Stitched []Stitched

	// Dropped maps the ids of nodes the dedupe pass removed to the
	// nodes that survived in their place.
	Dropped map[string]string
}

Report says what a Stitch call did.

type Stitched

type Stitched struct {
	// NodeID is the node in the enriched list the entry was applied to.
	NodeID string

	// Entry is the supplement entry that described it.
	Entry *Entry

	// Merged reports whether the entry was folded into the node (same
	// node type) rather than hung below it.
	Merged bool
}

Stitched records one supplement entry applied to one node.

type Stitcher

type Stitcher struct {
	Catalog *Catalog
	Options Options
}

Stitcher enriches node lists with the supplements of a catalog.

func New

func New(catalog *Catalog) *Stitcher

New returns a stitcher over the catalog with the default options.

func (*Stitcher) Stitch

func (s *Stitcher) Stitch(nl *sbom.NodeList) (*Report, error)

Stitch enriches nl in place. Every node is matched against the catalog, and each entry describing it is stitched onto it: an entry of the same node type is merged into the node, keeping what the node states and adding what the supplement knows, with the supplement's graph below; a package entry describing a file node is hung under the file with a generatedFrom edge, the way a decomposed binary relates to the package it was built from; a file entry describing a package node is hung under it with a contains edge. Stitched-in nodes are matched in turn, so supplements chain, except that a supplement never applies within the graph it brought in itself. Every node stitched onto gets a BOM reference to the supplement's document and a property naming its source. Unless disabled, a dedupe pass then collapses the nodes that now describe the same component.

type Supplement

type Supplement struct {
	// Source is the path the document was read from.
	Source string

	// Document is the parsed bill of materials. Its node list is what gets
	// stitched; its metadata identifies it for provenance.
	Document *protosbom.Document

	// Entries are the components the document describes, one per root
	// element, in document order.
	Entries []*Entry
}

Supplement is a bill of materials loaded to enrich an extraction: the document and where it came from.

type Unpacker

type Unpacker struct {
	Inner    api.Unpacker
	Stitcher *Stitcher

	// Reports collects the report of every list stitched, in order.
	Reports []*Report
}

Unpacker wraps another unpacker and stitches the catalog's supplements into everything it extracts. It satisfies api.Unpacker, so it stands in for the inner unpacker wherever one is used.

func Wrap

func Wrap(inner api.Unpacker, catalog *Catalog) *Unpacker

Wrap returns an unpacker that runs inner and stitches its results with the catalog's supplements.

func (*Unpacker) Extract

func (u *Unpacker) Extract(ctx context.Context, subject api.DecomposableSubject) ([]*sbom.NodeList, error)

Extract runs the inner unpacker and stitches every list it returns. Lists returned alongside an error are stitched too, since the inner unpacker chose to return them.

func (*Unpacker) RegisterDecomposer

func (u *Unpacker) RegisterDecomposer(d api.Decomposer)

RegisterDecomposer registers with the inner unpacker.

func (*Unpacker) UnregisterDecomposer

func (u *Unpacker) UnregisterDecomposer(d api.Decomposer)

UnregisterDecomposer unregisters from the inner unpacker.

Jump to

Keyboard shortcuts

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