Skip to content

Commit a70ebeb

Browse files
committed
Fix compile errors
* ensure code compiles again, fixing all compile errors * update tests Signed-off-by: Sebastian Ziebell <[email protected]>
1 parent ebbaf27 commit a70ebeb

File tree

13 files changed

+44
-46
lines changed

13 files changed

+44
-46
lines changed

cargo-cyclonedx/src/generator.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,11 @@ impl GeneratedSbom {
714714
// If running in debug mode, validate that the SBOM is self-consistent and well-formed
715715
if cfg!(debug_assertions) {
716716
let result = bom.validate();
717-
if let ValidationResult::Failed { reasons } = result {
718-
panic!("The generated SBOM failed validation: {:?}", &reasons);
717+
if result.has_errors() {
718+
panic!(
719+
"The generated SBOM failed validation: {:?}",
720+
result.errors()
721+
);
719722
}
720723
}
721724

cargo-cyclonedx/src/purl.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::str::FromStr;
22

33
use cargo_metadata::{camino::Utf8Path, Package};
4-
use cyclonedx_bom::prelude::Purl as CdxPurl;
4+
use cyclonedx_bom::{external_models::uri::validate_purl, prelude::Purl as CdxPurl};
55
use pathdiff::diff_utf8_paths;
66
use purl::{PackageError, PackageType, PurlBuilder};
77

@@ -81,8 +81,7 @@ fn to_purl_subpath(path: &Utf8Path) -> String {
8181
}
8282

8383
fn assert_validation_passes(purl: &CdxPurl) {
84-
use cyclonedx_bom::validation::{Validate, ValidationResult};
85-
assert_eq!(purl.validate(), ValidationResult::Passed);
84+
assert!(validate_purl(purl).is_ok());
8685
}
8786

8887
#[cfg(test)]

cyclonedx-bom/src/models/advisory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ mod test {
101101
validation_result.errors(),
102102
Some(validation::list(
103103
"Advisory",
104-
&[(
104+
[(
105105
0,
106106
vec![
107107
validation::field(

cyclonedx-bom/src/models/bom.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ mod test {
574574
actual.errors(),
575575
Some(validation::list(
576576
"compositions",
577-
&[(
577+
[(
578578
0,
579579
vec![
580580
validation::custom(

cyclonedx-bom/src/models/code.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ mod test {
318318
validation_result.errors(),
319319
Some(validation::list(
320320
"inner",
321-
&[(
321+
[(
322322
0,
323323
vec![
324324
validation::field(
@@ -408,7 +408,7 @@ mod test {
408408
validation_result.errors(),
409409
Some(validation::list(
410410
"inner",
411-
&[(
411+
[(
412412
0,
413413
vec![
414414
validation::field("patch_type", "Unknown patch classification"),
@@ -429,7 +429,7 @@ mod test {
429429
),
430430
validation::list(
431431
"resolves",
432-
&[(
432+
[(
433433
0,
434434
vec![
435435
validation::field("issue_type", "Unknown issue classification"),
@@ -449,7 +449,7 @@ mod test {
449449
)
450450
]
451451
),
452-
validation::list("references", &[(0, validation::field("inner", "Uri does not conform to RFC 3986"))])
452+
validation::list("references", [(0, validation::field("inner", "Uri does not conform to RFC 3986"))])
453453
]
454454
)]
455455
)

cyclonedx-bom/src/models/composition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ mod test {
135135
validation_result.errors(),
136136
Some(validation::list(
137137
"composition",
138-
&[(
138+
[(
139139
0,
140140
validation::r#field("aggregate", "Unknown aggregate type")
141141
)]

cyclonedx-bom/src/models/external_reference.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ mod test {
202202
validation_result.errors(),
203203
Some(validation::list(
204204
"inner",
205-
&[(
205+
[(
206206
0,
207207
validation::r#struct(
208208
"ExternalReference",
@@ -214,7 +214,7 @@ mod test {
214214
validation::field("url", "Uri does not conform to RFC 3986"),
215215
validation::list(
216216
"hashes",
217-
&[(
217+
[(
218218
0,
219219
validation::field(
220220
"content",

cyclonedx-bom/src/models/hash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ mod test {
172172
validation_result.errors(),
173173
Some(validation::list(
174174
"inner",
175-
&[(
175+
[(
176176
0,
177177
vec![
178178
validation::field("alg", "Unknown HashAlgorithm"),

cyclonedx-bom/src/models/license.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ impl Validate for LicenseChoice {
5454

5555
match self {
5656
LicenseChoice::License(license) => {
57-
context.add_struct("license", license, version);
57+
context = context.add_struct("license", license, version);
5858
}
5959
LicenseChoice::Expression(expression) => {
60-
context.add_enum("expression", expression, validate_spdx_expression);
60+
context = context.add_enum("expression", expression, validate_spdx_expression);
6161
}
6262
}
6363

@@ -148,17 +148,15 @@ pub enum LicenseIdentifier {
148148
}
149149

150150
impl Validate for LicenseIdentifier {
151-
fn validate(&self, version: SpecVersion) -> ValidationResult {
152-
let mut context = ValidationContext::new();
151+
fn validate(&self, _version: SpecVersion) -> ValidationResult {
153152
match self {
154-
LicenseIdentifier::Name(name) => {
155-
context.add_enum("Name", name, validate_normalized_string);
156-
}
157-
LicenseIdentifier::SpdxId(id) => {
158-
context.add_field("SpdxId", id, validate_spdx_identifier);
159-
}
153+
LicenseIdentifier::Name(name) => ValidationContext::new()
154+
.add_enum("Name", name, validate_normalized_string)
155+
.into(),
156+
LicenseIdentifier::SpdxId(id) => ValidationContext::new()
157+
.add_field("SpdxId", id, validate_spdx_identifier)
158+
.into(),
160159
}
161-
context.into()
162160
}
163161
}
164162

cyclonedx-bom/src/models/property.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ mod test {
104104
validation_result.errors(),
105105
Some(validation::list(
106106
"Property",
107-
&[(
107+
[(
108108
0,
109109
validation::field(
110110
"value",

0 commit comments

Comments
 (0)