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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
pub type Result<T> = std::result::Result<T, Error>;

#[derive(Debug)]
pub enum Error {
    WrongPassword,
    CryptoError,
    CipherError,
    BlockModeError,
    ParseError,
    ConversionError(std::str::Utf8Error),
    IoError(std::io::Error),
}

impl std::fmt::Display for Error {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match *self {
            Error::ConversionError(ref err) => write!(f, "{}", err),
            _ => write!(f, "{}", self),
        }
    }
}

impl std::error::Error for Error {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match *self {
            Error::ConversionError(ref err) => Some(err),
            _ => None,
        }
    }
}

impl std::convert::From<hmac::crypto_mac::InvalidKeyLength> for Error {
    fn from(_error: hmac::crypto_mac::InvalidKeyLength) -> Error {
        Error::CryptoError
    }
}

impl std::convert::From<aesni::block_cipher_trait::InvalidKeyLength> for Error {
    fn from(_error: aesni::block_cipher_trait::InvalidKeyLength) -> Error {
        Error::CipherError
    }
}

impl std::convert::From<block_modes::BlockModeError> for Error {
    fn from(_error: block_modes::BlockModeError) -> Error {
        Error::BlockModeError
    }
}

impl std::convert::From<block_modes::InvalidKeyIvLength> for Error {
    fn from(_error: block_modes::InvalidKeyIvLength) -> Error {
        Error::BlockModeError
    }
}

impl std::convert::From<plist::Error> for Error {
    fn from(_error: plist::Error) -> Error {
        Error::ParseError
    }
}

impl std::convert::From<std::str::Utf8Error> for Error {
    fn from(error: std::str::Utf8Error) -> Error {
        Error::ConversionError(error)
    }
}

impl std::convert::From<std::io::Error> for Error {
    fn from(error: std::io::Error) -> Error {
        Error::IoError(error)
    }
}

impl std::convert::From<std::num::ParseIntError> for Error {
    fn from(_error: std::num::ParseIntError) -> Error {
        Error::ParseError
    }
}