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