Skip to content

Commit cf2335c

Browse files
authored
Merge pull request #575 from justahero/sebastian/feat/v1_4_squash
Add support for 1.4 to cyclonedx-bom
2 parents c79c34d + 7b8880a commit cf2335c

File tree

432 files changed

+32296
-673
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

432 files changed

+32296
-673
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
# SBOM documents
55
**/bom.xml
66
**/*.cdx.xml
7+
!cyclonedx-bom/tests/examples/**/*.cdx.xml
78
**/bom.json
89
**/*.cdx.json
10+
!cyclonedx-bom/tests/examples/**/*.cdx.json
911

1012
# Nix Flake
1113
/.direnv/

Cargo.lock

Lines changed: 20 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cargo-cyclonedx/src/generator.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ impl SbomGenerator {
332332
}
333333

334334
fn get_licenses(&self, package: &Package) -> Option<Licenses> {
335-
let mut licenses = vec![];
335+
let mut licenses: Option<LicenseChoice> = None;
336336

337337
if let Some(license) = &package.license {
338338
let parse_mode = self
@@ -355,7 +355,7 @@ impl SbomGenerator {
355355
};
356356

357357
match result {
358-
Ok(expression) => licenses.push(LicenseChoice::Expression(expression)),
358+
Ok(expression) => licenses = Some(LicenseChoice::Expressions(vec![expression])),
359359
Err(err) => {
360360
let level = match &self.config.license_parser {
361361
Some(opts) if opts.accept_named.contains(license) => Level::Info,
@@ -368,17 +368,19 @@ impl SbomGenerator {
368368
license,
369369
err,
370370
);
371-
licenses.push(LicenseChoice::License(License::named_license(license)));
371+
licenses = Some(LicenseChoice::Licenses(vec![License::named_license(
372+
license,
373+
)]));
372374
}
373375
}
374376
}
375377

376-
if licenses.is_empty() {
378+
if let Some(licenses) = licenses {
379+
Some(Licenses(licenses))
380+
} else {
377381
log::trace!("Package {} has no licenses", package.name);
378-
return None;
382+
None
379383
}
380-
381-
Some(Licenses(licenses))
382384
}
383385

384386
fn create_metadata(&self, package: &Package) -> Result<Metadata, GeneratorError> {

cyclonedx-bom/CONTRIBUTING.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Contributing
2+
3+
Pull requests are welcome.
4+
But please read the
5+
[CycloneDX contributing guidelines](https://github.com/CycloneDX/.github/blob/master/CONTRIBUTING.md)
6+
first.
7+
8+
## Build
9+
10+
```shell
11+
cargo +stable build --verbose
12+
```
13+
14+
## Test
15+
16+
Run the tests:
17+
18+
```shell
19+
cargo test
20+
```
21+
22+
## Coding standards
23+
24+
Check for deviations from coding standards:
25+
26+
```shell
27+
cargo fmt -- --check
28+
cargo clippy --all-targets
29+
```
30+
31+
Apply coding standards via:
32+
33+
```shell
34+
cargo fmt
35+
```
36+
37+
## Sign off your commits
38+
39+
Please sign off your commits,
40+
to show that you agree to publish your changes under the current terms and licenses of the project.
41+
42+
```shell
43+
git commit --signoff ...
44+
```

cyclonedx-bom/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ rust-version.workspace = true
1515

1616
[dependencies]
1717
base64 = "0.21.2"
18-
http = "1.0.0"
18+
fluent-uri = "0.1.4"
1919
once_cell = "1.18.0"
20+
ordered-float = { version = "4.1.1", default-features = false }
2021
packageurl = "0.3.0"
2122
regex = "1.9.3"
2223
serde = { version = "1.0.193", features = ["derive"] }

cyclonedx-bom/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ assert_eq!(
8383
);
8484
```
8585

86+
## Verification and Validation
87+
88+
see [README](./tests/README.md) for details.
89+
90+
## Contributing
91+
92+
see [CONTRIBUTING](./CONTRIBUTING.md) for details.
93+
8694
## Copyright & License
8795

8896
CycloneDX Rust Cargo is Copyright (c) OWASP Foundation. All Rights Reserved.

cyclonedx-bom/src/errors.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ pub enum BomError {
2424

2525
#[error("Failed to serialize BOM to XML: {0}")]
2626
XmlSerializationError(String),
27+
28+
#[error("Failed to serialize BOM to v1.3: {0}")]
29+
BomV13SerializationError(String),
2730
}
2831

2932
#[derive(Debug, thiserror::Error)]
@@ -34,6 +37,11 @@ pub enum JsonWriteError {
3437
#[from]
3538
error: serde_json::Error,
3639
},
40+
#[error("Failed to convert Bom: {error}")]
41+
BomError {
42+
#[from]
43+
error: BomError,
44+
},
3745
}
3846

3947
#[derive(Debug, thiserror::Error)]
@@ -45,6 +53,11 @@ pub enum XmlWriteError {
4553
error: xml::writer::Error,
4654
element: String,
4755
},
56+
#[error("Failed to convert Bom: {error}")]
57+
BomError {
58+
#[from]
59+
error: BomError,
60+
},
4861
}
4962

5063
#[derive(Debug, thiserror::Error)]

cyclonedx-bom/src/external_models/uri.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use std::{convert::TryFrom, str::FromStr};
2020

21+
use fluent_uri::Uri as Url;
2122
use packageurl::PackageUrl;
2223
use thiserror::Error;
2324

@@ -74,7 +75,7 @@ impl TryFrom<String> for Uri {
7475
type Error = UriError;
7576

7677
fn try_from(value: String) -> Result<Self, Self::Error> {
77-
match value.parse::<http::Uri>() {
78+
match Url::parse(value.as_str()) {
7879
Ok(_) => Ok(Uri(value)),
7980
Err(_) => Err(UriError::InvalidUri(
8081
"Uri does not conform to RFC 3986".to_string(),
@@ -88,11 +89,11 @@ impl Validate for Uri {
8889
&self,
8990
context: ValidationContext,
9091
) -> Result<ValidationResult, ValidationError> {
91-
match self.0.parse::<http::Uri>() {
92+
match Url::parse(&self.0.to_string()) {
9293
Ok(_) => Ok(ValidationResult::Passed),
9394
Err(_) => Ok(ValidationResult::Failed {
9495
reasons: vec![FailureReason {
95-
message: "Uri does not conform to ISO 8601".to_string(),
96+
message: "Uri does not conform to RFC 3986".to_string(),
9697
context,
9798
}],
9899
}),
@@ -169,7 +170,7 @@ mod test {
169170
validation_result,
170171
ValidationResult::Failed {
171172
reasons: vec![FailureReason {
172-
message: "Uri does not conform to ISO 8601".to_string(),
173+
message: "Uri does not conform to RFC 3986".to_string(),
173174
context: ValidationContext::default()
174175
}]
175176
}

0 commit comments

Comments
 (0)