pub struct NormalizedSbom {
pub document: DocumentMetadata,
pub components: IndexMap<CanonicalId, Component>,
pub edges: Vec<DependencyEdge>,
pub extensions: FormatExtensions,
pub content_hash: u64,
pub primary_component_id: Option<CanonicalId>,
pub collision_count: usize,
}Expand description
Normalized SBOM document - the canonical intermediate representation.
This structure represents an SBOM in a format-agnostic way, allowing comparison between CycloneDX and SPDX documents.
Fields§
§document: DocumentMetadataDocument-level metadata
components: IndexMap<CanonicalId, Component>Components indexed by canonical ID
edges: Vec<DependencyEdge>Dependency edges
extensions: FormatExtensionsFormat-specific extensions
content_hash: u64Content hash for quick equality checks
primary_component_id: Option<CanonicalId>Primary/root product component (CycloneDX metadata.component or SPDX documentDescribes) This identifies the main product that this SBOM describes, important for CRA compliance.
collision_count: usizeNumber of canonical ID collisions encountered during parsing
Implementations§
Source§impl NormalizedSbom
impl NormalizedSbom
Sourcepub fn new(document: DocumentMetadata) -> Self
pub fn new(document: DocumentMetadata) -> Self
Create a new empty normalized SBOM
Sourcepub fn add_component(&mut self, component: Component) -> bool
pub fn add_component(&mut self, component: Component) -> bool
Add a component to the SBOM.
Returns true if a collision occurred (a component with the same canonical ID
was already present and has been overwritten). Collisions are logged as warnings.
Sourcepub fn log_collision_summary(&self)
pub fn log_collision_summary(&self)
Log a single summary line if any canonical ID collisions occurred during parsing.
Sourcepub fn add_edge(&mut self, edge: DependencyEdge)
pub fn add_edge(&mut self, edge: DependencyEdge)
Add a dependency edge
Sourcepub fn get_component(&self, id: &CanonicalId) -> Option<&Component>
pub fn get_component(&self, id: &CanonicalId) -> Option<&Component>
Get a component by canonical ID
Sourcepub fn get_dependencies(&self, id: &CanonicalId) -> Vec<&DependencyEdge>
pub fn get_dependencies(&self, id: &CanonicalId) -> Vec<&DependencyEdge>
Get dependencies of a component
Sourcepub fn get_dependents(&self, id: &CanonicalId) -> Vec<&DependencyEdge>
pub fn get_dependents(&self, id: &CanonicalId) -> Vec<&DependencyEdge>
Get dependents of a component
Sourcepub fn calculate_content_hash(&mut self)
pub fn calculate_content_hash(&mut self)
Calculate and update the content hash
Sourcepub fn component_count(&self) -> usize
pub fn component_count(&self) -> usize
Get total component count
Sourcepub fn primary_component(&self) -> Option<&Component>
pub fn primary_component(&self) -> Option<&Component>
Get the primary/root product component if set
Sourcepub fn set_primary_component(&mut self, id: CanonicalId)
pub fn set_primary_component(&mut self, id: CanonicalId)
Set the primary component by its canonical ID
Sourcepub fn ecosystems(&self) -> Vec<&Ecosystem>
pub fn ecosystems(&self) -> Vec<&Ecosystem>
Get all unique ecosystems in the SBOM
Sourcepub fn all_vulnerabilities(&self) -> Vec<(&Component, &VulnerabilityRef)>
pub fn all_vulnerabilities(&self) -> Vec<(&Component, &VulnerabilityRef)>
Get all vulnerabilities across all components
Sourcepub fn vulnerability_counts(&self) -> VulnerabilityCounts
pub fn vulnerability_counts(&self) -> VulnerabilityCounts
Count vulnerabilities by severity
Sourcepub fn build_index(&self) -> NormalizedSbomIndex
pub fn build_index(&self) -> NormalizedSbomIndex
Build an index for this SBOM.
The index provides O(1) lookups for dependencies, dependents, and name-based searches. Build once and reuse for multiple operations.
§Example
let sbom = parse_sbom(&path)?;
let index = sbom.build_index();
// Fast dependency lookup
let deps = index.dependencies_of(&component_id, &sbom.edges);Sourcepub fn get_dependencies_indexed<'a>(
&'a self,
id: &CanonicalId,
index: &NormalizedSbomIndex,
) -> Vec<&'a DependencyEdge>
pub fn get_dependencies_indexed<'a>( &'a self, id: &CanonicalId, index: &NormalizedSbomIndex, ) -> Vec<&'a DependencyEdge>
Get dependencies using an index (O(k) instead of O(edges)).
Use this when you have a prebuilt index for repeated lookups.
Sourcepub fn get_dependents_indexed<'a>(
&'a self,
id: &CanonicalId,
index: &NormalizedSbomIndex,
) -> Vec<&'a DependencyEdge>
pub fn get_dependents_indexed<'a>( &'a self, id: &CanonicalId, index: &NormalizedSbomIndex, ) -> Vec<&'a DependencyEdge>
Get dependents using an index (O(k) instead of O(edges)).
Use this when you have a prebuilt index for repeated lookups.
Sourcepub fn find_by_name_indexed(
&self,
name: &str,
index: &NormalizedSbomIndex,
) -> Vec<&Component>
pub fn find_by_name_indexed( &self, name: &str, index: &NormalizedSbomIndex, ) -> Vec<&Component>
Find components by name (case-insensitive) using an index.
Returns components whose lowercased name exactly matches the query.
Sourcepub fn search_by_name_indexed(
&self,
query: &str,
index: &NormalizedSbomIndex,
) -> Vec<&Component>
pub fn search_by_name_indexed( &self, query: &str, index: &NormalizedSbomIndex, ) -> Vec<&Component>
Search components by name (case-insensitive substring) using an index.
Returns components whose name contains the query substring.
Sourcepub fn apply_cra_sidecar(&mut self, sidecar: &CraSidecarMetadata)
pub fn apply_cra_sidecar(&mut self, sidecar: &CraSidecarMetadata)
Apply CRA sidecar metadata to supplement SBOM fields.
Sidecar values only override SBOM fields if the SBOM field is None/empty. This ensures SBOM data takes precedence when available.
Trait Implementations§
Source§impl Clone for NormalizedSbom
impl Clone for NormalizedSbom
Source§fn clone(&self) -> NormalizedSbom
fn clone(&self) -> NormalizedSbom
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NormalizedSbom
impl Debug for NormalizedSbom
Source§impl Default for NormalizedSbom
impl Default for NormalizedSbom
Source§impl<'de> Deserialize<'de> for NormalizedSbom
impl<'de> Deserialize<'de> for NormalizedSbom
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>,
Auto Trait Implementations§
impl Freeze for NormalizedSbom
impl RefUnwindSafe for NormalizedSbom
impl Send for NormalizedSbom
impl Sync for NormalizedSbom
impl Unpin for NormalizedSbom
impl UnwindSafe for NormalizedSbom
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<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more