1pub type Result<T> = core::result::Result<T, Error>;
5
6#[derive(Debug, Eq, PartialEq)]
8#[non_exhaustive]
9pub enum Error {
10 InvalidPaddingScheme,
12
13 Decryption,
15
16 Verification,
18
19 MessageTooLong,
21
22 InputNotHashed,
24
25 NprimesTooSmall,
27
28 TooFewPrimes,
30
31 InvalidPrime,
33
34 InvalidModulus,
36
37 InvalidExponent,
39
40 InvalidCoefficient,
42
43 ModulusTooSmall,
45
46 ModulusTooLarge,
48
49 PublicExponentTooSmall,
51
52 PublicExponentTooLarge,
54
55 #[cfg(feature = "encoding")]
57 Pkcs1(pkcs1::Error),
58
59 #[cfg(feature = "encoding")]
61 Pkcs8(pkcs8::Error),
62
63 Internal,
65
66 LabelTooLong,
68
69 InvalidPadLen,
71
72 InvalidArguments,
74
75 Decode(crypto_bigint::DecodeError),
77
78 Rng,
80}
81
82impl core::error::Error for Error {}
83
84impl core::fmt::Display for Error {
85 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
86 match self {
87 Error::InvalidPaddingScheme => write!(f, "invalid padding scheme"),
88 Error::Decryption => write!(f, "decryption error"),
89 Error::Verification => write!(f, "verification error"),
90 Error::MessageTooLong => write!(f, "message too long"),
91 Error::InputNotHashed => write!(f, "input must be hashed"),
92 Error::NprimesTooSmall => write!(f, "nprimes must be >= 2"),
93 Error::TooFewPrimes => {
94 write!(f, "too few primes of given length to generate an RSA key")
95 }
96 Error::InvalidPrime => write!(f, "invalid prime value"),
97 Error::InvalidModulus => write!(f, "invalid modulus"),
98 Error::InvalidExponent => write!(f, "invalid exponent"),
99 Error::InvalidCoefficient => write!(f, "invalid coefficient"),
100 Error::ModulusTooSmall => write!(f, "modulus too small"),
101 Error::ModulusTooLarge => write!(f, "modulus too large"),
102 Error::PublicExponentTooSmall => write!(f, "public exponent too small"),
103 Error::PublicExponentTooLarge => write!(f, "public exponent too large"),
104 #[cfg(feature = "encoding")]
105 Error::Pkcs1(err) => write!(f, "{}", err),
106 #[cfg(feature = "encoding")]
107 Error::Pkcs8(err) => write!(f, "{}", err),
108 Error::Internal => write!(f, "internal error"),
109 Error::LabelTooLong => write!(f, "label too long"),
110 Error::InvalidPadLen => write!(f, "invalid padding length"),
111 Error::InvalidArguments => write!(f, "invalid arguments"),
112 Error::Decode(err) => write!(f, "{:?}", err),
113 Error::Rng => write!(f, "rng error"),
114 }
115 }
116}
117
118#[cfg(feature = "encoding")]
119impl From<pkcs1::Error> for Error {
120 fn from(err: pkcs1::Error) -> Error {
121 Error::Pkcs1(err)
122 }
123}
124
125#[cfg(feature = "encoding")]
126impl From<pkcs8::Error> for Error {
127 fn from(err: pkcs8::Error) -> Error {
128 Error::Pkcs8(err)
129 }
130}
131impl From<crypto_bigint::DecodeError> for Error {
132 fn from(err: crypto_bigint::DecodeError) -> Error {
133 Error::Decode(err)
134 }
135}
136
137impl From<Error> for signature::Error {
138 fn from(err: Error) -> Self {
139 Self::from_source(err)
140 }
141}