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 ModulusTooLarge,
45
46 PublicExponentTooSmall,
48
49 PublicExponentTooLarge,
51
52 Pkcs1(pkcs1::Error),
54
55 Pkcs8(pkcs8::Error),
57
58 Internal,
60
61 LabelTooLong,
63}
64
65#[cfg(feature = "std")]
66impl std::error::Error for Error {}
67impl core::fmt::Display for Error {
68 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
69 match self {
70 Error::InvalidPaddingScheme => write!(f, "invalid padding scheme"),
71 Error::Decryption => write!(f, "decryption error"),
72 Error::Verification => write!(f, "verification error"),
73 Error::MessageTooLong => write!(f, "message too long"),
74 Error::InputNotHashed => write!(f, "input must be hashed"),
75 Error::NprimesTooSmall => write!(f, "nprimes must be >= 2"),
76 Error::TooFewPrimes => {
77 write!(f, "too few primes of given length to generate an RSA key")
78 }
79 Error::InvalidPrime => write!(f, "invalid prime value"),
80 Error::InvalidModulus => write!(f, "invalid modulus"),
81 Error::InvalidExponent => write!(f, "invalid exponent"),
82 Error::InvalidCoefficient => write!(f, "invalid coefficient"),
83 Error::ModulusTooLarge => write!(f, "modulus too large"),
84 Error::PublicExponentTooSmall => write!(f, "public exponent too small"),
85 Error::PublicExponentTooLarge => write!(f, "public exponent too large"),
86 Error::Pkcs1(err) => write!(f, "{}", err),
87 Error::Pkcs8(err) => write!(f, "{}", err),
88 Error::Internal => write!(f, "internal error"),
89 Error::LabelTooLong => write!(f, "label too long"),
90 }
91 }
92}
93
94impl From<pkcs1::Error> for Error {
95 fn from(err: pkcs1::Error) -> Error {
96 Error::Pkcs1(err)
97 }
98}
99
100impl From<pkcs8::Error> for Error {
101 fn from(err: pkcs8::Error) -> Error {
102 Error::Pkcs8(err)
103 }
104}
105
106#[cfg(feature = "std")]
107impl From<Error> for signature::Error {
108 fn from(err: Error) -> Self {
109 Self::from_source(err)
110 }
111}
112
113#[cfg(not(feature = "std"))]
114impl From<Error> for signature::Error {
115 fn from(_err: Error) -> Self {
116 Self::new()
117 }
118}