@@ -22,9 +22,7 @@ use fluent_uri::Uri as Url;
2222use packageurl:: PackageUrl ;
2323use thiserror:: Error ;
2424
25- use crate :: validation:: {
26- FailureReason , Validate , ValidationContext , ValidationError , ValidationResult ,
27- } ;
25+ use crate :: validation:: { Validate , ValidationContext , ValidationResult } ;
2826
2927#[ derive( Debug , Clone , PartialEq , Eq ) ]
3028pub struct Purl ( pub ( crate ) String ) ;
@@ -45,18 +43,13 @@ impl ToString for Purl {
4543}
4644
4745impl Validate for Purl {
48- fn validate_with_context (
49- & self ,
50- context : ValidationContext ,
51- ) -> Result < ValidationResult , ValidationError > {
46+ fn validate_with_context ( & self , context : ValidationContext ) -> ValidationResult {
5247 match PackageUrl :: from_str ( & self . 0 . to_string ( ) ) {
53- Ok ( _) => Ok ( ValidationResult :: Passed ) ,
54- Err ( e) => Ok ( ValidationResult :: Failed {
55- reasons : vec ! [ FailureReason {
56- message: format!( "Purl does not conform to Package URL spec: {}" , e) ,
57- context,
58- } ] ,
59- } ) ,
48+ Ok ( _) => ValidationResult :: Passed ,
49+ Err ( e) => ValidationResult :: failure (
50+ & format ! ( "Purl does not conform to Package URL spec: {}" , e) ,
51+ context,
52+ ) ,
6053 }
6154 }
6255}
@@ -85,18 +78,10 @@ impl TryFrom<String> for Uri {
8578}
8679
8780impl Validate for Uri {
88- fn validate_with_context (
89- & self ,
90- context : ValidationContext ,
91- ) -> Result < ValidationResult , ValidationError > {
81+ fn validate_with_context ( & self , context : ValidationContext ) -> ValidationResult {
9282 match Url :: parse ( & self . 0 . to_string ( ) ) {
93- Ok ( _) => Ok ( ValidationResult :: Passed ) ,
94- Err ( _) => Ok ( ValidationResult :: Failed {
95- reasons : vec ! [ FailureReason {
96- message: "Uri does not conform to RFC 3986" . to_string( ) ,
97- context,
98- } ] ,
99- } ) ,
83+ Ok ( _) => ValidationResult :: Passed ,
84+ Err ( _) => ValidationResult :: failure ( "Uri does not conform to RFC 3986" , context) ,
10085 }
10186 }
10287}
@@ -126,18 +111,14 @@ mod test {
126111
127112 #[ test]
128113 fn valid_purls_should_pass_validation ( ) {
129- let validation_result =
Purl ( "pkg:cargo/[email protected] " . to_string ( ) ) 130- . validate_with_context ( ValidationContext :: default ( ) )
131- . expect ( "Error while validating" ) ;
114+ let validation_result =
Purl ( "pkg:cargo/[email protected] " . to_string ( ) ) . validate ( ) ; 132115
133116 assert_eq ! ( validation_result, ValidationResult :: Passed ) ;
134117 }
135118
136119 #[ test]
137120 fn invalid_purls_should_fail_validation ( ) {
138- let validation_result = Purl ( "invalid purl" . to_string ( ) )
139- . validate_with_context ( ValidationContext :: default ( ) )
140- . expect ( "Error while validating" ) ;
121+ let validation_result = Purl ( "invalid purl" . to_string ( ) ) . validate ( ) ;
141122
142123 assert_eq ! (
143124 validation_result,
@@ -153,18 +134,14 @@ mod test {
153134
154135 #[ test]
155136 fn valid_uris_should_pass_validation ( ) {
156- let validation_result = Uri ( "https://example.com" . to_string ( ) )
157- . validate_with_context ( ValidationContext :: default ( ) )
158- . expect ( "Error while validating" ) ;
137+ let validation_result = Uri ( "https://example.com" . to_string ( ) ) . validate ( ) ;
159138
160139 assert_eq ! ( validation_result, ValidationResult :: Passed ) ;
161140 }
162141
163142 #[ test]
164143 fn invalid_uris_should_fail_validation ( ) {
165- let validation_result = Uri ( "invalid uri" . to_string ( ) )
166- . validate_with_context ( ValidationContext :: default ( ) )
167- . expect ( "Error while validating" ) ;
144+ let validation_result = Uri ( "invalid uri" . to_string ( ) ) . validate ( ) ;
168145
169146 assert_eq ! (
170147 validation_result,
0 commit comments