Skip to content

Commit ebbaf27

Browse files
committed
Fix compile errors
Signed-off-by: Sebastian Ziebell <[email protected]>
1 parent bcda061 commit ebbaf27

File tree

4 files changed

+37
-29
lines changed

4 files changed

+37
-29
lines changed

cyclonedx-bom/src/external_models/spdx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ impl ToString for SpdxIdentifier {
8181
}
8282

8383
pub fn validate_spdx_identifier(identifier: &SpdxIdentifier) -> Result<(), ValidationError> {
84-
match SpdxIdentifier::try_from(identifier.0) {
85-
Err(error) => Err(ValidationError::new("SPDX identifier is not valid")),
84+
match SpdxIdentifier::try_from(identifier.0.to_string()) {
85+
Err(_error) => Err(ValidationError::new("SPDX identifier is not valid")),
8686
_ => Ok(()),
8787
}
8888
}

cyclonedx-bom/src/models/advisory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl Advisory {
4949
}
5050

5151
impl Validate for Advisory {
52-
fn validate(&self, version: SpecVersion) -> ValidationResult {
52+
fn validate(&self, _version: SpecVersion) -> ValidationResult {
5353
ValidationContext::new()
5454
.add_field_option("title", self.title.as_ref(), validate_normalized_string)
5555
.add_field("url", &self.url, validate_uri)

cyclonedx-bom/src/models/attached_text.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl AttachedText {
4747
}
4848

4949
impl Validate for AttachedText {
50-
fn validate(&self, version: SpecVersion) -> ValidationResult {
50+
fn validate(&self, _version: SpecVersion) -> ValidationResult {
5151
let mut context = ValidationContext::new().add_field_option(
5252
"content_type",
5353
self.content_type.as_ref(),
@@ -58,12 +58,12 @@ impl Validate for AttachedText {
5858
match (encoding, STANDARD.decode(self.content.clone())) {
5959
(Encoding::Base64, Ok(_)) => (),
6060
(Encoding::Base64, Err(_)) => {
61-
context.add_field("content", self.content, |_| {
61+
context = context.add_field("content", &self.content, |_| {
6262
Err("Content is not Base64 encoded".into())
6363
});
6464
}
6565
(Encoding::UnknownEncoding(_), _) => {
66-
context.add_field("encoding", encoding, validate_encoding);
66+
context = context.add_field("encoding", encoding, validate_encoding);
6767
}
6868
}
6969
}

cyclonedx-bom/src/models/bom.rs

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -247,23 +247,23 @@ impl Validate for Bom {
247247

248248
if let Some(metadata) = &self.metadata {
249249
if let Some(component) = &metadata.component {
250-
validate_component_bom_refs(&mut context, &mut bom_refs, component);
250+
context = validate_component_bom_refs(context, &mut bom_refs, component);
251251
}
252252
}
253253

254254
if let Some(components) = &self.components {
255-
validate_components(&mut context, &mut bom_refs, components);
255+
context = validate_components(context, &mut bom_refs, components);
256256
}
257257

258258
if let Some(services) = &self.services {
259-
validate_services(&mut context, &mut bom_refs, services);
259+
context = validate_services(context, &mut bom_refs, services);
260260
}
261261

262262
// Check dependencies & sub dependencies
263263
if let Some(dependencies) = &self.dependencies {
264264
for dependency in &dependencies.0 {
265265
if !bom_refs.contains(&dependency.dependency_ref) {
266-
context.add_custom(
266+
context = context.add_custom(
267267
"dependency_ref",
268268
format!(
269269
"Dependency ref '{}' does not exist in the BOM",
@@ -274,7 +274,7 @@ impl Validate for Bom {
274274

275275
for sub_dependency in &dependency.dependencies {
276276
if !bom_refs.contains(sub_dependency) {
277-
context.add_custom(
277+
context = context.add_custom(
278278
"sub dependency_ref",
279279
format!(
280280
"Dependency ref '{}' does not exist in the BOM",
@@ -289,10 +289,10 @@ impl Validate for Bom {
289289
// Check compositions, its dependencies & assemblies
290290
if let Some(compositions) = &self.compositions {
291291
for composition in &compositions.0 {
292-
if let Some(assemblies) = composition.assemblies {
293-
for BomReference(assembly) in &assemblies {
292+
if let Some(assemblies) = &composition.assemblies {
293+
for BomReference(assembly) in assemblies {
294294
if !bom_refs.contains(assembly) {
295-
context.add_custom(
295+
context = context.add_custom(
296296
"composition ref",
297297
format!(
298298
"Composition reference '{assembly}' does not exist in the BOM"
@@ -305,7 +305,7 @@ impl Validate for Bom {
305305
if let Some(dependencies) = &composition.dependencies {
306306
for BomReference(dependency) in dependencies {
307307
if !bom_refs.contains(&dependency) {
308-
context.add_custom(
308+
context = context.add_custom(
309309
"composition ref",
310310
format!(
311311
"Composition reference '{dependency}' does not exist in the BOM"
@@ -343,57 +343,65 @@ impl BomReferencesContext {
343343

344344
/// Validates the Bom references.
345345
fn validate_component_bom_refs(
346-
context: &mut ValidationContext,
346+
mut context: ValidationContext,
347347
bom_refs: &mut BomReferencesContext,
348348
component: &Component,
349-
) {
349+
) -> ValidationContext {
350350
if let Some(bom_ref) = &component.bom_ref {
351351
if bom_refs.contains(&bom_ref) {
352-
context.add_custom("bom_ref", format!(r#"Bom ref "{bom_ref}" is not unique"#));
352+
context =
353+
context.add_custom("bom_ref", format!(r#"Bom ref "{bom_ref}" is not unique"#));
353354
}
354355
bom_refs.add_component_bom_ref(bom_ref);
355356
}
356357

357358
if let Some(components) = &component.components {
358-
validate_components(context, bom_refs, components);
359+
context = validate_components(context, bom_refs, components);
359360
}
361+
362+
context
360363
}
361364

362365
fn validate_components(
363-
context: &mut ValidationContext,
366+
mut context: ValidationContext,
364367
bom_refs: &mut BomReferencesContext,
365368
components: &Components,
366-
) {
369+
) -> ValidationContext {
367370
for component in &components.0 {
368-
validate_component_bom_refs(context, bom_refs, component);
371+
context = validate_component_bom_refs(context, bom_refs, component);
369372
}
373+
context
370374
}
371375

372376
fn validate_services(
373-
context: &mut ValidationContext,
377+
mut context: ValidationContext,
374378
bom_refs: &mut BomReferencesContext,
375379
services: &Services,
376-
) {
380+
) -> ValidationContext {
377381
for service in &services.0 {
378-
validate_service_bom_refs(context, bom_refs, service);
382+
context = validate_service_bom_refs(context, bom_refs, service);
379383
}
384+
context
380385
}
381386

382387
fn validate_service_bom_refs(
383-
context: &mut ValidationContext,
388+
mut context: ValidationContext,
384389
bom_refs: &mut BomReferencesContext,
385390
service: &Service,
386-
) {
391+
) -> ValidationContext {
387392
if let Some(bom_ref) = &service.bom_ref {
388393
if bom_refs.contains(bom_ref) {
389-
context.add_custom("bom_ref", format!(r#"Bom ref "{bom_ref}" is not unique"#));
394+
context =
395+
context.add_custom("bom_ref", format!(r#"Bom ref "{bom_ref}" is not unique"#));
390396
}
391397
bom_refs.add_service_bom_ref(bom_ref);
392398
}
393399

394400
if let Some(services) = &service.services {
395-
validate_services(context, bom_refs, services);
401+
context = validate_services(context, bom_refs, services);
396402
}
403+
404+
context
397405
}
398406

399407
#[derive(Clone, Debug, PartialEq, Eq)]

0 commit comments

Comments
 (0)