use std::error::Error;
use std::fmt;
#[derive(Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum RcgenError {
CouldNotParseCertificate,
CouldNotParseCertificationRequest,
CouldNotParseKeyPair,
#[cfg(feature = "x509-parser")]
InvalidNameType,
InvalidIpAddressOctetLength(usize),
KeyGenerationUnavailable,
#[cfg(feature = "x509-parser")]
UnsupportedExtension,
UnsupportedSignatureAlgorithm,
RingUnspecified,
RingKeyRejected(&'static str),
CertificateKeyPairMismatch,
Time,
#[cfg(feature = "pem")]
PemError(pem::PemError),
RemoteKeyError,
UnsupportedInCsr,
InvalidCrlNextUpdate,
IssuerNotCrlSigner,
}
impl fmt::Display for RcgenError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::RcgenError::*;
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")?,
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)?,
CertificateKeyPairMismatch => write!(
f,
"The provided certificate's signature \
algorithm is incompatible with the given key pair"
)?,
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"
)?,
};
Ok(())
}
}
impl Error for RcgenError {}
impl From<ring::error::Unspecified> for RcgenError {
fn from(_unspecified: ring::error::Unspecified) -> Self {
RcgenError::RingUnspecified
}
}
impl From<ring::error::KeyRejected> for RcgenError {
fn from(err: ring::error::KeyRejected) -> Self {
RcgenError::RingKeyRejected(err.description_())
}
}
#[cfg(feature = "pem")]
impl From<pem::PemError> for RcgenError {
fn from(e: pem::PemError) -> Self {
RcgenError::PemError(e)
}
}