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 string contains invalid characters
20 /// - A Base64 string has invalid padding
21 /// - A hex string contains non-hexadecimal characters
22 /// - A hex string has an odd length
23 InvalidInput,
24}
25
26#[cfg(feature = "std")]
27impl std::error::Error for Error {}
28
29impl Display for Error {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 match self {
32 Error::Overflow => write!(f, "Output buffer too small or calculation overflow"),
33 Error::InvalidInput => write!(f, "Invalid input for the given encoding"),
34 }
35 }
36}