spiffe/cert/
errors.rs

1//! Type error for X.509 certificate parsing and validations.
2
3use asn1::{ASN1DecodeErr, ASN1EncodeErr};
4use x509_parser::error::X509Error;
5
6/// An error that may arise parsing and validating X.509 certificates.
7#[derive(Debug, thiserror::Error, PartialEq)]
8#[non_exhaustive]
9pub enum CertificateError {
10    /// An X.509 extension cannot be found.
11    #[error("X.509 extension is missing: {0}")]
12    MissingX509Extension(String),
13
14    /// Unexpected X.509 extension encountered.
15    #[error("unexpected X.509 extension: {0}")]
16    UnexpectedExtension(String),
17
18    /// Error returned by the ASN.1/DER processing library.
19    #[error("failed decoding chain of DER certificates")]
20    ChainDecode(#[from] ASN1DecodeErr),
21
22    /// Error returned by the ASN.1/DER processing library.
23    #[error("failed parsing DER certificate")]
24    ParseDer(#[from] ASN1EncodeErr),
25
26    /// Error returned by the X.509 parsing library.
27    #[error("failed parsing X.509 certificate")]
28    ParseX509Certificate(#[from] X509Error),
29}
30
31/// An error that may arise decoding private keys.
32#[derive(Debug, thiserror::Error, PartialEq)]
33#[non_exhaustive]
34pub enum PrivateKeyError {
35    /// Error returned by the pkcs#8 private key decoding library.
36    #[error("failed decoding PKCS#8 private key")]
37    DecodePkcs8(pkcs8::Error),
38}