| 1 | //! Error types. |
| 2 | |
| 3 | use 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)] |
| 12 | pub struct StreamCipherError; |
| 13 | |
| 14 | impl fmt::Display for StreamCipherError { |
| 15 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { |
| 16 | f.write_str(data:"Loop Error" ) |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | #[cfg (feature = "std" )] |
| 21 | #[cfg_attr (docsrs, doc(cfg(feature = "std" )))] |
| 22 | impl std::error::Error for StreamCipherError {} |
| 23 | |
| 24 | /// The error type returned when a cipher position can not be represented |
| 25 | /// by the requested type. |
| 26 | #[derive (Copy, Clone, Debug)] |
| 27 | pub struct OverflowError; |
| 28 | |
| 29 | impl fmt::Display for OverflowError { |
| 30 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { |
| 31 | f.write_str(data:"Overflow Error" ) |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | impl From<OverflowError> for StreamCipherError { |
| 36 | fn from(_: OverflowError) -> StreamCipherError { |
| 37 | StreamCipherError |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | #[cfg (feature = "std" )] |
| 42 | #[cfg_attr (docsrs, doc(cfg(feature = "std" )))] |
| 43 | impl std::error::Error for OverflowError {} |
| 44 | |