Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust code to compile under rust 1.80 #217

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cryptoki/src/mechanism/ekdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions cryptoki/src/mechanism/elliptic_curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions cryptoki/src/mechanism/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<CK_GCM_PARAMS>()
ulParameterLen: size_of::<CK_GCM_PARAMS>()
.try_into()
.expect("usize can not fit in CK_ULONG"),
},
Expand Down Expand Up @@ -1039,7 +1039,7 @@ fn make_mechanism<T>(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::<T>()
ulParameterLen: size_of::<T>()
.try_into()
.expect("usize can not fit in CK_ULONG"),
}
Expand Down
22 changes: 11 additions & 11 deletions cryptoki/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,16 +617,16 @@ impl Attribute {
| Attribute::Verify(_)
| Attribute::VerifyRecover(_)
| Attribute::Wrap(_)
| Attribute::WrapWithTrusted(_) => std::mem::size_of::<bool>(),
| Attribute::WrapWithTrusted(_) => size_of::<bool>(),
Attribute::Base(_) => 1,
Attribute::Application(bytes) | Attribute::Label(bytes) | Attribute::Url(bytes) => {
std::mem::size_of::<CK_UTF8CHAR>() * bytes.len()
size_of::<CK_UTF8CHAR>() * bytes.len()
}
Attribute::AcIssuer(bytes) => bytes.len(),
Attribute::AttrTypes(bytes) => bytes.len(),
Attribute::CertificateType(_) => std::mem::size_of::<CK_CERTIFICATE_TYPE>(),
Attribute::CertificateType(_) => size_of::<CK_CERTIFICATE_TYPE>(),
Attribute::CheckValue(bytes) => bytes.len(),
Attribute::Class(_) => std::mem::size_of::<CK_OBJECT_CLASS>(),
Attribute::Class(_) => size_of::<CK_OBJECT_CLASS>(),
Attribute::Coefficient(bytes) => bytes.len(),
Attribute::EcParams(bytes) => bytes.len(),
Attribute::EcPoint(bytes) => bytes.len(),
Expand All @@ -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::<CK_MECHANISM_TYPE>(),
Attribute::KeyType(_) => std::mem::size_of::<CK_KEY_TYPE>(),
Attribute::KeyGenMechanism(_) => size_of::<CK_MECHANISM_TYPE>(),
Attribute::KeyType(_) => size_of::<CK_KEY_TYPE>(),
Attribute::Modulus(bytes) => bytes.len(),
Attribute::ModulusBits(_) => std::mem::size_of::<CK_ULONG>(),
Attribute::ModulusBits(_) => size_of::<CK_ULONG>(),
Attribute::ObjectId(bytes) => bytes.len(),
Attribute::Owner(bytes) => bytes.len(),
Attribute::Prime(bytes) => bytes.len(),
Expand All @@ -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::<CK_ULONG>(),
Attribute::EndDate(_) | Attribute::StartDate(_) => std::mem::size_of::<CK_DATE>(),
Attribute::ValueLen(_) => size_of::<CK_ULONG>(),
Attribute::EndDate(_) | Attribute::StartDate(_) => size_of::<CK_DATE>(),

Attribute::AllowedMechanisms(mechanisms) => {
std::mem::size_of::<CK_MECHANISM_TYPE>() * mechanisms.len()
size_of::<CK_MECHANISM_TYPE>() * mechanisms.len()
}
}
}
Expand Down Expand Up @@ -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<bool> {
let as_array: [u8; std::mem::size_of::<CK_BBOOL>()] = slice.try_into()?;
let as_array: [u8; size_of::<CK_BBOOL>()] = slice.try_into()?;
let as_byte = CK_BBOOL::from_ne_bytes(as_array);
Ok(!matches!(as_byte, 0u8))
}
Expand Down
2 changes: 1 addition & 1 deletion cryptoki/src/session/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)(
Expand Down
Loading