Skip to content

Commit

Permalink
Adjust code to compile under rust 1.80
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Devolder <eric.devolder@gmail.com>
  • Loading branch information
keldonin authored and gowthamsk-arm committed Aug 30, 2024
1 parent b2839f5 commit ad8baf6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
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

0 comments on commit ad8baf6

Please sign in to comment.