pub struct Sbom {
pub metadata: Metadata,
pub components: IndexMap<ComponentId, Component>,
pub dependencies: BTreeMap<ComponentId, BTreeMap<ComponentId, DependencyKind>>,
pub reverse_deps: BTreeMap<ComponentId, BTreeSet<ComponentId>>,
pub warnings: Vec<String>,
}Expand description
format-agnostic SBOM (Software Bill of Materials) representation.
this is the central type that holds all components and their relationships. it abstracts over format-specific details from CycloneDX, SPDX, and other formats.
§Example
use sbom_model::{Sbom, Component};
let mut sbom = Sbom::default();
let component = Component::new("serde".into(), Some("1.0.0".into()));
sbom.components.insert(component.id.clone(), component);Fields§
§metadata: Metadatadocument-level metadata (creation time, tools, authors).
components: IndexMap<ComponentId, Component>all components indexed by their stable identifier.
dependencies: BTreeMap<ComponentId, BTreeMap<ComponentId, DependencyKind>>dependency graph as adjacency list: parent -> (child -> kind).
reverse_deps: BTreeMap<ComponentId, BTreeSet<ComponentId>>reverse dependency index: child -> set of parents.
derived from dependencies; call rebuild_reverse_deps
after modifying dependencies to keep it in sync.
warnings: Vec<String>non-fatal warnings produced during parsing (e.g. orphaned dependency refs).
Implementations§
Source§impl Sbom
impl Sbom
Sourcepub fn normalize(&mut self)
pub fn normalize(&mut self)
normalizes the SBOM for deterministic comparison.
this method:
- sorts components by ID
- deduplicates and sorts licenses within each component
- lowercases hash algorithms and values
- clears volatile metadata (timestamps, tools, authors)
call this before comparing two SBOMs to ignore irrelevant differences.
Sourcepub fn rebuild_reverse_deps(&mut self)
pub fn rebuild_reverse_deps(&mut self)
rebuilds the reverse dependency index from the forward dependencies map.
must be called after modifying dependencies for rdeps() and roots()
to return correct results. Parsers call this automatically; call it
explicitly when constructing an Sbom by hand.
Sourcepub fn insert_component(&mut self, component: Component) -> Option<Component>
pub fn insert_component(&mut self, component: Component) -> Option<Component>
inserts a component, replacing any component with the same id.
the replaced component’s source_ids are
merged into the new one’s, sorted and deduplicated. returns the
replaced component.
Sourcepub fn insert_dependency(
&mut self,
parent: ComponentId,
child: ComponentId,
kind: DependencyKind,
)
pub fn insert_dependency( &mut self, parent: ComponentId, child: ComponentId, kind: DependencyKind, )
adds a parent -> child dependency edge.
an edge added twice with different kinds keeps the kind declared first
in DependencyKind, so Runtime wins over every other kind. call
rebuild_reverse_deps afterwards.
Sourcepub fn roots(&self) -> Vec<ComponentId>
pub fn roots(&self) -> Vec<ComponentId>
returns root components (those not depended on by any other component).
these are typically the top-level packages or applications in the SBOM.
uses the precomputed reverse_deps index.
Sourcepub fn deps(&self, id: &ComponentId) -> Vec<ComponentId>
pub fn deps(&self, id: &ComponentId) -> Vec<ComponentId>
returns direct dependencies of the given component.
Sourcepub fn rdeps(&self, id: &ComponentId) -> Vec<ComponentId>
pub fn rdeps(&self, id: &ComponentId) -> Vec<ComponentId>
returns reverse dependencies (components that depend on the given component).
uses the precomputed reverse_deps index.
Sourcepub fn transitive_deps(&self, id: &ComponentId) -> BTreeSet<ComponentId>
pub fn transitive_deps(&self, id: &ComponentId) -> BTreeSet<ComponentId>
returns all transitive dependencies of the given component.
traverses the dependency graph depth-first and returns all reachable components.
Sourcepub fn ecosystems(&self) -> BTreeSet<String>
pub fn ecosystems(&self) -> BTreeSet<String>
returns all unique ecosystems present in the SBOM.
Sourcepub fn licenses(&self) -> BTreeSet<String>
pub fn licenses(&self) -> BTreeSet<String>
returns all unique licenses present across all components.
Sourcepub fn missing_hashes(&self) -> Vec<ComponentId>
pub fn missing_hashes(&self) -> Vec<ComponentId>
returns components that have no checksums/hashes.
useful for identifying components that may need integrity verification.
Sourcepub fn detect_cycles(&self) -> Vec<Vec<ComponentId>>
pub fn detect_cycles(&self) -> Vec<Vec<ComponentId>>
detects dependency cycles in the SBOM’s dependency graph.
uses iterative stack-based depth-first search with three-color marking (white/gray/black) to find all distinct cycles. each returned vector contains the component IDs forming a cycle, starting and ending with the same ID.
returns an empty vector if the graph is acyclic.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Sbom
impl<'de> Deserialize<'de> for Sbom
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Sbom
Auto Trait Implementations§
impl Freeze for Sbom
impl RefUnwindSafe for Sbom
impl Send for Sbom
impl Sync for Sbom
impl Unpin for Sbom
impl UnsafeUnpin for Sbom
impl UnwindSafe for Sbom
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.