use std::fmt;
#[derive(Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
CouldNotParseCertificate,
CouldNotParseCertificationRequest,
CouldNotParseKeyPair,
#[cfg(feature = "x509-parser")]
InvalidNameType,
InvalidAsn1String(InvalidAsn1String),
InvalidIpAddressOctetLength(usize),
KeyGenerationUnavailable,
#[cfg(feature = "x509-parser")]
UnsupportedExtension,
UnsupportedSignatureAlgorithm,
RingUnspecified,
RingKeyRejected(String),
Time,
#[cfg(feature = "pem")]
PemError(String),
RemoteKeyError,
UnsupportedInCsr,
InvalidCrlNextUpdate,
IssuerNotCrlSigner,
#[cfg(not(feature = "crypto"))]
MissingSerialNumber,
#[cfg(feature = "x509-parser")]
X509(String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::Error::*;
match self {
CouldNotParseCertificate => write!(f, "Could not parse certificate")?,
CouldNotParseCertificationRequest => write!(
f,
"Could not parse certificate signing \
request"
)?,
CouldNotParseKeyPair => write!(f, "Could not parse key pair")?,
#[cfg(feature = "x509-parser")]
InvalidNameType => write!(f, "Invalid subject alternative name type")?,
InvalidAsn1String(e) => write!(f, "{}", e)?,
InvalidIpAddressOctetLength(actual) => {
write!(f, "Invalid IP address octet length of {actual} bytes")?
},
KeyGenerationUnavailable => write!(
f,
"There is no support for generating \
keys for the given algorithm"
)?,
UnsupportedSignatureAlgorithm => write!(
f,
"The requested signature algorithm \
is not supported"
)?,
#[cfg(feature = "x509-parser")]
UnsupportedExtension => write!(f, "Unsupported extension requested in CSR")?,
RingUnspecified => write!(f, "Unspecified ring error")?,
RingKeyRejected(e) => write!(f, "Key rejected by ring: {}", e)?,
Time => write!(f, "Time error")?,
RemoteKeyError => write!(f, "Remote key error")?,
#[cfg(feature = "pem")]
PemError(e) => write!(f, "PEM error: {}", e)?,
UnsupportedInCsr => write!(f, "Certificate parameter unsupported in CSR")?,
InvalidCrlNextUpdate => write!(f, "Invalid CRL next update parameter")?,
IssuerNotCrlSigner => write!(
f,
"CRL issuer must specify no key usage, or key usage including cRLSign"
)?,
#[cfg(not(feature = "crypto"))]
MissingSerialNumber => write!(f, "A serial number must be specified")?,
#[cfg(feature = "x509-parser")]
X509(e) => write!(f, "X.509 parsing error: {e}")?,
};
Ok(())
}
}
impl std::error::Error for Error {}
#[derive(Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum InvalidAsn1String {
PrintableString(String),
UniversalString(String),
Ia5String(String),
TeletexString(String),
BmpString(String),
}
impl fmt::Display for InvalidAsn1String {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use InvalidAsn1String::*;
match self {
PrintableString(s) => write!(f, "Invalid PrintableString: '{}'", s)?,
Ia5String(s) => write!(f, "Invalid IA5String: '{}'", s)?,
BmpString(s) => write!(f, "Invalid BMPString: '{}'", s)?,
UniversalString(s) => write!(f, "Invalid UniversalString: '{}'", s)?,
TeletexString(s) => write!(f, "Invalid TeletexString: '{}'", s)?,
};
Ok(())
}
}
#[cfg(any(feature = "crypto", feature = "pem"))]
pub(crate) trait ExternalError<T>: Sized {
fn _err(self) -> Result<T, Error>;
}