@@ -230,8 +230,7 @@ impl DerivedKey {
230
230
///
231
231
/// * `template` - The template for the key to be derived.
232
232
pub fn new ( template : & [ Attribute ] ) -> Self {
233
- let template: Box < [ cryptoki_sys:: CK_ATTRIBUTE ] > =
234
- template. iter ( ) . map ( |attr| attr. into ( ) ) . collect ( ) ;
233
+ let template: Box < [ cryptoki_sys:: CK_ATTRIBUTE ] > = template. iter ( ) . map ( Into :: into) . collect ( ) ;
235
234
let template = Pin :: new ( template) ;
236
235
237
236
Self {
@@ -241,6 +240,20 @@ impl DerivedKey {
241
240
}
242
241
}
243
242
243
+ impl From < & mut DerivedKey > for cryptoki_sys:: CK_DERIVED_KEY {
244
+ fn from ( value : & mut DerivedKey ) -> Self {
245
+ cryptoki_sys:: CK_DERIVED_KEY {
246
+ pTemplate : value. template . as_ptr ( ) as cryptoki_sys:: CK_ATTRIBUTE_PTR ,
247
+ ulAttributeCount : value
248
+ . template
249
+ . len ( )
250
+ . try_into ( )
251
+ . expect ( "number of attributes in template does not fit in CK_ULONG" ) ,
252
+ phKey : & mut value. handle as cryptoki_sys:: CK_OBJECT_HANDLE_PTR ,
253
+ }
254
+ }
255
+ }
256
+
244
257
/// NIST SP 800-108 (aka KBKDF) counter-mode parameters.
245
258
///
246
259
/// This structure wraps a `CK_SP800_108_KDF_PARAMS` structure.
@@ -270,21 +283,13 @@ impl<'a> KbkdfCounterParams<'a> {
270
283
prf_data_params : & ' a [ PrfCounterDataParam < ' a > ] ,
271
284
additional_derived_keys : Option < & ' a mut [ DerivedKey ] > ,
272
285
) -> Self {
273
- let additional_derived_keys: Option < Box < [ cryptoki_sys :: CK_DERIVED_KEY ] > > =
274
- additional_derived_keys . map ( |keys| {
286
+ let mut additional_derived_keys = additional_derived_keys
287
+ . map ( |keys| {
275
288
keys. iter_mut ( )
276
- . map ( |key| cryptoki_sys:: CK_DERIVED_KEY {
277
- pTemplate : key. template . as_ptr ( ) as cryptoki_sys:: CK_ATTRIBUTE_PTR ,
278
- ulAttributeCount : key
279
- . template
280
- . len ( )
281
- . try_into ( )
282
- . expect ( "number of attributes in template does not fit in CK_ULONG" ) ,
283
- phKey : & mut key. handle as cryptoki_sys:: CK_OBJECT_HANDLE_PTR ,
284
- } )
285
- . collect ( )
286
- } ) ;
287
- let mut additional_derived_keys = additional_derived_keys. map ( |keys| Pin :: new ( keys) ) ;
289
+ . map ( Into :: into)
290
+ . collect :: < Box < [ cryptoki_sys:: CK_DERIVED_KEY ] > > ( )
291
+ } )
292
+ . map ( Pin :: new) ;
288
293
289
294
let inner = cryptoki_sys:: CK_SP800_108_KDF_PARAMS {
290
295
prfType : prf_mechanism. into ( ) ,
@@ -362,21 +367,13 @@ impl<'a> KbkdfFeedbackParams<'a> {
362
367
iv : Option < & ' a [ u8 ] > ,
363
368
additional_derived_keys : Option < & ' a mut [ DerivedKey ] > ,
364
369
) -> Self {
365
- let additional_derived_keys: Option < Box < [ cryptoki_sys :: CK_DERIVED_KEY ] > > =
366
- additional_derived_keys . map ( |keys| {
370
+ let mut additional_derived_keys = additional_derived_keys
371
+ . map ( |keys| {
367
372
keys. iter_mut ( )
368
- . map ( |key| cryptoki_sys:: CK_DERIVED_KEY {
369
- pTemplate : key. template . as_ptr ( ) as cryptoki_sys:: CK_ATTRIBUTE_PTR ,
370
- ulAttributeCount : key
371
- . template
372
- . len ( )
373
- . try_into ( )
374
- . expect ( "number of attributes in template does not fit in CK_ULONG" ) ,
375
- phKey : & mut key. handle as cryptoki_sys:: CK_OBJECT_HANDLE_PTR ,
376
- } )
377
- . collect ( )
378
- } ) ;
379
- let mut additional_derived_keys = additional_derived_keys. map ( |keys| Pin :: new ( keys) ) ;
373
+ . map ( Into :: into)
374
+ . collect :: < Box < [ cryptoki_sys:: CK_DERIVED_KEY ] > > ( )
375
+ } )
376
+ . map ( Pin :: new) ;
380
377
381
378
let inner = cryptoki_sys:: CK_SP800_108_FEEDBACK_KDF_PARAMS {
382
379
prfType : prf_mechanism. into ( ) ,
@@ -457,21 +454,13 @@ impl<'a> KbkdfDoublePipelineParams<'a> {
457
454
prf_data_params : & ' a [ PrfDataParam < ' a > ] ,
458
455
additional_derived_keys : Option < & ' a mut [ DerivedKey ] > ,
459
456
) -> Self {
460
- let additional_derived_keys: Option < Box < [ cryptoki_sys :: CK_DERIVED_KEY ] > > =
461
- additional_derived_keys . map ( |keys| {
457
+ let mut additional_derived_keys = additional_derived_keys
458
+ . map ( |keys| {
462
459
keys. iter_mut ( )
463
- . map ( |key| cryptoki_sys:: CK_DERIVED_KEY {
464
- pTemplate : key. template . as_ptr ( ) as cryptoki_sys:: CK_ATTRIBUTE_PTR ,
465
- ulAttributeCount : key
466
- . template
467
- . len ( )
468
- . try_into ( )
469
- . expect ( "number of attributes in template does not fit in CK_ULONG" ) ,
470
- phKey : & mut key. handle as cryptoki_sys:: CK_OBJECT_HANDLE_PTR ,
471
- } )
472
- . collect ( )
473
- } ) ;
474
- let mut additional_derived_keys = additional_derived_keys. map ( |keys| Pin :: new ( keys) ) ;
460
+ . map ( Into :: into)
461
+ . collect :: < Box < [ cryptoki_sys:: CK_DERIVED_KEY ] > > ( )
462
+ } )
463
+ . map ( Pin :: new) ;
475
464
476
465
let inner = cryptoki_sys:: CK_SP800_108_KDF_PARAMS {
477
466
prfType : prf_mechanism. into ( ) ,
0 commit comments