@@ -38,53 +38,55 @@ impl<'a> HkdfParams<'a> {
38
38
///
39
39
/// # Arguments
40
40
///
41
- /// * `extract` - Whether to execute the extract portion of HKDF.
42
- ///
43
- /// * `expand` - Whether to execute the expand portion of HKDF.
44
- ///
45
41
/// * `prf_hash_mechanism` - The base hash used for the HMAC in the underlying HKDF operation
46
42
///
47
- /// * `salt` - The salt for the extract stage.
43
+ /// * `salt` - The salt for the extract stage, skip extract if `None` .
48
44
///
49
- /// * `info` - The info string for the expand stage.
45
+ /// * `info` - The info string for the expand stage, skip expand if `None` .
50
46
pub fn new (
51
- extract : bool ,
52
- expand : bool ,
53
47
prf_hash_mechanism : MechanismType ,
54
- salt : HkdfSalt ,
55
- info : & ' a [ u8 ] ,
48
+ salt : Option < HkdfSalt > ,
49
+ info : Option < & ' a [ u8 ] > ,
56
50
) -> Self {
57
51
Self {
58
52
inner : cryptoki_sys:: CK_HKDF_PARAMS {
59
- bExtract : extract as u8 ,
60
- bExpand : expand as u8 ,
53
+ bExtract : salt . is_some ( ) as u8 ,
54
+ bExpand : info . is_some ( ) as u8 ,
61
55
prfHashMechanism : * prf_hash_mechanism,
62
56
ulSaltType : match salt {
63
- HkdfSalt :: Null => CKF_HKDF_SALT_NULL ,
64
- HkdfSalt :: Data ( _) => CKF_HKDF_SALT_DATA ,
65
- HkdfSalt :: Key ( _) => CKF_HKDF_SALT_KEY ,
57
+ None | Some ( HkdfSalt :: Null ) => CKF_HKDF_SALT_NULL ,
58
+ Some ( HkdfSalt :: Data ( _) ) => CKF_HKDF_SALT_DATA ,
59
+ Some ( HkdfSalt :: Key ( _) ) => CKF_HKDF_SALT_KEY ,
66
60
} ,
67
- pSalt : if let HkdfSalt :: Data ( data) = salt {
61
+ pSalt : if let Some ( HkdfSalt :: Data ( data) ) = salt {
68
62
data. as_ptr ( ) as * mut _
69
63
} else {
70
64
null_mut ( )
71
65
} ,
72
- ulSaltLen : if let HkdfSalt :: Data ( data) = salt {
66
+ ulSaltLen : if let Some ( HkdfSalt :: Data ( data) ) = salt {
73
67
data. len ( )
74
68
. try_into ( )
75
69
. expect ( "salt length does not fit in CK_ULONG" )
76
70
} else {
77
71
0
78
72
} ,
79
- hSaltKey : match salt {
80
- HkdfSalt :: Key ( key) => key. handle ( ) ,
81
- _ => 0 ,
73
+ hSaltKey : if let Some ( HkdfSalt :: Key ( key) ) = salt {
74
+ key. handle ( )
75
+ } else {
76
+ 0
77
+ } ,
78
+ pInfo : if let Some ( info) = info {
79
+ info. as_ptr ( ) as * mut _
80
+ } else {
81
+ null_mut ( )
82
+ } ,
83
+ ulInfoLen : if let Some ( info) = info {
84
+ info. len ( )
85
+ . try_into ( )
86
+ . expect ( "salt length does not fit in CK_ULONG" )
87
+ } else {
88
+ 0
82
89
} ,
83
- pInfo : info. as_ptr ( ) as * mut _ ,
84
- ulInfoLen : info
85
- . len ( )
86
- . try_into ( )
87
- . expect ( "info length does not fit in CK_ULONG" ) ,
88
90
} ,
89
91
_marker : PhantomData ,
90
92
}
0 commit comments