Skip to content

Commit 0651f72

Browse files
committed
error: add is_fatal helper, use in verify_cert
This commit adds a method to `Error` for testing whether an error should be considered fatal, e.g. should stop any further path building progress. The existing consideration of fatal errors in `loop_while_non_fatal_error` is updated to use the `is_fatal` fn. Having this in a central place means we can avoid duplicating the match arms in multiple places, where they are likely to fall out-of-sync.
1 parent 0598dd2 commit 0651f72

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/error.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ pub enum Error {
115115
UnsupportedSignatureAlgorithmForPublicKey,
116116
}
117117

118+
impl Error {
119+
/// Returns true for errors that should be considered fatal during path building. Errors of
120+
/// this class should halt any further path building and be returned immediately.
121+
#[inline]
122+
pub(crate) fn is_fatal(&self) -> bool {
123+
matches!(
124+
self,
125+
Error::MaximumSignatureChecksExceeded
126+
| Error::MaximumPathBuildCallsExceeded
127+
| Error::MaximumNameConstraintComparisonsExceeded
128+
)
129+
}
130+
}
131+
118132
impl fmt::Display for Error {
119133
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
120134
write!(f, "{:?}", self)

src/verify_cert.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,9 @@ where
464464
// If the error is not fatal, then keep going.
465465
match f(v) {
466466
Ok(()) => return Ok(()),
467-
err @ Err(Error::MaximumSignatureChecksExceeded)
468-
| err @ Err(Error::MaximumPathBuildCallsExceeded)
469-
| err @ Err(Error::MaximumNameConstraintComparisonsExceeded) => return err,
467+
// Fatal errors should halt further looping.
468+
res @ Err(err) if err.is_fatal() => return res,
469+
// Non-fatal errors should allow looping to continue.
470470
_ => {}
471471
}
472472
}

0 commit comments

Comments
 (0)