@@ -259,6 +259,52 @@ impl<'a> CryptLuks2TokenHandle<'a> {
259259 ) ) )
260260 . map ( |rc| rc as c_uint )
261261 }
262+
263+ /// Activate device or check key using a token and PIN
264+ #[ cfg( cryptsetup24supported) ]
265+ pub fn activate_by_token_pin < T > (
266+ & mut self ,
267+ name : Option < & str > ,
268+ type_ : Option < & str > ,
269+ token : Option < c_uint > ,
270+ pin : & [ u8 ] ,
271+ usrdata : Option < & mut T > ,
272+ flags : CryptActivate ,
273+ ) -> Result < c_uint , LibcryptErr > {
274+ let name_cstring_option = match name {
275+ Some ( n) => Some ( to_cstring ! ( n) ?) ,
276+ None => None ,
277+ } ;
278+ let type_cstring_option = match type_ {
279+ Some ( t) => Some ( to_cstring ! ( t) ?) ,
280+ None => None ,
281+ } ;
282+ let usrdata_ptr = match usrdata {
283+ Some ( reference) => ( reference as * mut T ) . cast :: < c_void > ( ) ,
284+ None => ptr:: null_mut ( ) ,
285+ } ;
286+ errno_int_success ! ( mutex!( libcryptsetup_rs_sys:: crypt_activate_by_token_pin(
287+ self . reference. as_ptr( ) ,
288+ // NOTE: Must keep as_ref to avoid use after free error.
289+ name_cstring_option
290+ . as_ref( )
291+ . map( |s| s. as_ptr( ) )
292+ . unwrap_or_else( ptr:: null) ,
293+ // NOTE: Must keep as_ref to avoid use after free error.
294+ type_cstring_option
295+ . as_ref( )
296+ . map( |s| s. as_ptr( ) )
297+ . unwrap_or_else( ptr:: null) ,
298+ token
299+ . map( |t| t as c_int)
300+ . unwrap_or( libcryptsetup_rs_sys:: CRYPT_ANY_TOKEN ) ,
301+ to_byte_ptr!( pin) ,
302+ pin. len( ) ,
303+ usrdata_ptr,
304+ flags. bits( ) ,
305+ ) ) )
306+ . map ( |rc| rc as c_uint )
307+ }
262308}
263309
264310/// Register token handler
0 commit comments