sha_crypt/
errors.rs

1//! Error types.
2
3use alloc::string;
4
5#[cfg(feature = "simple")]
6use alloc::string::String;
7
8#[cfg(feature = "std")]
9use std::io;
10
11/// Error type.
12#[derive(Debug)]
13pub enum CryptError {
14    /// Should be within range defs::ROUNDS_MIN < defs::ROUNDS_MIN
15    RoundsError,
16
17    /// RNG failed.
18    RandomError,
19
20    /// I/O error.
21    #[cfg(feature = "std")]
22    #[cfg_attr(docsrs, doc(cfg(feature = "std")))]
23    IoError(io::Error),
24
25    /// UTF-8 error.
26    StringError(string::FromUtf8Error),
27}
28
29#[cfg(feature = "std")]
30impl From<io::Error> for CryptError {
31    fn from(e: io::Error) -> Self {
32        CryptError::IoError(e)
33    }
34}
35
36impl From<string::FromUtf8Error> for CryptError {
37    fn from(e: string::FromUtf8Error) -> Self {
38        CryptError::StringError(e)
39    }
40}
41
42#[cfg(feature = "simple")]
43#[cfg_attr(docsrs, doc(cfg(feature = "simple")))]
44#[derive(Debug)]
45pub enum CheckError {
46    InvalidFormat(String),
47    Crypt(CryptError),
48    HashMismatch,
49}
50
51/// Decoding errors.
52#[cfg(feature = "simple")]
53#[cfg_attr(docsrs, doc(cfg(feature = "simple")))]
54#[derive(Debug)]
55pub struct DecodeError;
56
57#[cfg(feature = "simple")]
58impl From<DecodeError> for CheckError {
59    fn from(_: DecodeError) -> CheckError {
60        CheckError::InvalidFormat("invalid B64".into())
61    }
62}