From 6a88acfbe4cc9e8f504a1b4e4fe1e1b3c36402ab Mon Sep 17 00:00:00 2001 From: Eric Devolder Date: Wed, 28 Aug 2024 10:42:41 +0200 Subject: [PATCH 1/2] Adjust code to compile under rust 1.80 Signed-off-by: Eric Devolder --- cryptoki/src/mechanism/mod.rs | 4 ++-- cryptoki/src/object.rs | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cryptoki/src/mechanism/mod.rs b/cryptoki/src/mechanism/mod.rs index 984d2267..0b501169 100644 --- a/cryptoki/src/mechanism/mod.rs +++ b/cryptoki/src/mechanism/mod.rs @@ -976,7 +976,7 @@ impl From<&Mechanism<'_>> for CK_MECHANISM { Mechanism::AesGcm(params) => CK_MECHANISM { mechanism, pParameter: params as *const _ as *mut c_void, - ulParameterLen: std::mem::size_of::() + ulParameterLen: size_of::() .try_into() .expect("usize can not fit in CK_ULONG"), }, @@ -1039,7 +1039,7 @@ fn make_mechanism(mechanism: CK_MECHANISM_TYPE, param: &T) -> CK_MECHANISM { // mechanisms we support involve mutating the parameter, so // this cast is OK. pParameter: param as *const T as *mut c_void, - ulParameterLen: std::mem::size_of::() + ulParameterLen: size_of::() .try_into() .expect("usize can not fit in CK_ULONG"), } diff --git a/cryptoki/src/object.rs b/cryptoki/src/object.rs index 5448c8a2..baa1e4d2 100644 --- a/cryptoki/src/object.rs +++ b/cryptoki/src/object.rs @@ -617,16 +617,16 @@ impl Attribute { | Attribute::Verify(_) | Attribute::VerifyRecover(_) | Attribute::Wrap(_) - | Attribute::WrapWithTrusted(_) => std::mem::size_of::(), + | Attribute::WrapWithTrusted(_) => size_of::(), Attribute::Base(_) => 1, Attribute::Application(bytes) | Attribute::Label(bytes) | Attribute::Url(bytes) => { - std::mem::size_of::() * bytes.len() + size_of::() * bytes.len() } Attribute::AcIssuer(bytes) => bytes.len(), Attribute::AttrTypes(bytes) => bytes.len(), - Attribute::CertificateType(_) => std::mem::size_of::(), + Attribute::CertificateType(_) => size_of::(), Attribute::CheckValue(bytes) => bytes.len(), - Attribute::Class(_) => std::mem::size_of::(), + Attribute::Class(_) => size_of::(), Attribute::Coefficient(bytes) => bytes.len(), Attribute::EcParams(bytes) => bytes.len(), Attribute::EcPoint(bytes) => bytes.len(), @@ -636,10 +636,10 @@ impl Attribute { Attribute::HashOfSubjectPublicKey(bytes) => bytes.len(), Attribute::Id(bytes) => bytes.len(), Attribute::Issuer(bytes) => bytes.len(), - Attribute::KeyGenMechanism(_) => std::mem::size_of::(), - Attribute::KeyType(_) => std::mem::size_of::(), + Attribute::KeyGenMechanism(_) => size_of::(), + Attribute::KeyType(_) => size_of::(), Attribute::Modulus(bytes) => bytes.len(), - Attribute::ModulusBits(_) => std::mem::size_of::(), + Attribute::ModulusBits(_) => size_of::(), Attribute::ObjectId(bytes) => bytes.len(), Attribute::Owner(bytes) => bytes.len(), Attribute::Prime(bytes) => bytes.len(), @@ -651,11 +651,11 @@ impl Attribute { Attribute::SerialNumber(bytes) => bytes.len(), Attribute::Subject(bytes) => bytes.len(), Attribute::Value(bytes) => bytes.len(), - Attribute::ValueLen(_) => std::mem::size_of::(), - Attribute::EndDate(_) | Attribute::StartDate(_) => std::mem::size_of::(), + Attribute::ValueLen(_) => size_of::(), + Attribute::EndDate(_) | Attribute::StartDate(_) => size_of::(), Attribute::AllowedMechanisms(mechanisms) => { - std::mem::size_of::() * mechanisms.len() + size_of::() * mechanisms.len() } } } @@ -767,7 +767,7 @@ impl From<&Attribute> for CK_ATTRIBUTE { /// false, and a nonzero value means true." so there is no invalid /// byte value. fn try_u8_into_bool(slice: &[u8]) -> Result { - let as_array: [u8; std::mem::size_of::()] = slice.try_into()?; + let as_array: [u8; size_of::()] = slice.try_into()?; let as_byte = CK_BBOOL::from_ne_bytes(as_array); Ok(!matches!(as_byte, 0u8)) } From 8a13adc2a1cd0f4f65572c86968acfd0e00f4d50 Mon Sep 17 00:00:00 2001 From: Eric Devolder Date: Thu, 29 Aug 2024 21:51:01 +0200 Subject: [PATCH 2/2] Combined fixes from #218 Signed-off-by: Eric Devolder --- cryptoki/src/mechanism/ekdf.rs | 2 +- cryptoki/src/mechanism/elliptic_curve.rs | 14 +++++++------- cryptoki/src/session/random.rs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cryptoki/src/mechanism/ekdf.rs b/cryptoki/src/mechanism/ekdf.rs index e8a3e05f..7494bb44 100644 --- a/cryptoki/src/mechanism/ekdf.rs +++ b/cryptoki/src/mechanism/ekdf.rs @@ -28,7 +28,7 @@ impl<'a> AesCbcDeriveParams<'a> { /// * `iv` - The initialization vector /// /// * `data` - Data that will be encryption with the base key to obtain - /// the new key from the resulted cypher. + /// the new key from the resulted cypher. pub fn new(iv: [u8; 16], data: &'a [u8]) -> Self { Self { inner: cryptoki_sys::CK_AES_CBC_ENCRYPT_DATA_PARAMS { diff --git a/cryptoki/src/mechanism/elliptic_curve.rs b/cryptoki/src/mechanism/elliptic_curve.rs index 21f55e0e..9c362872 100644 --- a/cryptoki/src/mechanism/elliptic_curve.rs +++ b/cryptoki/src/mechanism/elliptic_curve.rs @@ -42,13 +42,13 @@ impl<'a> Ecdh1DeriveParams<'a> { /// * `kdf` - The key derivation function to use. /// /// * `public_data` - The other party's public key. A token MUST be able - /// to accept this value encoded as a raw octet string (as per section - /// A.5.2 of ANSI X9.62). A token MAY, in addition, support accepting - /// this value as a DER-encoded `ECPoint` (as per section E.6 of ANSI - /// X9.62) i.e. the same as a `CKA_EC_POINT` encoding. The calling - /// application is responsible for converting the offered public key to the - /// compressed or uncompressed forms of these encodings if the token does - /// not support the offered form. + /// to accept this value encoded as a raw octet string (as per section + /// A.5.2 of ANSI X9.62). A token MAY, in addition, support accepting + /// this value as a DER-encoded `ECPoint` (as per section E.6 of ANSI + /// X9.62) i.e. the same as a `CKA_EC_POINT` encoding. The calling + /// application is responsible for converting the offered public key to the + /// compressed or uncompressed forms of these encodings if the token does + /// not support the offered form. pub fn new(kdf: EcKdf<'a>, public_data: &'a [u8]) -> Self { Self { kdf: kdf.kdf_type, diff --git a/cryptoki/src/session/random.rs b/cryptoki/src/session/random.rs index 409a4e4e..4926933b 100644 --- a/cryptoki/src/session/random.rs +++ b/cryptoki/src/session/random.rs @@ -13,7 +13,7 @@ impl Session { /// # Arguments /// /// * `random_slice` - The slice to stick the random data into. The length of the slice represents - /// the number of bytes to obtain from the RBG + /// the number of bytes to obtain from the RBG pub fn generate_random_slice(&self, random_data: &mut [u8]) -> Result<()> { unsafe { Rv::from(get_pkcs11!(self.client(), C_GenerateRandom)(