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
use crate::{consts::flags::CryptActivate, device::CryptDevice, err::LibcryptErr};
pub struct ActiveDevice {
pub offset: u64,
pub iv_offset: u64,
pub size: u64,
pub flags: CryptActivate,
}
impl<'a> TryFrom<&'a libcryptsetup_rs_sys::crypt_active_device> for ActiveDevice {
type Error = LibcryptErr;
fn try_from(v: &'a libcryptsetup_rs_sys::crypt_active_device) -> Result<Self, Self::Error> {
Ok(ActiveDevice {
offset: v.offset,
iv_offset: v.iv_offset,
size: v.size,
flags: CryptActivate::from_bits(v.flags).ok_or(LibcryptErr::InvalidConversion)?,
})
}
}
pub struct CryptRuntimeHandle<'a> {
reference: &'a mut CryptDevice,
name: &'a str,
}
impl<'a> CryptRuntimeHandle<'a> {
pub(crate) fn new(reference: &'a mut CryptDevice, name: &'a str) -> Self {
CryptRuntimeHandle { reference, name }
}
pub fn get_active_device(&mut self) -> Result<ActiveDevice, LibcryptErr> {
let mut cad = libcryptsetup_rs_sys::crypt_active_device {
offset: 0,
iv_offset: 0,
size: 0,
flags: 0,
};
let name_cstring = to_cstring!(self.name)?;
errno!(mutex!(libcryptsetup_rs_sys::crypt_get_active_device(
self.reference.as_ptr(),
name_cstring.as_ptr(),
&mut cad as *mut _,
)))
.and_then(|_| ActiveDevice::try_from(&cad))
}
pub fn get_active_integrity_failures(&mut self) -> Result<u64, LibcryptErr> {
let name_cstring = to_cstring!(self.name)?;
Ok(
mutex!(libcryptsetup_rs_sys::crypt_get_active_integrity_failures(
self.reference.as_ptr(),
name_cstring.as_ptr(),
)) as u64,
)
}
}