Skip to main content

sbom_tools/serialization/
mod.rs

1//! SBOM serialization and transformation.
2//!
3//! Two complementary strategies live here:
4//! - [`enricher`]/[`merger`]/[`pruner`] patch the *original* raw JSON in place,
5//!   preserving the source format's structure exactly.
6//! - [`emit`] *synthesizes* a fresh document from the canonical model, enabling
7//!   cross-format conversion (e.g. SPDX → CycloneDX).
8
9pub mod emit;
10mod enricher;
11mod merger;
12mod pruner;
13
14pub use emit::{
15    EmitError, EmitTarget, FidelityReport, emit, emit_cyclonedx, emit_spdx, preserve_source_json,
16};
17pub use enricher::enrich_sbom_json;
18pub use merger::{DeduplicationStrategy, MergeConfig, MergeError, merge_sbom_json};
19pub use pruner::{TailorConfig, tailor_sbom_json};
20
21use serde_json::Value;
22
23/// Extension trait for convenient JSON field access.
24pub(crate) trait ValueExt {
25    /// Get a string field or return `""` if missing/not a string.
26    fn str_field(&self, key: &str) -> &str;
27}
28
29impl ValueExt for Value {
30    fn str_field(&self, key: &str) -> &str {
31        self.get(key).and_then(Value::as_str).unwrap_or("")
32    }
33}