mod cyclonedx;
mod fidelity;
mod preserve;
mod spdx;
pub use cyclonedx::emit_cyclonedx;
pub use fidelity::FidelityReport;
pub use preserve::preserve_source_json;
pub use spdx::emit_spdx;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum EmitTarget {
CycloneDx,
Spdx,
}
impl EmitTarget {
#[must_use]
pub fn parse(s: &str) -> Option<Self> {
match s.to_ascii_lowercase().as_str() {
"cyclonedx" | "cdx" | "cyclone-dx" => Some(Self::CycloneDx),
"spdx" => Some(Self::Spdx),
_ => None,
}
}
}
#[derive(Debug, thiserror::Error)]
pub enum EmitError {
#[error("emitting to {0} is not yet implemented")]
Unsupported(&'static str),
#[error("failed to serialize emitted SBOM: {0}")]
Serialize(#[from] serde_json::Error),
}
pub fn emit(
sbom: &crate::model::NormalizedSbom,
target: EmitTarget,
) -> Result<(String, FidelityReport), EmitError> {
match target {
EmitTarget::CycloneDx => emit_cyclonedx(sbom),
EmitTarget::Spdx => emit_spdx(sbom),
}
}