Skip to main content

ntex_tls/x509/
error.rs

1use std::fmt;
2
3/// Error returned by x509 operations.
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum Error {
6    /// Input is not valid DER encoded X.509 data.
7    InvalidDer(String),
8    /// Input is not valid PEM.
9    InvalidPem(String),
10    /// PKCS#12 / key material could not be loaded.
11    InvalidIdentity(String),
12    /// Requested item (certificate in a store) was not found.
13    NotFound(String),
14    /// Crypto backend failure.
15    Backend(String),
16    /// Operation is not supported (by this platform or for this key type).
17    Unsupported(String),
18}
19
20impl fmt::Display for Error {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        match self {
23            Error::InvalidDer(e) => write!(f, "Invalid DER certificate: {e}"),
24            Error::InvalidPem(e) => write!(f, "Invalid PEM certificate: {e}"),
25            Error::InvalidIdentity(e) => write!(f, "Invalid identity: {e}"),
26            Error::NotFound(e) => write!(f, "Not found: {e}"),
27            Error::Backend(e) => write!(f, "Crypto backend error: {e}"),
28            Error::Unsupported(e) => write!(f, "Unsupported: {e}"),
29        }
30    }
31}
32
33impl std::error::Error for Error {}