cipher/
errors.rs

1//! Error types.
2
3use core::fmt;
4
5/// The error type returned when stream cipher has reached the end of a keystream.
6#[derive(Copy, Clone, Debug)]
7pub struct LoopError;
8
9impl fmt::Display for LoopError {
10    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
11        f.write_str("Loop Error")
12    }
13}
14
15#[cfg(feature = "std")]
16impl std::error::Error for LoopError {}
17
18/// The error type returned when key and/or nonce used in stream cipher
19/// initialization had an invalid length.
20#[derive(Copy, Clone, Debug)]
21pub struct InvalidLength;
22
23impl fmt::Display for InvalidLength {
24    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
25        f.write_str("Loop Error")
26    }
27}
28
29#[cfg(feature = "std")]
30impl std::error::Error for InvalidLength {}
31
32/// The error type returned when a cipher position can not be represented
33/// by the requested type.
34#[derive(Copy, Clone, Debug)]
35pub struct OverflowError;
36
37impl fmt::Display for OverflowError {
38    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
39        f.write_str("Overflow Error")
40    }
41}
42
43impl From<OverflowError> for LoopError {
44    fn from(_: OverflowError) -> LoopError {
45        LoopError
46    }
47}
48
49#[cfg(feature = "std")]
50impl std::error::Error for OverflowError {}