forked from trustification/trustify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
101 additions
and
63 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub mod spdx; | ||
|
||
use crate::cpe::Cpe; | ||
use crate::purl::Purl; | ||
use uuid::Uuid; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use sbom_walker::report::ReportSink; | ||
use serde_json::Value; | ||
use spdx_rs::models::SPDX; | ||
|
||
/// Parse a SPDX document, possibly replacing invalid license expressions. | ||
/// | ||
/// Returns the parsed document and a flag indicating if license expressions got replaced. | ||
pub fn parse_spdx(report: &dyn ReportSink, json: Value) -> Result<(SPDX, bool), serde_json::Error> { | ||
let (json, changed) = fix_license(report, json); | ||
Ok((serde_json::from_value(json)?, changed)) | ||
} | ||
|
||
/// Check the document for invalid SPDX license expressions and replace them with `NOASSERTION`. | ||
pub fn fix_license(report: &dyn ReportSink, mut json: Value) -> (Value, bool) { | ||
let mut changed = false; | ||
if let Some(packages) = json["packages"].as_array_mut() { | ||
for package in packages { | ||
if let Some(declared) = package["licenseDeclared"].as_str() { | ||
if let Err(err) = spdx_expression::SpdxExpression::parse(declared) { | ||
package["licenseDeclared"] = "NOASSERTION".into(); | ||
changed = true; | ||
|
||
let message = | ||
format!("Replacing faulty SPDX license expression with NOASSERTION: {err}"); | ||
log::debug!("{message}"); | ||
report.error(message); | ||
} | ||
} | ||
} | ||
} | ||
|
||
(json, changed) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters