44//! See: <https://docs.oasis-open.org/pkcs11/pkcs11-curr/v3.0/os/pkcs11-curr-v3.0-os.html#_Toc30061446>
55
66use core:: { convert:: TryInto , marker:: PhantomData , pin:: Pin , ptr} ;
7+ use std:: num:: NonZeroUsize ;
78
89use cryptoki_sys:: {
910 CK_ATTRIBUTE , CK_ATTRIBUTE_PTR , CK_DERIVED_KEY , CK_DERIVED_KEY_PTR , CK_INVALID_HANDLE ,
@@ -42,10 +43,11 @@ impl KbkdfCounterFormat {
4243 /// * `endianness` - The endianness of the counter's bit representation.
4344 ///
4445 /// * `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 {
4647 Self ( CK_SP800_108_COUNTER_FORMAT {
4748 bLittleEndian : ( endianness == Endianness :: Little ) . into ( ) ,
4849 ulWidthInBits : width_in_bits
50+ . get ( )
4951 . try_into ( )
5052 . expect ( "bit width of KBKDF internal counter does not fit in CK_ULONG" ) ,
5153 } )
@@ -83,7 +85,7 @@ impl KbkdfDkmLengthFormat {
8385 pub fn new (
8486 dkm_length_method : KbkdfDkmLengthMethod ,
8587 endianness : Endianness ,
86- width_in_bits : usize ,
88+ width_in_bits : NonZeroUsize ,
8789 ) -> Self {
8890 Self ( CK_SP800_108_DKM_LENGTH_FORMAT {
8991 dkmLengthMethod : match dkm_length_method {
@@ -92,6 +94,7 @@ impl KbkdfDkmLengthFormat {
9294 } ,
9395 bLittleEndian : ( endianness == Endianness :: Little ) . into ( ) ,
9496 ulWidthInBits : width_in_bits
97+ . get ( )
9598 . try_into ( )
9699 . expect ( "bit width of KBKDF DKM length value does not fit in CK_ULONG" ) ,
97100 } )
0 commit comments