1#[derive(Debug)]
3pub enum RsaError {
4 IntegerTooLarge,
5 OctetStringEmpty,
6 MessageRepresentativeOutOfRange,
7 MessageTooLong,
8 InvalidBufferSize,
9 InvalidKeySize,
10 MaskTooLong,
11 DecryptionError,
12 EncodingError,
13 InvalidSignature,
14 ArithmeticError,
15 ImportError,
16 ExportError,
17 ParamsError,
18 RandomGeneratorFailure,
19}
20
21impl std::fmt::Display for RsaError {
22 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23 let message = match self {
24 RsaError::IntegerTooLarge => "integer too large",
25 RsaError::OctetStringEmpty => "octet string empty",
26 RsaError::MessageRepresentativeOutOfRange => "message representative out of range",
27 RsaError::MessageTooLong => "message too long",
28 RsaError::InvalidKeySize => "invalid key size",
29 RsaError::InvalidBufferSize => "invalid buffer size",
30 RsaError::MaskTooLong => "mask too long",
31 RsaError::DecryptionError => "decryption error",
32 RsaError::EncodingError => "encoding error",
33 RsaError::InvalidSignature => "invalid signature",
34 RsaError::ArithmeticError => "arithmetic error",
35 RsaError::ImportError => "import error",
36 RsaError::ExportError => "export error",
37 RsaError::ParamsError => "params error",
38 RsaError::RandomGeneratorFailure => "random generator failure",
39 };
40
41 f.write_fmt(format_args!("{}", message))
42 }
43}
44
45impl std::error::Error for RsaError {}