Skip to main content

structured_pkix/path/
error.rs

1//! Failures of path processing and the caller's injected capabilities.
2
3use core::fmt;
4
5/// A path operation that could not finish, preserving the originating cause.
6///
7/// A callback may report policy, provider or resource failures in its own error
8/// type. These are distinct from a completed signature check answering `No` or
9/// `Unsupported`, or a recognizer answering `false`. This wrapper allocates no
10/// storage; owned data inside a callback error remains the callback's accounting
11/// responsibility.
12#[derive(Debug)]
13pub enum BuildError<V, R> {
14    /// Shared processing failed, including a located resource refusal.
15    Processing(crate::Error),
16    /// The injected signature verifier failed to execute its check.
17    Verification(V),
18    /// The injected extension recognizer failed to execute its query.
19    Recognition(R),
20}
21
22/// Result of path processing with the injected callbacks' original error types.
23pub type BuildResult<T, V, R> = core::result::Result<T, BuildError<V, R>>;
24
25impl<V, R> From<crate::Error> for BuildError<V, R> {
26    fn from(error: crate::Error) -> Self {
27        Self::Processing(error)
28    }
29}
30
31impl<V, R> From<crate::error::CallbackError<R>> for BuildError<V, R> {
32    fn from(error: crate::error::CallbackError<R>) -> Self {
33        match error {
34            crate::error::CallbackError::Processing(error) => Self::Processing(error),
35            crate::error::CallbackError::Callback(error) => Self::Recognition(error),
36        }
37    }
38}
39
40impl<V: fmt::Display, R: fmt::Display> fmt::Display for BuildError<V, R> {
41    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42        match self {
43            Self::Processing(error) => error.fmt(f),
44            Self::Verification(error) => write!(f, "signature verifier: {error}"),
45            Self::Recognition(error) => write!(f, "extension recognizer: {error}"),
46        }
47    }
48}
49
50#[cfg(feature = "std")]
51impl<V: std::error::Error + 'static, R: std::error::Error + 'static> std::error::Error
52    for BuildError<V, R>
53{
54    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
55        match self {
56            Self::Processing(error) => Some(error),
57            Self::Verification(error) => Some(error),
58            Self::Recognition(error) => Some(error),
59        }
60    }
61}