use core::fmt;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum StreamError {
NotInitialised,
BufferTooShort,
MaxBytesExceeded,
CounterExhausted,
}
impl fmt::Display for StreamError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NotInitialised => f.write_str("stream cipher is not initialised"),
Self::BufferTooShort => f.write_str("stream cipher output buffer is too short"),
Self::MaxBytesExceeded => f.write_str("stream cipher byte limit exceeded"),
Self::CounterExhausted => f.write_str("stream cipher counter exhausted"),
}
}
}
impl core::error::Error for StreamError {}
#[cfg(test)]
mod tests {
extern crate std;
use std::format;
use super::StreamError;
#[test]
fn each_variant_has_a_message() {
for error in [
StreamError::NotInitialised,
StreamError::BufferTooShort,
StreamError::MaxBytesExceeded,
StreamError::CounterExhausted,
] {
assert!(!format!("{error}").is_empty());
}
}
}