Documentation
¶
Overview ¶
Package sbom parses Software Bill of Materials documents into a unified data model. It reads CycloneDX and SPDX (JSON serialisations) and normalises both into the same Document/Package/Relationship shape so callers don't need to care which format they were handed.
The model and field mappings are a port of github.com/andrew/sbom (Ruby).
doc, err := sbom.Parse(data)
for _, p := range doc.Packages {
fmt.Println(p.Name, p.Version, p.PURL())
}
Index ¶
Constants ¶
const ( SupplierOrganization = "Organization" SupplierPerson = "Person" )
Supplier/originator type values, shared across both formats.
Variables ¶
var ErrUnrecognized = errors.New("sbom: unrecognized format")
ErrUnrecognized is returned when the input does not look like any supported SBOM format.
Functions ¶
Types ¶
type Component ¶
Component is the root subject the SBOM describes (CycloneDX metadata.component / SPDX root package).
type Document ¶
type Document struct {
Name string
ID string
Type Type
SpecVersion string
DataLicense string
Namespace string
Created string
Supplier string
Creators []Creator
Component Component
}
Document holds metadata about the SBOM document itself, distinct from the packages it describes.
type ExternalRef ¶
ExternalRef is a typed pointer to an external resource. PURLs and CPEs are stored here in both formats.
type Package ¶
type Package struct {
ID string
Name string
Version string
Type string
Description string
Supplier string
SupplierType string
Originator string
OriginatorType string
Homepage string
DownloadLocation string
Filename string
LicenseConcluded string
LicenseDeclared string
Copyright string
Checksums []Checksum
ExternalRefs []ExternalRef
Properties []Property
}
Package is a single component/package entry from the SBOM, regardless of source format.
type Relationship ¶
type Relationship struct {
SourceID string
Source string
TargetID string
Target string
Type string
}
Relationship links two elements in the SBOM. SourceID/TargetID are the raw identifiers from the document; Source/Target are resolved names where the parser could determine them.
type SBOM ¶
type SBOM struct {
Type Type
SpecVersion string
Document Document
Packages []Package
Relationships []Relationship
// contains filtered or unexported fields
}
SBOM is the unified parse result.
func New ¶
New returns an empty SBOM ready for AddPackage calls. Use this when building a document for Encode rather than parsing one.
func Parse ¶
Parse sniffs the SBOM format from content and parses it. Only JSON serialisations are supported.
func (*SBOM) AddPackage ¶
AddPackage appends p, replacing any existing package with the same (Name, Version) pair.
type Type ¶
type Type string
Type identifies the source SBOM specification.
func Detect ¶
Detect inspects content and returns the SBOM Type without fully parsing it. Returns TypeUnknown if the format can't be determined.
Only the top-level object keys are scanned; nested arrays and objects are skipped without allocation so detection cost is independent of document size once a discriminator is found.