libcryptsetup_rs/
backup.rs1use std::{path::Path, ptr};
6
7use crate::{consts::vals::EncryptionFormat, device::CryptDevice, err::LibcryptErr};
8
9pub struct CryptBackupHandle<'a> {
11 reference: &'a mut CryptDevice,
12}
13
14impl<'a> CryptBackupHandle<'a> {
15 pub(crate) fn new(reference: &'a mut CryptDevice) -> Self {
16 CryptBackupHandle { reference }
17 }
18
19 pub fn header_backup(
21 &mut self,
22 requested_type: Option<EncryptionFormat>,
23 backup_file: &Path,
24 ) -> Result<(), LibcryptErr> {
25 let backup_file_cstring = path_to_cstring!(backup_file)?;
26 errno!(mutex!(libcryptsetup_rs_sys::crypt_header_backup(
27 self.reference.as_ptr(),
28 requested_type
29 .map(|ty| ty.as_ptr())
30 .unwrap_or_else(ptr::null),
31 backup_file_cstring.as_ptr(),
32 )))
33 }
34
35 pub fn header_restore(
37 &mut self,
38 requested_type: Option<EncryptionFormat>,
39 backup_file: &Path,
40 ) -> Result<(), LibcryptErr> {
41 let backup_file_cstring = path_to_cstring!(backup_file)?;
42 errno!(mutex!(libcryptsetup_rs_sys::crypt_header_restore(
43 self.reference.as_ptr(),
44 requested_type
45 .map(|ty| ty.as_ptr())
46 .unwrap_or_else(ptr::null),
47 backup_file_cstring.as_ptr(),
48 )))
49 }
50}