Skip to content

Commit 2658f3a

Browse files
committed
Rename main validate function
* specify version to validate in specification tests Signed-off-by: Sebastian Ziebell <[email protected]>
1 parent b80f397 commit 2658f3a

25 files changed

+151
-152
lines changed

cargo-cyclonedx/src/generator.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ use cyclonedx_bom::models::metadata::Metadata;
4949
use cyclonedx_bom::models::metadata::MetadataError;
5050
use cyclonedx_bom::models::organization::OrganizationalContact;
5151
use cyclonedx_bom::models::tool::{Tool, Tools};
52-
use cyclonedx_bom::validation::Validate;
53-
use cyclonedx_bom::validation::ValidationResult;
52+
use cyclonedx_bom::validation::{Validate, ValidationResult};
5453
use once_cell::sync::Lazy;
5554
use regex::Regex;
5655

cyclonedx-bom/src/models/advisory.rs

Lines changed: 5 additions & 5 deletions
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_version(&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)
@@ -61,9 +61,9 @@ impl Validate for Advisory {
6161
pub struct Advisories(pub Vec<Advisory>);
6262

6363
impl Validate for Advisories {
64-
fn validate(&self, version: SpecVersion) -> ValidationResult {
64+
fn validate_version(&self, version: SpecVersion) -> ValidationResult {
6565
ValidationContext::new()
66-
.add_list("inner", &self.0, |advisory| advisory.validate(version))
66+
.add_list("inner", &self.0, |advisory| advisory.validate_version(version))
6767
.into()
6868
}
6969
}
@@ -84,7 +84,7 @@ mod test {
8484
title: Some(NormalizedString::new("title")),
8585
url: Uri("https://example.com".to_string()),
8686
}])
87-
.validate_default();
87+
.validate();
8888

8989
assert_eq!(validation_result, ValidationResult::Passed);
9090
}
@@ -95,7 +95,7 @@ mod test {
9595
title: Some(NormalizedString("invalid\ttitle".to_string())),
9696
url: Uri("invalid url".to_string()),
9797
}])
98-
.validate_default();
98+
.validate();
9999

100100
assert_eq!(
101101
validation_result.errors(),

cyclonedx-bom/src/models/attached_text.rs

Lines changed: 5 additions & 5 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_version(&self, _version: SpecVersion) -> ValidationResult {
5151
let mut context = ValidationContext::new().add_field_option(
5252
"content_type",
5353
self.content_type.as_ref(),
@@ -138,7 +138,7 @@ mod test {
138138
encoding: Some(Encoding::Base64),
139139
content: "dGhpcyB0ZXh0IGlzIHBsYWlu".to_string(),
140140
}
141-
.validate_default();
141+
.validate();
142142

143143
assert_eq!(validation_result, ValidationResult::Passed);
144144
}
@@ -150,7 +150,7 @@ mod test {
150150
encoding: Some(Encoding::Base64),
151151
content: "not base64 encoded".to_string(),
152152
}
153-
.validate_default();
153+
.validate();
154154

155155
assert_eq!(
156156
validation_result.errors(),
@@ -174,7 +174,7 @@ mod test {
174174
encoding: Some(Encoding::UnknownEncoding("unknown".to_string())),
175175
content: "not base64 encoded".to_string(),
176176
}
177-
.validate_default();
177+
.validate();
178178

179179
assert_eq!(
180180
validation_result.errors(),
@@ -189,7 +189,7 @@ mod test {
189189
encoding: None,
190190
content: "not base64 encoded".to_string(),
191191
}
192-
.validate_default();
192+
.validate();
193193

194194
assert_eq!(validation_result, ValidationResult::Passed);
195195
}

cyclonedx-bom/src/models/bom.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl Default for Bom {
226226
}
227227

228228
impl Validate for Bom {
229-
fn validate(&self, version: SpecVersion) -> ValidationResult {
229+
fn validate_version(&self, version: SpecVersion) -> ValidationResult {
230230
let mut context = ValidationContext::new()
231231
.add_field_option(
232232
"serial_number",
@@ -503,7 +503,7 @@ mod test {
503503
signature: None,
504504
};
505505

506-
let actual = bom.validate_default();
506+
let actual = bom.validate();
507507

508508
assert_eq!(actual, ValidationResult::Passed);
509509
}
@@ -527,7 +527,7 @@ mod test {
527527
signature: None,
528528
};
529529

530-
let actual = bom.validate_default();
530+
let actual = bom.validate();
531531

532532
assert_eq!(
533533
actual.errors(),
@@ -568,7 +568,7 @@ mod test {
568568
signature: None,
569569
};
570570

571-
let actual = bom.validate(SpecVersion::V1_3);
571+
let actual = bom.validate_version(SpecVersion::V1_3);
572572

573573
assert_eq!(
574574
actual.errors(),
@@ -685,7 +685,7 @@ mod test {
685685
signature: None,
686686
};
687687

688-
let actual = bom.validate_default();
688+
let actual = bom.validate();
689689

690690
/*
691691
assert_eq!(
@@ -845,7 +845,7 @@ mod test {
845845
vulnerabilities: None,
846846
signature: None,
847847
}
848-
.validate_default();
848+
.validate();
849849

850850
/*
851851
assert_eq!(

cyclonedx-bom/src/models/code.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub struct Commit {
3838
}
3939

4040
impl Validate for Commit {
41-
fn validate(&self, version: SpecVersion) -> ValidationResult {
41+
fn validate_version(&self, version: SpecVersion) -> ValidationResult {
4242
ValidationContext::new()
4343
.add_field_option("uid", self.uid.as_ref(), validate_normalized_string)
4444
.add_field_option("url", self.url.as_ref(), validate_uri)
@@ -53,9 +53,9 @@ impl Validate for Commit {
5353
pub struct Commits(pub Vec<Commit>);
5454

5555
impl Validate for Commits {
56-
fn validate(&self, version: SpecVersion) -> ValidationResult {
56+
fn validate_version(&self, version: SpecVersion) -> ValidationResult {
5757
ValidationContext::new()
58-
.add_list("inner", &self.0, |commit| commit.validate(version))
58+
.add_list("inner", &self.0, |commit| commit.validate_version(version))
5959
.into()
6060
}
6161
}
@@ -67,7 +67,7 @@ pub struct Diff {
6767
}
6868

6969
impl Validate for Diff {
70-
fn validate(&self, version: SpecVersion) -> ValidationResult {
70+
fn validate_version(&self, version: SpecVersion) -> ValidationResult {
7171
ValidationContext::new()
7272
.add_struct_option("text", self.text.as_ref(), version)
7373
.add_field_option("url", self.url.as_ref(), validate_uri)
@@ -83,7 +83,7 @@ pub struct IdentifiableAction {
8383
}
8484

8585
impl Validate for IdentifiableAction {
86-
fn validate(&self, version: SpecVersion) -> ValidationResult {
86+
fn validate_version(&self, _version: SpecVersion) -> ValidationResult {
8787
ValidationContext::new()
8888
.add_field_option("timestamp", self.timestamp.as_ref(), validate_date_time)
8989
.add_field_option("name", self.name.as_ref(), validate_normalized_string)
@@ -103,7 +103,7 @@ pub struct Issue {
103103
}
104104

105105
impl Validate for Issue {
106-
fn validate(&self, version: SpecVersion) -> ValidationResult {
106+
fn validate_version(&self, version: SpecVersion) -> ValidationResult {
107107
ValidationContext::new()
108108
.add_field(
109109
"issue_type",
@@ -175,7 +175,7 @@ pub struct Patch {
175175
}
176176

177177
impl Validate for Patch {
178-
fn validate(&self, version: SpecVersion) -> ValidationResult {
178+
fn validate_version(&self, version: SpecVersion) -> ValidationResult {
179179
ValidationContext::new()
180180
.add_enum(
181181
"patch_type",
@@ -184,7 +184,7 @@ impl Validate for Patch {
184184
)
185185
.add_struct_option("diff", self.diff.as_ref(), version)
186186
.add_list_option("resolves", self.resolves.as_ref(), |issue| {
187-
issue.validate(version)
187+
issue.validate_version(version)
188188
})
189189
.into()
190190
}
@@ -194,9 +194,9 @@ impl Validate for Patch {
194194
pub struct Patches(pub Vec<Patch>);
195195

196196
impl Validate for Patches {
197-
fn validate(&self, version: SpecVersion) -> ValidationResult {
197+
fn validate_version(&self, version: SpecVersion) -> ValidationResult {
198198
ValidationContext::new()
199-
.add_list("inner", &self.0, |patch| patch.validate(version))
199+
.add_list("inner", &self.0, |patch| patch.validate_version(version))
200200
.into()
201201
}
202202
}
@@ -255,7 +255,7 @@ pub struct Source {
255255
}
256256

257257
impl Validate for Source {
258-
fn validate(&self, version: SpecVersion) -> ValidationResult {
258+
fn validate_version(&self, version: SpecVersion) -> ValidationResult {
259259
ValidationContext::new()
260260
.add_field_option("name", self.name.as_ref(), validate_normalized_string)
261261
.add_field_option("url", self.url.as_ref(), validate_uri)
@@ -287,7 +287,7 @@ mod test {
287287
}),
288288
message: Some(NormalizedString("no_whitespace".to_string())),
289289
}])
290-
.validate_default();
290+
.validate();
291291

292292
assert_eq!(validation_result, ValidationResult::Passed);
293293
}
@@ -309,7 +309,7 @@ mod test {
309309
}),
310310
message: Some(NormalizedString("spaces and\ttabs".to_string())),
311311
}])
312-
.validate_default();
312+
.validate();
313313

314314
assert_eq!(
315315
validation_result.errors(),
@@ -370,7 +370,7 @@ mod test {
370370
references: Some(vec![Uri("https://example.com".to_string())]),
371371
}]),
372372
}])
373-
.validate_default();
373+
.validate();
374374

375375
assert_eq!(validation_result, ValidationResult::Passed);
376376
}
@@ -399,7 +399,7 @@ mod test {
399399
references: Some(vec![Uri("invalid uri".to_string())]),
400400
}]),
401401
}])
402-
.validate_default();
402+
.validate();
403403

404404
assert_eq!(
405405
validation_result.errors(),

cyclonedx-bom/src/models/component.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl Component {
106106
}
107107

108108
impl Validate for Component {
109-
fn validate(&self, version: SpecVersion) -> ValidationResult {
109+
fn validate_version(&self, version: SpecVersion) -> ValidationResult {
110110
ValidationContext::new()
111111
.add_field(
112112
"component_type",
@@ -157,9 +157,9 @@ impl Validate for Component {
157157
pub struct Components(pub Vec<Component>);
158158

159159
impl Validate for Components {
160-
fn validate(&self, version: SpecVersion) -> ValidationResult {
160+
fn validate_version(&self, version: SpecVersion) -> ValidationResult {
161161
ValidationContext::new()
162-
.add_list("inner", &self.0, |component| component.validate(version))
162+
.add_list("inner", &self.0, |component| component.validate_version(version))
163163
.into()
164164
}
165165
}
@@ -288,7 +288,7 @@ pub struct Swid {
288288
}
289289

290290
impl Validate for Swid {
291-
fn validate(&self, version: SpecVersion) -> ValidationResult {
291+
fn validate_version(&self, version: SpecVersion) -> ValidationResult {
292292
ValidationContext::new()
293293
.add_struct_option("text", self.text.as_ref(), version)
294294
.add_field_option("url", self.url.as_ref(), validate_uri)
@@ -322,7 +322,7 @@ pub struct ComponentEvidence {
322322
}
323323

324324
impl Validate for ComponentEvidence {
325-
fn validate(&self, version: SpecVersion) -> ValidationResult {
325+
fn validate_version(&self, version: SpecVersion) -> ValidationResult {
326326
ValidationContext::new()
327327
.add_struct_option("licenses", self.licenses.as_ref(), version)
328328
.add_struct_option("copyright", self.copyright.as_ref(), version)
@@ -341,7 +341,7 @@ pub struct Pedigree {
341341
}
342342

343343
impl Validate for Pedigree {
344-
fn validate(&self, version: SpecVersion) -> ValidationResult {
344+
fn validate_version(&self, version: SpecVersion) -> ValidationResult {
345345
ValidationContext::new().into()
346346
/*
347347
let mut results: Vec<ValidationResult> = vec![];
@@ -394,7 +394,7 @@ pub struct Copyright(pub String);
394394
pub struct CopyrightTexts(pub(crate) Vec<Copyright>);
395395

396396
impl Validate for CopyrightTexts {
397-
fn validate(&self, _version: SpecVersion) -> ValidationResult {
397+
fn validate_version(&self, _version: SpecVersion) -> ValidationResult {
398398
ValidationContext::new()
399399
.add_list("inner", &self.0, validate_copyright)
400400
.into()
@@ -498,7 +498,7 @@ mod test {
498498
}),
499499
signature: Some(Signature::single(Algorithm::HS512, "abcdefgh")),
500500
}])
501-
.validate_default();
501+
.validate();
502502

503503
assert_eq!(validation_result, ValidationResult::Passed);
504504
}
@@ -586,7 +586,7 @@ mod test {
586586
}),
587587
signature: Some(Signature::single(Algorithm::HS512, "abcdefgh")),
588588
}])
589-
.validate_default();
589+
.validate();
590590

591591
/*
592592
assert_eq!(

cyclonedx-bom/src/models/composition.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub struct Composition {
2929
}
3030

3131
impl Validate for Composition {
32-
fn validate(&self, version: SpecVersion) -> ValidationResult {
32+
fn validate_version(&self, version: SpecVersion) -> ValidationResult {
3333
ValidationContext::new()
3434
.add_field("aggregate", &self.aggregate, validate_aggregate_type)
3535
.into()
@@ -40,10 +40,10 @@ impl Validate for Composition {
4040
pub struct Compositions(pub Vec<Composition>);
4141

4242
impl Validate for Compositions {
43-
fn validate(&self, version: SpecVersion) -> ValidationResult {
43+
fn validate_version(&self, version: SpecVersion) -> ValidationResult {
4444
ValidationContext::new()
4545
.add_list("composition", &self.0, |composition| {
46-
composition.validate(version)
46+
composition.validate_version(version)
4747
})
4848
.into()
4949
}
@@ -116,7 +116,7 @@ mod test {
116116
dependencies: Some(vec![BomReference("reference".to_string())]),
117117
signature: Some(Signature::single(Algorithm::HS512, "abcdefgh")),
118118
}])
119-
.validate(SpecVersion::V1_3);
119+
.validate_version(SpecVersion::V1_3);
120120

121121
assert_eq!(validation_result, ValidationResult::Passed);
122122
}
@@ -129,7 +129,7 @@ mod test {
129129
dependencies: Some(vec![BomReference("reference".to_string())]),
130130
signature: Some(Signature::single(Algorithm::HS512, "abcdefgh")),
131131
}])
132-
.validate(SpecVersion::V1_3);
132+
.validate_version(SpecVersion::V1_3);
133133

134134
assert_eq!(
135135
validation_result.errors(),

0 commit comments

Comments
 (0)