aes_kw/
error.rs

1use core::fmt;
2
3/// Result type with the `aes-kw` crate's [`Error`].
4pub type Result<T> = core::result::Result<T, Error>;
5
6/// Errors emitted from the wrap and unwrap operations.
7#[derive(Debug)]
8pub enum Error {
9    /// Input data length invalid.
10    InvalidDataSize,
11
12    /// Invalid KEK size.
13    InvalidKekSize {
14        /// KEK size provided in bytes (expected 8, 12, or 24).
15        size: usize,
16    },
17
18    /// Output buffer size invalid.
19    InvalidOutputSize {
20        /// Expected size in bytes.
21        expected: usize,
22    },
23
24    /// Integrity check did not pass.
25    IntegrityCheckFailed,
26}
27
28impl fmt::Display for Error {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        match self {
31            Error::InvalidDataSize => write!(f, "data must be a multiple of 64 bits for AES-KW and less than 2^32 bytes for AES-KWP"),
32            Error::InvalidKekSize { size } => {
33                write!(f, "invalid AES KEK size: {}", size)
34            }
35            Error::InvalidOutputSize { expected } => {
36                write!(f, "invalid output buffer size: expected {}", expected)
37            }
38            Error::IntegrityCheckFailed => {
39                write!(f, "integrity check failed")
40            }
41        }
42    }
43}
44
45#[cfg(feature = "std")]
46impl std::error::Error for Error {}