Skip to main content

bouncycastle_core/
errors.rs

1#[derive(Debug)]
2pub enum HashError {
3    GenericError(&'static str),
4    InvalidLength(&'static str),
5    InvalidState(&'static str),
6    InvalidInput(&'static str),
7    KeyMaterialError(KeyMaterialError),
8}
9
10#[derive(Debug)]
11pub enum KeyMaterialError {
12    ActingOnZeroizedKey,
13    GenericError(&'static str),
14    HazardousOperationNotPermitted,
15    InputDataLongerThanKeyCapacity,
16    InvalidKeyType(&'static str),
17    InvalidLength,
18    SecurityStrength(&'static str),
19}
20
21#[derive(Debug)]
22pub enum KDFError {
23    GenericError(&'static str),
24    HashError(HashError),
25    InvalidLength(&'static str),
26    KeyMaterialError(KeyMaterialError),
27    MACError(MACError),
28}
29
30#[derive(Debug)]
31pub enum KEMError {
32    GenericError(&'static str),
33    ConsistencyCheckFailed(&'static str),
34    EncodingError(&'static str),
35    DecapsulationFailed,
36    DecodingError(&'static str),
37    KeyGenError(&'static str),
38    KeyMaterialError(KeyMaterialError),
39    LengthError(&'static str),
40    RNGError(RNGError),
41}
42
43#[derive(Debug)]
44pub enum MACError {
45    GenericError(&'static str),
46    HashError(HashError),
47    InvalidLength(&'static str),
48    InvalidState(&'static str),
49    KeyMaterialError(KeyMaterialError),
50}
51
52#[derive(Debug)]
53pub enum RNGError {
54    GenericError(&'static str),
55
56    /// Attempting to extract output before the RNG has been seeded.
57    Uninitialized,
58
59    /// The RNG has been seeded, but not sufficiently to support the requested generation operation.
60    /// This includes uses in SP 800-90A mode where more output is requested than the security strength
61    /// to which the RNG has been initialized.
62    InsufficientSeedEntropy,
63
64    /// Indicates that the RNG cannot produce any more output until it has been reseeded with fresh entropy.
65    ReseedRequired,
66
67    KeyMaterialError(KeyMaterialError),
68}
69
70#[derive(Debug)]
71pub enum SignatureError {
72    GenericError(&'static str),
73    ConsistencyCheckFailed(),
74    EncodingError(&'static str),
75    DecodingError(&'static str),
76    KeyGenError(&'static str),
77    KeyMaterialError(KeyMaterialError),
78    LengthError(&'static str),
79    SignatureVerificationFailed,
80    RNGError(RNGError),
81}
82
83
84
85
86/*** Promotion functions ***/
87impl From<KeyMaterialError> for HashError {
88    fn from(e: KeyMaterialError) -> HashError {
89        Self::KeyMaterialError(e)
90    }
91}
92
93impl From<HashError> for KDFError {
94    fn from(e: HashError) -> KDFError {
95        Self::HashError(e)
96    }
97}
98
99impl From<MACError> for KDFError {
100    fn from(e: MACError) -> KDFError {
101        Self::MACError(e)
102    }
103}
104
105impl From<KeyMaterialError> for KDFError {
106    fn from(e: KeyMaterialError) -> KDFError {
107        Self::KeyMaterialError(e)
108    }
109}
110
111impl From<KeyMaterialError> for KEMError {
112    fn from(e: KeyMaterialError) -> KEMError {
113        Self::KeyMaterialError(e)
114    }
115}
116
117impl From<RNGError> for KEMError {
118    fn from(e: RNGError) -> KEMError { Self::RNGError(e) }
119}
120
121impl From<KeyMaterialError> for MACError {
122    fn from(e: KeyMaterialError) -> MACError {
123        Self::KeyMaterialError(e)
124    }
125}
126
127impl From<HashError> for MACError {
128    fn from(e: HashError) -> MACError {
129        Self::HashError(e)
130    }
131}
132
133impl From<KeyMaterialError> for RNGError {
134    fn from(e: KeyMaterialError) -> RNGError {
135        Self::KeyMaterialError(e)
136    }
137}
138
139impl From<KeyMaterialError> for SignatureError {
140    fn from(e: KeyMaterialError) -> SignatureError {
141        Self::KeyMaterialError(e)
142    }
143}
144
145impl From<RNGError> for SignatureError {
146    fn from(e: RNGError) -> SignatureError { Self::RNGError(e) }
147}
148