1
+ // Copyright 2021 Contributors to the Parsec project.
2
+ // SPDX-License-Identifier: Apache-2.0
1
3
//! Mechanisms of hash-based key derive function (HKDF)
2
4
//! See: <https://docs.oasis-open.org/pkcs11/pkcs11-curr/v3.0/os/pkcs11-curr-v3.0-os.html#_Toc30061597>
3
5
@@ -9,8 +11,8 @@ use crate::object::ObjectHandle;
9
11
10
12
use super :: MechanismType ;
11
13
12
- #[ derive( Debug , Clone , Copy ) ]
13
14
/// The salt for the extract stage.
15
+ #[ derive( Debug , Clone , Copy ) ]
14
16
pub enum HkdfSalt < ' a > {
15
17
/// CKF_HKDF_SALT_NULL no salt is supplied.
16
18
Null ,
@@ -62,16 +64,17 @@ impl<'a> HkdfParams<'a> {
62
64
HkdfSalt :: Data ( _) => CKF_HKDF_SALT_DATA ,
63
65
HkdfSalt :: Key ( _) => CKF_HKDF_SALT_KEY ,
64
66
} ,
65
- pSalt : match salt {
66
- HkdfSalt :: Data ( data) => data. as_ptr ( ) as * mut _ ,
67
- _ => null_mut ( ) ,
67
+ pSalt : if let HkdfSalt :: Data ( data) = salt {
68
+ data. as_ptr ( ) as * mut _
69
+ } else {
70
+ null_mut ( )
68
71
} ,
69
- ulSaltLen : match salt {
70
- HkdfSalt :: Data ( data) => data
71
- . len ( )
72
+ ulSaltLen : if let HkdfSalt :: Data ( data) = salt {
73
+ data. len ( )
72
74
. try_into ( )
73
- . expect ( "salt length does not fit in CK_ULONG" ) ,
74
- _ => 0 ,
75
+ . expect ( "salt length does not fit in CK_ULONG" )
76
+ } else {
77
+ 0
75
78
} ,
76
79
hSaltKey : match salt {
77
80
HkdfSalt :: Key ( key) => key. handle ( ) ,
0 commit comments