use core::fmt;
#[cfg(feature = "pem")]
use der::pem;
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum Error {
#[cfg(feature = "der")]
Asn1(der::Error),
Crypto,
#[cfg(feature = "pkcs8")]
Pkcs8(pkcs8::Error),
PointEncoding,
Version,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
#[cfg(feature = "der")]
Error::Asn1(err) => write!(f, "SEC1 ASN.1 error: {}", err),
Error::Crypto => f.write_str("SEC1 cryptographic error"),
#[cfg(feature = "pkcs8")]
Error::Pkcs8(err) => write!(f, "{}", err),
Error::PointEncoding => f.write_str("elliptic curve point encoding error"),
Error::Version => f.write_str("SEC1 version error"),
}
}
}
#[cfg(feature = "der")]
impl From<der::Error> for Error {
fn from(err: der::Error) -> Error {
Error::Asn1(err)
}
}
#[cfg(feature = "pem")]
impl From<pem::Error> for Error {
fn from(err: pem::Error) -> Error {
der::Error::from(err).into()
}
}
#[cfg(feature = "pkcs8")]
impl From<pkcs8::Error> for Error {
fn from(err: pkcs8::Error) -> Error {
Error::Pkcs8(err)
}
}
#[cfg(feature = "pkcs8")]
impl From<pkcs8::spki::Error> for Error {
fn from(err: pkcs8::spki::Error) -> Error {
Error::Pkcs8(pkcs8::Error::PublicKey(err))
}
}
#[cfg(feature = "std")]
impl std::error::Error for Error {}