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
#[derive(Debug)]
pub enum RtjError {
Generic(Box<dyn std::error::Error>),
Encryption(crypto_box::aead::Error),
Rng(rand::Error),
InvalidOperation(String),
}
impl std::fmt::Display for RtjError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {
RtjError::Generic(..) => {
write!(f, "general error")
}
RtjError::Encryption(..) => {
write!(f, "encryption/decryption failure")
}
RtjError::Rng(..) => {
write!(f, "rng failure")
}
RtjError::InvalidOperation(..) => {
write!(f, "invalid operation")
}
}
}
}
impl std::error::Error for RtjError {}
impl From<Box<dyn std::error::Error>> for RtjError {
fn from(err: Box<dyn std::error::Error>) -> RtjError {
RtjError::Generic(err)
}
}
impl From<rand::Error> for RtjError {
fn from(err: rand::Error) -> RtjError {
RtjError::Rng(err)
}
}
impl From<crypto_box::aead::Error> for RtjError {
fn from(err: crypto_box::aead::Error) -> RtjError {
RtjError::Encryption(err)
}
}