pub struct Sbom {
pub metadata: Metadata,
pub components: IndexMap<ComponentId, Component>,
pub dependencies: BTreeMap<ComponentId, BTreeSet<ComponentId>>,
}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, BTreeSet<ComponentId>>Dependency graph as adjacency list: parent -> set of children.
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 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.
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).
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.
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
impl StructuralPartialEq 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 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,
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.