4
4
//! See: <https://docs.oasis-open.org/pkcs11/pkcs11-curr/v3.0/os/pkcs11-curr-v3.0-os.html#_Toc30061446>
5
5
6
6
use core:: { convert:: TryInto , marker:: PhantomData , pin:: Pin , ptr} ;
7
+ use std:: num:: NonZeroUsize ;
7
8
8
9
use cryptoki_sys:: {
9
10
CK_ATTRIBUTE , CK_ATTRIBUTE_PTR , CK_DERIVED_KEY , CK_DERIVED_KEY_PTR , CK_INVALID_HANDLE ,
@@ -42,10 +43,11 @@ impl KbkdfCounterFormat {
42
43
/// * `endianness` - The endianness of the counter's bit representation.
43
44
///
44
45
/// * `width_in_bits` - The number of bits used to represent the counter value.
45
- pub fn new ( endianness : Endianness , width_in_bits : usize ) -> Self {
46
+ pub fn new ( endianness : Endianness , width_in_bits : NonZeroUsize ) -> Self {
46
47
Self ( CK_SP800_108_COUNTER_FORMAT {
47
48
bLittleEndian : ( endianness == Endianness :: Little ) . into ( ) ,
48
49
ulWidthInBits : width_in_bits
50
+ . get ( )
49
51
. try_into ( )
50
52
. expect ( "bit width of KBKDF internal counter does not fit in CK_ULONG" ) ,
51
53
} )
@@ -83,7 +85,7 @@ impl KbkdfDkmLengthFormat {
83
85
pub fn new (
84
86
dkm_length_method : KbkdfDkmLengthMethod ,
85
87
endianness : Endianness ,
86
- width_in_bits : usize ,
88
+ width_in_bits : NonZeroUsize ,
87
89
) -> Self {
88
90
Self ( CK_SP800_108_DKM_LENGTH_FORMAT {
89
91
dkmLengthMethod : match dkm_length_method {
@@ -92,6 +94,7 @@ impl KbkdfDkmLengthFormat {
92
94
} ,
93
95
bLittleEndian : ( endianness == Endianness :: Little ) . into ( ) ,
94
96
ulWidthInBits : width_in_bits
97
+ . get ( )
95
98
. try_into ( )
96
99
. expect ( "bit width of KBKDF DKM length value does not fit in CK_ULONG" ) ,
97
100
} )
0 commit comments