Skip to content

Commit bc95ac0

Browse files
authored
Merge pull request #447 from jbaublitz/issue-stratisd-3597-2
Make LUKS info in reencryption optional
2 parents 12feb1a + c4042f2 commit bc95ac0

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/luks2/reencrypt.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct CryptParamsReencryptRef<'a> {
3030
#[allow(dead_code)]
3131
reference: &'a CryptParamsReencrypt,
3232
#[allow(dead_code)]
33-
luks2_params: Box<CryptParamsLuks2Ref<'a>>,
33+
luks2_params: Option<Box<CryptParamsLuks2Ref<'a>>>,
3434
#[allow(dead_code)]
3535
resilience_cstring: CString,
3636
#[allow(dead_code)]
@@ -60,7 +60,7 @@ pub struct CryptParamsReencrypt {
6060
/// Size of the device
6161
pub device_size: u64,
6262
/// LUKS2-specific parameters
63-
pub luks2: CryptParamsLuks2,
63+
pub luks2: Option<CryptParamsLuks2>,
6464
/// Reencryption flags
6565
pub flags: CryptReencrypt,
6666
}
@@ -69,7 +69,10 @@ impl<'a> TryInto<CryptParamsReencryptRef<'a>> for &'a CryptParamsReencrypt {
6969
type Error = LibcryptErr;
7070

7171
fn try_into(self) -> Result<CryptParamsReencryptRef<'a>, Self::Error> {
72-
let mut luks2_params: Box<CryptParamsLuks2Ref<'a>> = Box::new((&self.luks2).try_into()?);
72+
let mut luks2_params: Option<Box<CryptParamsLuks2Ref<'a>>> = match self.luks2.as_ref() {
73+
Some(l) => Some(Box::new(l.try_into()?)),
74+
None => None,
75+
};
7376

7477
let resilience_cstring = to_cstring!(self.resilience)?;
7578
let hash_cstring = to_cstring!(self.hash)?;
@@ -82,7 +85,10 @@ impl<'a> TryInto<CryptParamsReencryptRef<'a>> for &'a CryptParamsReencrypt {
8285
data_shift: self.data_shift,
8386
max_hotzone_size: self.max_hotzone_size,
8487
device_size: self.device_size,
85-
luks2: luks2_params.as_ptr().cast(),
88+
luks2: luks2_params
89+
.as_mut()
90+
.map(|l| l.as_ptr().cast())
91+
.unwrap_or(ptr::null_mut()),
8692
flags: self.flags.bits(),
8793
};
8894
Ok(CryptParamsReencryptRef {

src/tests/reencrypt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub fn test_reencrypt_by_password() {
8080
data_shift: 0,
8181
max_hotzone_size: 0,
8282
device_size: 0,
83-
luks2: CryptParamsLuks2 {
83+
luks2: Some(CryptParamsLuks2 {
8484
data_alignment: 0,
8585
data_device: None,
8686
integrity: None,
@@ -89,7 +89,7 @@ pub fn test_reencrypt_by_password() {
8989
label: None,
9090
sector_size: size,
9191
subsystem: None,
92-
},
92+
}),
9393
flags: CryptReencrypt::empty(),
9494
},
9595
)

0 commit comments

Comments
 (0)