Skip to content

Commit

Permalink
chore: extend loader detection for cyclonedx 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Dec 9, 2024
1 parent a12a763 commit bca5f75
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 5 additions & 4 deletions modules/ingestor/src/service/advisory/csaf/loader.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::service::advisory::csaf::util::gen_identifier;
use crate::{
graph::{
advisory::{
Expand All @@ -8,7 +7,10 @@ use crate::{
Graph,
},
model::IngestResult,
service::{advisory::csaf::StatusCreator, Error, Warnings},
service::{
advisory::csaf::{util::gen_identifier, StatusCreator},
Error, Warnings,
},
};
use csaf::{
vulnerability::{ProductStatus, Vulnerability},
Expand All @@ -17,8 +19,7 @@ use csaf::{
use sbom_walker::report::ReportSink;
use sea_orm::{ConnectionTrait, TransactionTrait};
use semver::Version;
use std::fmt::Debug;
use std::str::FromStr;
use std::{fmt::Debug, str::FromStr};
use time::OffsetDateTime;
use tracing::instrument;
use trustify_common::{hashing::Digests, id::Id};
Expand Down
10 changes: 8 additions & 2 deletions modules/ingestor/src/service/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ impl<'g> Format {

pub fn is_cyclonedx(bytes: &[u8]) -> Result<bool, Error> {
match masked(depth(1).and(key("specVersion")), bytes) {
Ok(Some(x)) if matches!(x.as_str(), "1.3" | "1.4" | "1.5") => Ok(true),
Ok(Some(x)) if matches!(x.as_str(), "1.3" | "1.4" | "1.5" | "1.6") => Ok(true),
Ok(Some(x)) => Err(Error::UnsupportedFormat(format!(
"CycloneDX version {x} is unsupported; try 1.3, 1.4, or 1.5"
"CycloneDX version {x} is unsupported; try 1.3, 1.4, 1.5, 1.6"
))),
Err(_) | Ok(None) => Ok(false),
}
Expand Down Expand Up @@ -293,6 +293,12 @@ mod test {
Ok(Format::CycloneDX)
));

let cyclone = document_bytes("cyclonedx/simple_1dot6.json").await?;
assert!(matches!(
Format::from_bytes(&cyclone),
Ok(Format::CycloneDX)
));

let spdx = document_bytes("ubi9-9.2-755.1697625012.json").await?;
assert!(matches!(Format::from_bytes(&spdx), Ok(Format::SPDX)));

Expand Down

0 comments on commit bca5f75

Please sign in to comment.