@@ -270,9 +270,9 @@ pub struct CryptParamsVerityRef<'a> {
270270 #[ allow( dead_code) ]
271271 data_device_cstring : CString ,
272272 #[ allow( dead_code) ]
273- hash_device_cstring : CString ,
273+ hash_device_cstring : Option < CString > ,
274274 #[ allow( dead_code) ]
275- fec_device_cstring : CString ,
275+ fec_device_cstring : Option < CString > ,
276276}
277277
278278/// Parameters specific to Verity
@@ -282,9 +282,9 @@ pub struct CryptParamsVerity {
282282 #[ allow( missing_docs) ]
283283 pub data_device : PathBuf ,
284284 #[ allow( missing_docs) ]
285- pub hash_device : PathBuf ,
285+ pub hash_device : Option < PathBuf > ,
286286 #[ allow( missing_docs) ]
287- pub fec_device : PathBuf ,
287+ pub fec_device : Option < PathBuf > ,
288288 #[ allow( missing_docs) ]
289289 pub salt : Vec < u8 > ,
290290 #[ allow( missing_docs) ]
@@ -312,8 +312,14 @@ impl<'a> TryFrom<&'a libcryptsetup_rs_sys::crypt_params_verity> for CryptParamsV
312312 Ok ( CryptParamsVerity {
313313 hash_name : from_str_ptr_to_owned ! ( v. hash_name) ?,
314314 data_device : PathBuf :: from ( from_str_ptr_to_owned ! ( v. data_device) ?) ,
315- hash_device : PathBuf :: from ( from_str_ptr_to_owned ! ( v. hash_device) ?) ,
316- fec_device : PathBuf :: from ( from_str_ptr_to_owned ! ( v. fec_device) ?) ,
315+ hash_device : match ptr_to_option ! ( v. hash_device) {
316+ Some ( s) => Some ( PathBuf :: from ( from_str_ptr_to_owned ! ( s) ?) ) ,
317+ None => None ,
318+ } ,
319+ fec_device : match ptr_to_option ! ( v. fec_device) {
320+ Some ( s) => Some ( PathBuf :: from ( from_str_ptr_to_owned ! ( s) ?) ) ,
321+ None => None ,
322+ } ,
317323 salt : Vec :: from ( unsafe {
318324 std:: slice:: from_raw_parts ( v. salt . cast :: < u8 > ( ) , v. salt_size as usize )
319325 } ) ,
@@ -335,14 +341,26 @@ impl<'a> TryInto<CryptParamsVerityRef<'a>> for &'a CryptParamsVerity {
335341 fn try_into ( self ) -> Result < CryptParamsVerityRef < ' a > , Self :: Error > {
336342 let hash_name_cstring = to_cstring ! ( self . hash_name) ?;
337343 let data_device_cstring = path_to_cstring ! ( self . data_device) ?;
338- let hash_device_cstring = path_to_cstring ! ( self . hash_device) ?;
339- let fec_device_cstring = path_to_cstring ! ( self . fec_device) ?;
344+ let hash_device_cstring = match self . hash_device {
345+ Some ( ref hash_device) => Some ( path_to_cstring ! ( hash_device) ?) ,
346+ None => None ,
347+ } ;
348+ let fec_device_cstring = match self . fec_device {
349+ Some ( ref fec_device) => Some ( path_to_cstring ! ( fec_device) ?) ,
350+ None => None ,
351+ } ;
340352 Ok ( CryptParamsVerityRef {
341353 inner : libcryptsetup_rs_sys:: crypt_params_verity {
342354 hash_name : hash_name_cstring. as_ptr ( ) ,
343355 data_device : data_device_cstring. as_ptr ( ) ,
344- hash_device : hash_device_cstring. as_ptr ( ) ,
345- fec_device : fec_device_cstring. as_ptr ( ) ,
356+ hash_device : hash_device_cstring
357+ . as_ref ( )
358+ . map ( |hd| hd. as_ptr ( ) )
359+ . unwrap_or ( ptr:: null ( ) ) ,
360+ fec_device : fec_device_cstring
361+ . as_ref ( )
362+ . map ( |fd| fd. as_ptr ( ) )
363+ . unwrap_or ( ptr:: null ( ) ) ,
346364 salt : self . salt . as_ptr ( ) . cast :: < libc:: c_char > ( ) ,
347365 salt_size : self . salt . len ( ) as u32 ,
348366 hash_type : self . hash_type ,
0 commit comments