1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//! Error handling module

use std::fmt;
pub use crate::aes::SymmError;
pub use crate::scrypt::ScryptError;

/// Generic Error type for the crate
#[derive(Debug)]
pub enum Error {
    /// AES encryption error
    Aes(SymmError),
    /// Scrypt encryption error
    Scrypt(ScryptError)
}

impl From<SymmError> for Error {
    fn from(err: SymmError) -> Error {
        Error::Aes(err)
    }
}

impl From<ScryptError> for Error {
    fn from(err: ScryptError) -> Error {
        Error::Scrypt(err)
    }
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            Error::Aes(err) => err.fmt(f),
            Error::Scrypt(err) => err.fmt(f),
        }
    }
}