ssh_cipher/
error.rs

1//! Error types.
2
3use crate::Cipher;
4use core::fmt;
5
6/// Result type with `ssh-cipher` crate's [`Error`] as the error type.
7pub type Result<T> = core::result::Result<T, Error>;
8
9/// Error type.
10#[derive(Clone, Debug, Eq, PartialEq)]
11#[non_exhaustive]
12pub enum Error {
13    /// Cryptographic errors.
14    Crypto,
15
16    /// Invalid key size.
17    KeySize,
18
19    /// Invalid length (i.e. of an input buffer).
20    Length,
21
22    /// Invalid initialization vector / nonce size.
23    IvSize,
24
25    /// Invalid AEAD tag size.
26    TagSize,
27
28    /// Unsupported cipher.
29    UnsupportedCipher(Cipher),
30}
31
32impl fmt::Display for Error {
33    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34        match self {
35            Error::Crypto => write!(f, "cryptographic error"),
36            Error::KeySize => write!(f, "invalid key size"),
37            Error::Length => write!(f, "invalid input length"),
38            Error::IvSize => write!(f, "invalid initialization vector size"),
39            Error::TagSize => write!(f, "invalid AEAD tag size"),
40            Error::UnsupportedCipher(cipher) => write!(f, "unsupported cipher: {}", cipher),
41        }
42    }
43}
44
45impl core::error::Error for Error {}