@@ -53,7 +53,7 @@ pub fn build_chain(
5353
5454 // TODO: revocation.
5555
56- match loop_while_non_fatal_error ( trust_anchors, |trust_anchor : & TrustAnchor | {
56+ let found_trust_anchor = find_ok ( trust_anchors, |trust_anchor : & TrustAnchor | {
5757 let trust_anchor_subject = untrusted:: Input :: from ( trust_anchor. subject ) ;
5858 if cert. issuer != trust_anchor_subject {
5959 return Err ( Error :: UnknownIssuer ) ;
@@ -72,16 +72,13 @@ pub fn build_chain(
7272 check_signatures ( supported_sig_algs, cert, trust_anchor_spki) ?;
7373
7474 Ok ( ( ) )
75- } ) {
76- Ok ( ( ) ) => {
77- return Ok ( ( ) ) ;
78- }
79- Err ( ..) => {
80- // If the error is not fatal, then keep going.
81- }
75+ } ) ;
76+
77+ if found_trust_anchor {
78+ return Ok ( ( ) ) ;
8279 }
8380
84- loop_while_non_fatal_error ( intermediate_certs, |cert_der| {
81+ let found_chain = find_ok ( intermediate_certs, |cert_der| {
8582 let potential_issuer =
8683 cert:: parse_cert ( untrusted:: Input :: from ( * cert_der) , EndEntityOrCA :: CA ( & cert) ) ?;
8784
@@ -125,7 +122,13 @@ pub fn build_chain(
125122 time,
126123 next_sub_ca_count,
127124 )
128- } )
125+ } ) ;
126+
127+ if found_chain {
128+ return Ok ( ( ) ) ;
129+ }
130+
131+ return Err ( Error :: UnknownIssuer ) ;
129132}
130133
131134fn check_signatures (
@@ -331,22 +334,6 @@ fn check_eku(
331334 }
332335}
333336
334- fn loop_while_non_fatal_error < V > (
335- values : V ,
336- f : impl Fn ( V :: Item ) -> Result < ( ) , Error > ,
337- ) -> Result < ( ) , Error >
338- where
339- V : IntoIterator ,
340- {
341- for v in values {
342- match f ( v) {
343- Ok ( ( ) ) => {
344- return Ok ( ( ) ) ;
345- }
346- Err ( ..) => {
347- // If the error is not fatal, then keep going.
348- }
349- }
350- }
351- Err ( Error :: UnknownIssuer )
337+ fn find_ok < I > ( values : impl IntoIterator < Item = I > , f : impl Fn ( I ) -> Result < ( ) , Error > ) -> bool {
338+ values. into_iter ( ) . map ( f) . find ( |r| r. is_ok ( ) ) . is_some ( )
352339}
0 commit comments