cipher\stream/
errors.rs

1//! Error types.
2
3use core::fmt;
4
5/// This error is returned by the [`StreamCipher`][crate::stream::StreamCipher]
6/// trait methods.
7///
8/// Usually it's used in cases when stream cipher has reached the end
9/// of a keystream, but also can be used if lengths of provided input
10/// and output buffers are not equal.
11#[derive(Copy, Clone, Debug)]
12pub struct StreamCipherError;
13
14impl fmt::Display for StreamCipherError {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
16        f.write_str("Loop Error")
17    }
18}
19
20impl core::error::Error for StreamCipherError {}
21
22/// The error type returned when a cipher position can not be represented
23/// by the requested type.
24#[derive(Copy, Clone, Debug)]
25pub struct OverflowError;
26
27impl fmt::Display for OverflowError {
28    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
29        f.write_str("Overflow Error")
30    }
31}
32
33impl From<OverflowError> for StreamCipherError {
34    fn from(_: OverflowError) -> StreamCipherError {
35        StreamCipherError
36    }
37}
38
39impl core::error::Error for OverflowError {}