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
use std::{
error::Error,
ffi::NulError,
fmt::{self, Display},
io,
str::Utf8Error,
};
#[derive(Debug)]
pub enum LibcryptErr {
IOError(io::Error),
UuidError(uuid::Error),
NullError(NulError),
Utf8Error(Utf8Error),
JsonError(serde_json::Error),
InvalidConversion,
NullPtr,
NoNull(&'static str),
Other(String),
}
impl Display for LibcryptErr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
LibcryptErr::IOError(ref e) => write!(f, "IO error occurred: {}", e),
LibcryptErr::UuidError(ref e) => write!(f, "Failed to parse UUID from C string: {}", e),
LibcryptErr::NullError(ref e) => write!(
f,
"Null error occurred when handling &str conversion: {}",
e
),
LibcryptErr::Utf8Error(ref e) => write!(
f,
"UTF8 error occurred when handling &str conversion: {}",
e
),
LibcryptErr::JsonError(ref e) => {
write!(f, "Failed to parse the provided string into JSON: {}", e)
}
LibcryptErr::InvalidConversion => {
write!(f, "Failed to perform the specified conversion")
}
LibcryptErr::NullPtr => write!(f, "Cryptsetup returned a null pointer"),
LibcryptErr::NoNull(s) => {
write!(f, "Static string {} was not created with c_str!() macro", s)
}
LibcryptErr::Other(ref s) => write!(f, "Failed with error: {}", s),
}
}
}
impl Error for LibcryptErr {}