use core::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DecodeError {
InvalidLength,
InvalidByte {
offset: usize,
byte: u8,
},
InvalidPadding {
offset: usize,
},
OutputSliceTooSmall {
expected: usize,
actual: usize,
},
}
impl fmt::Display for DecodeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Self::InvalidLength => write!(f, "Invalid base64 input length"),
Self::InvalidByte { offset, byte } => {
write!(f, "Invalid base64 byte {:#04x} at index {}", byte, offset)
}
Self::InvalidPadding { offset } => {
write!(f, "Invalid padding character at index {}", offset)
}
Self::OutputSliceTooSmall { expected, actual } => {
write!(
f,
"Destination buffer too small: expected at least {} bytes, got {}",
expected, actual
)
}
}
}
}
impl core::error::Error for DecodeError {}