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
use std::{fmt, io};
use std::error::Error;
#[derive(Debug)]
pub enum CryptoError {
UnsupportedVersion,
DecryptFailed,
BadLength,
BadKey,
BadFormat,
NotInStorage,
Io(io::Error),
}
impl fmt::Display for CryptoError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
CryptoError::UnsupportedVersion => write!(f, "Chosen crypto version not supported."),
CryptoError::DecryptFailed => write!(f, "Could not decrypt with key"),
CryptoError::BadKey => write!(f, "Crypto key is weak or invalid"),
CryptoError::BadLength => write!(f, "Provided data length is invalid"),
CryptoError::BadFormat => write!(f, "Format of data does not match specification"),
CryptoError::NotInStorage => write!(f, "Provided Key/Identity/StreamKey is not in storage"),
CryptoError::Io(ref err) => err.fmt(f),
}
}
}
impl Error for CryptoError {
}
impl From<io::Error> for CryptoError {
fn from(err: io::Error) -> CryptoError {
CryptoError::Io(err)
}
}