Skip to main content

bouncycastle_core_interface/
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 MACError {
32    GenericError(&'static str),
33    HashError(HashError),
34    InvalidLength(&'static str),
35    InvalidState(&'static str),
36    KeyMaterialError(KeyMaterialError),
37}
38
39#[derive(Debug)]
40pub enum RNGError {
41    GenericError(&'static str),
42
43    /// Attempting to extract output before the RNG has been seeded.
44    Uninitialized,
45
46    /// The RNG has been seeded, but not sufficiently to support the requested generation operation.
47    /// This includes uses in SP 800-90A mode where more output is requested than the security strength
48    /// to which the RNG has been initialized.
49    InsufficientSeedEntropy,
50
51    /// Indicates that the RNG cannot produce any more output until it has been reseeded with fresh entropy.
52    ReseedRequired,
53
54    KeyMaterialError(KeyMaterialError),
55}
56
57#[derive(Debug)]
58pub enum SignatureError {
59    GenericError(&'static str),
60    ConsistencyCheckFailed(),
61    EncodingError(&'static str),
62    DecodingError(&'static str),
63    KeyGenError(&'static str),
64    LengthError(&'static str),
65    RNGError(RNGError),
66    SignatureVerificationFailed,
67}
68
69
70
71
72/*** Promotion functions ***/
73impl From<KeyMaterialError> for HashError {
74    fn from(e: KeyMaterialError) -> HashError {
75        Self::KeyMaterialError(e)
76    }
77}
78
79impl From<HashError> for KDFError {
80    fn from(e: HashError) -> KDFError {
81        Self::HashError(e)
82    }
83}
84
85impl From<MACError> for KDFError {
86    fn from(e: MACError) -> KDFError {
87        Self::MACError(e)
88    }
89}
90
91impl From<KeyMaterialError> for KDFError {
92    fn from(e: KeyMaterialError) -> KDFError {
93        Self::KeyMaterialError(e)
94    }
95}
96
97impl From<KeyMaterialError> for MACError {
98    fn from(e: KeyMaterialError) -> MACError {
99        Self::KeyMaterialError(e)
100    }
101}
102
103impl From<HashError> for MACError {
104    fn from(e: HashError) -> MACError {
105        Self::HashError(e)
106    }
107}
108
109impl From<KeyMaterialError> for RNGError {
110    fn from(e: KeyMaterialError) -> RNGError {
111        Self::KeyMaterialError(e)
112    }
113}
114
115impl From<RNGError> for SignatureError {
116    fn from(e: RNGError) -> SignatureError { Self::RNGError(e) }
117}