Documentation
¶
Index ¶
- func EnrichNodes(client *CratesIOClient, nodes map[PackageKey]*sbom.Node)
- func NewPackageNode(name, version, checksum string) *sbom.Node
- func ParseDependencyRef(dep string) (name, version string)
- type CargoLock
- type CargoToml
- type CratesIOClient
- type Decomposer
- type DependencySpec
- type DependencyTree
- func (dt *DependencyTree) Build(opts *api.DecomposerOptions) (*sbom.NodeList, error)
- func (dt *DependencyTree) Enrich(client *CratesIOClient)
- func (dt *DependencyTree) GetDependencyCount() int
- func (dt *DependencyTree) GetDirectDependencyCount() int
- func (dt *DependencyTree) ListDependencies() []string
- type DependencyType
- type LockPackage
- type Options
- type PackageInfo
- type PackageKey
- type TargetDeps
- type WorkspaceInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnrichNodes ¶ added in v0.3.3
func EnrichNodes(client *CratesIOClient, nodes map[PackageKey]*sbom.Node)
EnrichNodes fetches metadata from crates.io for the given crate nodes in parallel and populates license, description, homepage, repository, documentation, crate size and MSRV on them. Nodes for crates that are not on crates.io should be left out: the lookup would only fail.
func NewPackageNode ¶ added in v0.3.3
NewPackageNode builds the node for a crate at a version, the way every Rust reader renders one: a pkg:cargo purl, the crates.io download URL and the library purpose, plus the crate's SHA-256 when known. Readers of other Cargo data, such as the dependency list embedded in a binary, use it so their packages look the same as the source decomposer's.
func ParseDependencyRef ¶
ParseDependencyRef parses a dependency reference string from Cargo.lock. Dependencies can be in formats: - "name" (simple, when only one version exists) - "name version" (when multiple versions might exist) - "name version (source)" (with explicit source)
Types ¶
type CargoLock ¶
type CargoLock struct {
Version int `toml:"version"`
Packages []LockPackage `toml:"package"`
Metadata toml.Primitive `toml:"metadata"` // Ignored but captured to avoid parse errors
}
CargoLock represents the structure of a Cargo.lock file.
func ParseCargoLock ¶
ParseCargoLock parses a Cargo.lock file from the given directory.
func ParseCargoLockData ¶
ParseCargoLockData parses Cargo.lock content from bytes.
func (*CargoLock) BuildPackageIndex ¶
func (cl *CargoLock) BuildPackageIndex() (byKey map[PackageKey]*LockPackage, byName map[string][]*LockPackage)
BuildPackageIndex creates a map from package key to package for quick lookups. It also creates an index by name only for packages with unique names.
func (*CargoLock) FindRootPackages ¶
func (cl *CargoLock) FindRootPackages() []*LockPackage
type CargoToml ¶
type CargoToml struct {
Package PackageInfo `toml:"package"`
Dependencies map[string]DependencySpec `toml:"dependencies"`
DevDependencies map[string]DependencySpec `toml:"dev-dependencies"`
BuildDependencies map[string]DependencySpec `toml:"build-dependencies"`
Target map[string]TargetDeps `toml:"target"`
Workspace *WorkspaceInfo `toml:"workspace"`
}
CargoToml represents the structure of a Cargo.toml file.
func ParseCargoToml ¶
ParseCargoToml parses a Cargo.toml file from the given directory.
func ParseCargoTomlData ¶
ParseCargoTomlData parses Cargo.toml content from bytes.
func (*CargoToml) GetDirectDependencies ¶
func (ct *CargoToml) GetDirectDependencies() map[string]DependencyType
GetDirectDependencies returns a map of dependency names to their types. This includes dependencies from all sections and target-specific dependencies.
type CratesIOClient ¶ added in v0.2.1
CratesIOClient fetches crate metadata from the crates.io API.
func NewCratesIOClient ¶ added in v0.2.1
func NewCratesIOClient(concurrency int) *CratesIOClient
NewCratesIOClient creates a new client for the crates.io API.
func (*CratesIOClient) FetchAll ¶ added in v0.2.1
func (c *CratesIOClient) FetchAll(packages []PackageKey) map[PackageKey]*crateVersion
FetchAll fetches metadata for multiple crates in parallel using the Agent's GetGroup. Returns a map of PackageKey to parsed metadata. Errors on individual crates are silently skipped.
type Decomposer ¶
type Decomposer struct{}
func New ¶
func New() *Decomposer
func (*Decomposer) DefaultOptions ¶
func (d *Decomposer) DefaultOptions() any
DefaultOptions returns the default options for the Rust decomposer.
func (*Decomposer) Extract ¶
func (d *Decomposer) Extract(opts *api.DecomposerOptions) (*sbom.NodeList, error)
Extract parses Cargo.toml and Cargo.lock files and builds the complete dependency graph as a protobom NodeList.
func (*Decomposer) FindCodeBases ¶
func (d *Decomposer) FindCodeBases(index *code.PathIndex) ([]string, error)
FindCodeBases locates Rust codebases by looking for Cargo.lock files.
func (*Decomposer) Requirements ¶
func (d *Decomposer) Requirements(_ *api.DecomposerOptions) []api.Requirement
Requirements returns the requirements for the decomposer. No external binary required - uses pure Go implementation.
type DependencySpec ¶
type DependencySpec struct {
Version string `toml:"version"`
Path string `toml:"path"`
Git string `toml:"git"`
Branch string `toml:"branch"`
Tag string `toml:"tag"`
Rev string `toml:"rev"`
Features []string `toml:"features"`
Optional bool `toml:"optional"`
// contains filtered or unexported fields
}
DependencySpec represents a dependency specification in Cargo.toml. Dependencies can be specified in multiple formats: - Simple: "1.0" - Table: { version = "1.0", features = ["foo"] }
func (*DependencySpec) GetVersion ¶
func (ds *DependencySpec) GetVersion() string
GetVersion returns the version specification.
func (*DependencySpec) IsGit ¶
func (ds *DependencySpec) IsGit() bool
IsGit returns true if this is a git dependency.
func (*DependencySpec) IsLocalPath ¶
func (ds *DependencySpec) IsLocalPath() bool
IsLocalPath returns true if this is a path dependency.
func (*DependencySpec) UnmarshalTOML ¶
func (ds *DependencySpec) UnmarshalTOML(data any) error
UnmarshalTOML implements custom unmarshaling for dependency specs.
type DependencyTree ¶
type DependencyTree struct {
// contains filtered or unexported fields
}
DependencyTree builds a complete dependency graph from Cargo files.
func NewDependencyTree ¶
func NewDependencyTree(toml *CargoToml, lock *CargoLock, opts *Options) *DependencyTree
NewDependencyTree creates a new dependency tree from parsed Cargo files.
func (*DependencyTree) Build ¶
func (dt *DependencyTree) Build(opts *api.DecomposerOptions) (*sbom.NodeList, error)
Build constructs the complete dependency graph as a protobom NodeList.
func (*DependencyTree) Enrich ¶ added in v0.2.1
func (dt *DependencyTree) Enrich(client *CratesIOClient)
Enrich fetches metadata from crates.io for all cached dependency nodes and populates license, description, homepage, repository, documentation, and other fields on the protobom nodes.
func (*DependencyTree) GetDependencyCount ¶
func (dt *DependencyTree) GetDependencyCount() int
GetDependencyCount returns the total number of dependencies.
func (*DependencyTree) GetDirectDependencyCount ¶
func (dt *DependencyTree) GetDirectDependencyCount() int
GetDirectDependencyCount returns the number of direct dependencies.
func (*DependencyTree) ListDependencies ¶
func (dt *DependencyTree) ListDependencies() []string
ListDependencies returns a sorted list of all dependencies for debugging/testing.
type DependencyType ¶
type DependencyType int
DependencyType represents the type of dependency relationship.
const ( DepTypeNormal DependencyType = iota DepTypeDev DepTypeBuild )
func (DependencyType) String ¶
func (dt DependencyType) String() string
String returns a string representation of the dependency type.
type LockPackage ¶
type LockPackage struct {
Name string `toml:"name"`
Version string `toml:"version"`
Source string `toml:"source,omitempty"`
Checksum string `toml:"checksum,omitempty"`
Dependencies []string `toml:"dependencies,omitempty"`
}
LockPackage represents a package entry in Cargo.lock.
func ResolveDependency ¶
func ResolveDependency(dep string, byKey map[PackageKey]*LockPackage, byName map[string][]*LockPackage) (*LockPackage, error)
ResolveDependency resolves a dependency reference to a specific package. If version is empty and multiple versions exist, it returns the first one found.
type Options ¶
type Options struct {
// IncludeDevDependencies includes dev dependencies in the output.
IncludeDevDependencies bool
// IncludeBuildDependencies includes build dependencies in the output.
IncludeBuildDependencies bool
// Concurrency controls the number of parallel HTTP requests to crates.io (default: 10).
Concurrency int
}
Options configures the Rust dependency extraction.
type PackageInfo ¶
type PackageInfo struct {
Name string `toml:"name"`
Version string `toml:"version"`
Edition string `toml:"edition"`
Description string `toml:"description"`
License string `toml:"license"`
Homepage string `toml:"homepage"`
Repository string `toml:"repository"`
}
PackageInfo contains package metadata from Cargo.toml.
type PackageKey ¶
PackageKey uniquely identifies a package by name and version.
func (PackageKey) String ¶
func (pk PackageKey) String() string
type TargetDeps ¶
type TargetDeps struct {
Dependencies map[string]DependencySpec `toml:"dependencies"`
DevDependencies map[string]DependencySpec `toml:"dev-dependencies"`
BuildDependencies map[string]DependencySpec `toml:"build-dependencies"`
}
TargetDeps represents target-specific dependencies.
type WorkspaceInfo ¶
type WorkspaceInfo struct {
Members []string `toml:"members"`
Dependencies map[string]DependencySpec `toml:"dependencies"`
}
WorkspaceInfo represents workspace configuration.