pub type Result<T> = core::result::Result<T, Error>;
#[derive(Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum Error {
InvalidPaddingScheme,
Decryption,
Verification,
MessageTooLong,
InputNotHashed,
NprimesTooSmall,
TooFewPrimes,
InvalidPrime,
InvalidModulus,
InvalidExponent,
InvalidCoefficient,
ModulusTooSmall,
ModulusTooLarge,
PublicExponentTooSmall,
PublicExponentTooLarge,
#[cfg(feature = "encoding")]
Pkcs1(pkcs1::Error),
#[cfg(feature = "encoding")]
Pkcs8(pkcs8::Error),
Internal,
LabelTooLong,
InvalidPadLen,
InvalidArguments,
Decode(crypto_bigint::DecodeError),
Rng,
}
impl core::error::Error for Error {}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
Error::InvalidPaddingScheme => write!(f, "invalid padding scheme"),
Error::Decryption => write!(f, "decryption error"),
Error::Verification => write!(f, "verification error"),
Error::MessageTooLong => write!(f, "message too long"),
Error::InputNotHashed => write!(f, "input must be hashed"),
Error::NprimesTooSmall => write!(f, "nprimes must be >= 2"),
Error::TooFewPrimes => {
write!(f, "too few primes of given length to generate an RSA key")
}
Error::InvalidPrime => write!(f, "invalid prime value"),
Error::InvalidModulus => write!(f, "invalid modulus"),
Error::InvalidExponent => write!(f, "invalid exponent"),
Error::InvalidCoefficient => write!(f, "invalid coefficient"),
Error::ModulusTooSmall => write!(f, "modulus too small"),
Error::ModulusTooLarge => write!(f, "modulus too large"),
Error::PublicExponentTooSmall => write!(f, "public exponent too small"),
Error::PublicExponentTooLarge => write!(f, "public exponent too large"),
#[cfg(feature = "encoding")]
Error::Pkcs1(err) => write!(f, "{}", err),
#[cfg(feature = "encoding")]
Error::Pkcs8(err) => write!(f, "{}", err),
Error::Internal => write!(f, "internal error"),
Error::LabelTooLong => write!(f, "label too long"),
Error::InvalidPadLen => write!(f, "invalid padding length"),
Error::InvalidArguments => write!(f, "invalid arguments"),
Error::Decode(err) => write!(f, "{:?}", err),
Error::Rng => write!(f, "rng error"),
}
}
}
#[cfg(feature = "encoding")]
impl From<pkcs1::Error> for Error {
fn from(err: pkcs1::Error) -> Error {
Error::Pkcs1(err)
}
}
#[cfg(feature = "encoding")]
impl From<pkcs8::Error> for Error {
fn from(err: pkcs8::Error) -> Error {
Error::Pkcs8(err)
}
}
impl From<crypto_bigint::DecodeError> for Error {
fn from(err: crypto_bigint::DecodeError) -> Error {
Error::Decode(err)
}
}
impl From<Error> for signature::Error {
fn from(err: Error) -> Self {
Self::from_source(err)
}
}