1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
//! **A powerful library for working with Software Bills of Materials (SBOMs).**
//!
//! `sbom-tools` provides a comprehensive suite of tools for parsing, analyzing, diffing,
//! and enriching software bills of materials. It is designed to be a foundational library for
//! supply chain security, compliance, and dependency management workflows.
//!
//! The library supports common SBOM formats like **CycloneDX** and **SPDX** and normalizes them
//! into a unified, easy-to-use data model. It powers both a command-line interface (CLI)
//! for direct use and a Rust library for programmatic integration into your own applications.
//!
//! ## Key Features
//!
//! - **Multi-Format Parsing**: Ingests CycloneDX 1.4–1.7 (JSON, XML) and SPDX 2.2–2.3
//! (JSON, tag-value, RDF/XML) and SPDX 3.0 (JSON-LD), with automatic format detection.
//! - **Intelligent Diffing**: Performs semantic diffs between two SBOMs to identify changes
//! in components, dependencies, licenses, and vulnerabilities.
//! - **Data Enrichment**: Augments SBOMs with external data, including:
//! - **Vulnerability Information**: Fetches vulnerability data from the OSV (Open Source Vulnerability) database.
//! - **End-of-Life (EOL) Status**: Checks components against the `endoflife.date` API to identify unsupported software.
//! - More enrichers for staleness, KEV, etc.
//! - **Quality & Compliance Scoring**: Checks SBOMs for compliance against established standards
//! like NTIA Minimum Elements and the EU Cyber Resilience Act (CRA).
//! - **Flexible Reporting**: Generates analysis reports in multiple formats, including JSON,
//! Markdown, SARIF, and a full-featured interactive Terminal UI (TUI).
//!
//! ## Core Concepts & Modules
//!
//! The library is organized into several key modules:
//!
//! - **[`model`]**: Defines the central data structure, [`NormalizedSbom`]. Regardless of the input
//! format (CycloneDX or SPDX), the library parses it into this unified model. This allows you to work with
//! a consistent and predictable API for all your SBOM analysis tasks.
//! - **[`pipeline`]**: Contains the primary functions for processing SBOMs. You can use the functions
//! in this module to construct a pipeline to parse, enrich, and generate reports in a single,
//! streamlined operation.
//! - **[`diff`]**: Home of the [`DiffEngine`], which performs a semantic comparison of two `NormalizedSbom` objects.
//! - **[`enrichment`]**: Provides `Enricher` traits and implementations for augmenting SBOMs with external data.
//! Requires the `enrichment` feature flag.
//! - **[`quality`]**: Contains the [`ComplianceChecker`] for validating SBOMs against standards and the
//! [`QualityScorer`] for grading overall quality.
//! - **[`reports`]**: Includes generators for creating output reports in various formats.
//!
//! ## Getting Started: Parsing an SBOM
//!
//! The most common entry point is to parse an existing SBOM file using the [`pipeline`] module.
//! The library will automatically detect the format and return a [`NormalizedSbom`].
//!
//! ```no_run
//! use std::path::Path;
//! use sbom_tools::parse_sbom;
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let sbom = parse_sbom(Path::new("path/to/your/sbom.json"))?;
//!
//! println!(
//! "Successfully parsed SBOM for '{}' with {} components.",
//! sbom.document.name.unwrap_or_else(|| "Unknown".to_string()),
//! sbom.components.len()
//! );
//!
//! Ok(())
//! }
//! ```
//!
//! ## Examples
//!
//! Below are examples for other common use cases.
//!
//! ### Diffing Two SBOMs
//!
//! The [`DiffEngine`] identifies what has been added, removed, or modified between an "old"
//! and a "new" SBOM.
//!
//! ```no_run
//! use std::path::Path;
//! use sbom_tools::{parse_sbom, DiffEngine};
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let old_sbom = parse_sbom(Path::new("path/to/old-sbom.json"))?;
//! let new_sbom = parse_sbom(Path::new("path/to/new-sbom.json"))?;
//!
//! let engine = DiffEngine::new();
//! let diff = engine.diff(&old_sbom, &new_sbom)?;
//!
//! println!("Components Added: {}", diff.components.added.len());
//! println!("Components Removed: {}", diff.components.removed.len());
//!
//! for added in &diff.components.added {
//! println!(" + {} {}", added.name,
//! added.new_version.as_deref().unwrap_or(""));
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ### Enriching with Vulnerability and End-of-Life (EOL) Data
//!
//! You can configure the processing pipeline to run enrichment stages. The following example
//! enables both OSV vulnerability scanning and EOL status checking.
//!
//! *Note: This requires the `enrichment` feature flag to be enabled.*
//!
//! ```ignore
//! use sbom_tools::parse_sbom;
//! use sbom_tools::model::EolStatus;
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut sbom = parse_sbom("path/to/your/sbom.json")?;
//!
//! // Enrich with OSV vulnerability data (requires `enrichment` feature)
//! #[cfg(feature = "enrichment")]
//! {
//! use sbom_tools::{OsvEnricher, OsvEnricherConfig, VulnerabilityEnricher};
//! let enricher = OsvEnricher::new(OsvEnricherConfig::default());
//! enricher.enrich(&mut sbom)?;
//! }
//!
//! println!("--- Vulnerability and EOL Report ---");
//! for component in sbom.components.values() {
//! if !component.vulnerabilities.is_empty() {
//! println!("\n[!] Component '{}' has {} vulnerabilities:",
//! component.name, component.vulnerabilities.len());
//! for vuln in &component.vulnerabilities {
//! println!(" - {}: {}", vuln.id,
//! vuln.summary.as_deref().unwrap_or("No summary"));
//! }
//! }
//!
//! if let Some(eol_info) = &component.eol {
//! if eol_info.status == EolStatus::EndOfLife {
//! println!("\n[!] Component '{}' has reached End-of-Life!",
//! component.name);
//! println!(" - Product: {}", eol_info.product);
//! if let Some(eol_date) = eol_info.eol_date {
//! println!(" - EOL Date: {}", eol_date);
//! }
//! }
//! }
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ### Checking for Compliance
//!
//! The [`ComplianceChecker`] validates an SBOM against a specific standard, such as the
//! EU Cyber Resilience Act (CRA).
//!
//! ```no_run
//! use std::path::Path;
//! use sbom_tools::parse_sbom;
//! use sbom_tools::quality::{ComplianceChecker, ComplianceLevel};
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let sbom = parse_sbom(Path::new("path/to/your/sbom.json"))?;
//!
//! // Check against the EU CRA Phase 2 requirements
//! let checker = ComplianceChecker::new(ComplianceLevel::CraPhase2);
//! let result = checker.check(&sbom);
//!
//! if result.is_compliant {
//! println!("SBOM is compliant with {}.", result.level.name());
//! } else {
//! println!("SBOM is NOT compliant with {}. Found {} errors and {} warnings.",
//! result.level.name(),
//! result.error_count,
//! result.warning_count
//! );
//!
//! for violation in result.violations {
//! println!("[{:?}] {}: {}",
//! violation.severity, violation.category.name(), violation.message);
//! }
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ## Feature Flags
//!
//! `sbom-tools` uses feature flags to manage optional functionality and dependencies.
//! - `enrichment`: Enables all data enrichment modules, such as OSV and EOL lookups.
//! This adds network dependencies like `reqwest`.
//!
//! ## Command-Line Interface (CLI)
//!
//! This documentation is for the `sbom-tools` library crate. If you are looking for the
//! command-line tool, please refer to the project's README or install it via `cargo install sbom-tools`.
// Lint to discourage unwrap() in production code - prefer explicit error handling
// Pedantic lints: allow categories that are design choices for this codebase
// Re-export main types for convenience
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
// TUI shared ViewModel exports for building custom TUI components
pub use ;