Skip to main content

libcrux_blake2/impl_hacl/
error.rs

1extern crate alloc;
2
3/// Indicates an error has occurred
4#[derive(Debug)]
5pub enum Error {
6    /// The used key length is invalid.
7    InvalidKeyLength,
8    /// The used digest length is invalid.
9    InvalidDigestLength,
10    ///The maximum input length is exceeded.
11    MaximumLengthExceeded,
12    /// The maximum chunk length is exceeded.
13    InvalidChunkLength,
14    /// An unexpected error has occurred.
15    Unexpected,
16}
17
18impl alloc::fmt::Display for Error {
19    fn fmt(&self, f: &mut alloc::fmt::Formatter<'_>) -> alloc::fmt::Result {
20        let text = match self {
21            Error::InvalidKeyLength => "The used key length is invalid.",
22            Error::InvalidDigestLength => "The used digest length is invalid.",
23            Error::MaximumLengthExceeded => "The maximum input length is exceeded.",
24            Error::InvalidChunkLength => "The maximum chunk length is exceeded.",
25            Error::Unexpected => "An unexpected error has occurred.",
26        };
27
28        write!(f, "{text}")
29    }
30}
31
32#[cfg(not(feature = "std"))]
33impl core::error::Error for Error {}
34
35#[cfg(feature = "std")]
36impl std::error::Error for Error {}