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/*** Promotion functions ***/
58impl From<KeyMaterialError> for HashError {
59    fn from(e: KeyMaterialError) -> HashError {
60        Self::KeyMaterialError(e)
61    }
62}
63
64impl From<HashError> for KDFError {
65    fn from(e: HashError) -> KDFError {
66        Self::HashError(e)
67    }
68}
69
70impl From<MACError> for KDFError {
71    fn from(e: MACError) -> KDFError {
72        Self::MACError(e)
73    }
74}
75
76impl From<KeyMaterialError> for KDFError {
77    fn from(e: KeyMaterialError) -> KDFError {
78        Self::KeyMaterialError(e)
79    }
80}
81
82impl From<KeyMaterialError> for MACError {
83    fn from(e: KeyMaterialError) -> MACError {
84        Self::KeyMaterialError(e)
85    }
86}
87
88impl From<HashError> for MACError {
89    fn from(e: HashError) -> MACError {
90        Self::HashError(e)
91    }
92}
93
94impl From<KeyMaterialError> for RNGError {
95    fn from(e: KeyMaterialError) -> RNGError {
96        Self::KeyMaterialError(e)
97    }
98}