1use std::fmt;
2
3#[derive(Debug, PartialEq, Eq)]
4#[non_exhaustive]
5pub enum Error {
7 CouldNotParseCertificate,
9 CouldNotParseCertificationRequest,
11 CouldNotParseKeyPair,
13 #[cfg(feature = "x509-parser")]
14 InvalidNameType,
16 InvalidAsn1String(InvalidAsn1String),
18 InvalidIpAddressOctetLength(usize),
20 KeyGenerationUnavailable,
23 #[cfg(feature = "x509-parser")]
24 UnsupportedExtension,
26 UnsupportedSignatureAlgorithm,
28 RingUnspecified,
30 RingKeyRejected(String),
32 Time,
34 #[cfg(feature = "pem")]
35 PemError(String),
37 RemoteKeyError,
39 UnsupportedInCsr,
41 InvalidCrlNextUpdate,
43 IssuerNotCrlSigner,
45 #[cfg(not(feature = "crypto"))]
46 MissingSerialNumber,
48 #[cfg(feature = "x509-parser")]
50 X509(String),
51}
52
53impl fmt::Display for Error {
54 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
55 use self::Error::*;
56 match self {
57 CouldNotParseCertificate => write!(f, "Could not parse certificate")?,
58 CouldNotParseCertificationRequest => write!(
59 f,
60 "Could not parse certificate signing \
61 request"
62 )?,
63 CouldNotParseKeyPair => write!(f, "Could not parse key pair")?,
64 #[cfg(feature = "x509-parser")]
65 InvalidNameType => write!(f, "Invalid subject alternative name type")?,
66 InvalidAsn1String(e) => write!(f, "{}", e)?,
67 InvalidIpAddressOctetLength(actual) => {
68 write!(f, "Invalid IP address octet length of {actual} bytes")?
69 },
70 KeyGenerationUnavailable => write!(
71 f,
72 "There is no support for generating \
73 keys for the given algorithm"
74 )?,
75 UnsupportedSignatureAlgorithm => write!(
76 f,
77 "The requested signature algorithm \
78 is not supported"
79 )?,
80 #[cfg(feature = "x509-parser")]
81 UnsupportedExtension => write!(f, "Unsupported extension requested in CSR")?,
82 RingUnspecified => write!(f, "Unspecified ring error")?,
83 RingKeyRejected(e) => write!(f, "Key rejected by ring: {}", e)?,
84
85 Time => write!(f, "Time error")?,
86 RemoteKeyError => write!(f, "Remote key error")?,
87 #[cfg(feature = "pem")]
88 PemError(e) => write!(f, "PEM error: {}", e)?,
89 UnsupportedInCsr => write!(f, "Certificate parameter unsupported in CSR")?,
90 InvalidCrlNextUpdate => write!(f, "Invalid CRL next update parameter")?,
91 IssuerNotCrlSigner => write!(
92 f,
93 "CRL issuer must specify no key usage, or key usage including cRLSign"
94 )?,
95 #[cfg(not(feature = "crypto"))]
96 MissingSerialNumber => write!(f, "A serial number must be specified")?,
97 #[cfg(feature = "x509-parser")]
98 X509(e) => write!(f, "X.509 parsing error: {e}")?,
99 };
100 Ok(())
101 }
102}
103
104impl std::error::Error for Error {}
105
106#[derive(Debug, PartialEq, Eq)]
108#[non_exhaustive]
109pub enum InvalidAsn1String {
110 PrintableString(String),
112 UniversalString(String),
114 Ia5String(String),
116 TeletexString(String),
118 BmpString(String),
120}
121
122impl fmt::Display for InvalidAsn1String {
123 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
124 use InvalidAsn1String::*;
125 match self {
126 PrintableString(s) => write!(f, "Invalid PrintableString: '{}'", s)?,
127 Ia5String(s) => write!(f, "Invalid IA5String: '{}'", s)?,
128 BmpString(s) => write!(f, "Invalid BMPString: '{}'", s)?,
129 UniversalString(s) => write!(f, "Invalid UniversalString: '{}'", s)?,
130 TeletexString(s) => write!(f, "Invalid TeletexString: '{}'", s)?,
131 };
132 Ok(())
133 }
134}
135
136#[cfg(any(feature = "crypto", feature = "pem"))]
141pub(crate) trait ExternalError<T>: Sized {
142 fn _err(self) -> Result<T, Error>;
143}