From ea45bd14ba1e6f745924f49d334987897245f32c Mon Sep 17 00:00:00 2001 From: John Baublitz Date: Wed, 18 Sep 2024 14:16:06 -0400 Subject: [PATCH] Allow specifying key length in add_by_key --- src/keyslot.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/keyslot.rs b/src/keyslot.rs index 3040f874..bae95c25 100644 --- a/src/keyslot.rs +++ b/src/keyslot.rs @@ -7,6 +7,7 @@ use std::{ ptr, }; +use either::Either; use libc::{c_int, c_uint}; use crate::{ @@ -111,12 +112,13 @@ impl<'a> CryptKeyslotHandle<'a> { pub fn add_by_key( &mut self, keyslot: Option, - volume_key: Option<&[u8]>, + volume_key: Option>, passphrase: &[u8], flags: CryptVolumeKey, ) -> Result { let (vk_ptr, vk_len) = match volume_key { - Some(vk) => (to_byte_ptr!(vk), vk.len()), + Some(Either::Left(vk)) => (to_byte_ptr!(vk), vk.len()), + Some(Either::Right(s)) => (std::ptr::null(), s), None => (std::ptr::null(), 0), }; errno_int_success!(mutex!(libcryptsetup_rs_sys::crypt_keyslot_add_by_key(