ct_codecs/error.rs
1use core::fmt::{self, Display};
2
3/// Error type for ct-codecs operations.
4///
5/// This enum represents the possible error conditions that can occur
6/// during encoding and decoding operations.
7#[derive(Debug, Copy, Clone, Eq, PartialEq)]
8pub enum Error {
9 /// The provided output buffer would be too small to hold the result.
10 ///
11 /// This error occurs when:
12 /// - The output buffer passed to an encode/decode function is too small
13 /// - A calculation would result in an integer overflow
14 Overflow,
15
16 /// The input isn't valid for the given encoding.
17 ///
18 /// This error occurs when:
19 /// - A Base64 or Base32 string contains invalid characters
20 /// - A Base64 or Base32 string has invalid padding
21 /// - An encoded string is non-canonical (e.g. non-zero padding bits)
22 /// - A hex string contains non-hexadecimal characters
23 /// - A hex string has an odd length
24 InvalidInput,
25}
26
27#[cfg(feature = "std")]
28impl std::error::Error for Error {}
29
30impl Display for Error {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 match self {
33 Error::Overflow => write!(f, "Output buffer too small or calculation overflow"),
34 Error::InvalidInput => write!(f, "Invalid input for the given encoding"),
35 }
36 }
37}