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
#[derive(Debug)]
pub enum Error {
EncryptionError(&'static str),
DHError(&'static str),
SignatureError(&'static str),
SerdeError(String),
OutOfEntropy,
}
impl<'a> std::convert::From<std::io::Error> for Error {
fn from(other: std::io::Error) -> Error {
use std::error::Error;
crate::error::Error::SerdeError(other.description().to_string())
}
}
impl std::error::Error for Error {
fn description(&self) -> &str {
match self {
Error::EncryptionError(e) => e,
Error::DHError(e) => e,
Error::SignatureError(e) => e,
Error::SerdeError(e) => e.as_str(),
Error::OutOfEntropy => "Out of Entropy",
}
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
use std::error::Error;
f.write_str(self.description())
}
}
impl serde::ser::Error for Error {
fn custom<T: std::fmt::Display>(msg: T) -> Self {
Error::SerdeError(format!("{}", msg))
}
}