@@ -38,53 +38,55 @@ impl<'a> HkdfParams<'a> {
3838 ///
3939 /// # Arguments
4040 ///
41- /// * `extract` - Whether to execute the extract portion of HKDF.
42- ///
43- /// * `expand` - Whether to execute the expand portion of HKDF.
44- ///
4541 /// * `prf_hash_mechanism` - The base hash used for the HMAC in the underlying HKDF operation
4642 ///
47- /// * `salt` - The salt for the extract stage.
43+ /// * `salt` - The salt for the extract stage, skip extract if `None` .
4844 ///
49- /// * `info` - The info string for the expand stage.
45+ /// * `info` - The info string for the expand stage, skip expand if `None` .
5046 pub fn new (
51- extract : bool ,
52- expand : bool ,
5347 prf_hash_mechanism : MechanismType ,
54- salt : HkdfSalt ,
55- info : & ' a [ u8 ] ,
48+ salt : Option < HkdfSalt > ,
49+ info : Option < & ' a [ u8 ] > ,
5650 ) -> Self {
5751 Self {
5852 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 ,
6155 prfHashMechanism : * prf_hash_mechanism,
6256 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 ,
6660 } ,
67- pSalt : if let HkdfSalt :: Data ( data) = salt {
61+ pSalt : if let Some ( HkdfSalt :: Data ( data) ) = salt {
6862 data. as_ptr ( ) as * mut _
6963 } else {
7064 null_mut ( )
7165 } ,
72- ulSaltLen : if let HkdfSalt :: Data ( data) = salt {
66+ ulSaltLen : if let Some ( HkdfSalt :: Data ( data) ) = salt {
7367 data. len ( )
7468 . try_into ( )
7569 . expect ( "salt length does not fit in CK_ULONG" )
7670 } else {
7771 0
7872 } ,
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
8289 } ,
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" ) ,
8890 } ,
8991 _marker : PhantomData ,
9092 }
0 commit comments