Skip to content

Commit 61aad83

Browse files
committed
Performed another cargo update, updated bitflags crate to latest version, and resolved all cargo clippy warnings
Signed-off-by: mematthias <[email protected]>
1 parent 87ea688 commit 61aad83

File tree

15 files changed

+84
-53
lines changed

15 files changed

+84
-53
lines changed

Cargo.lock

Lines changed: 12 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cryptoki-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cryptoki-sys"
3-
version = "0.4.1"
3+
version = "0.4.0"
44
authors = ["Contributors to the Parsec project"]
55
edition = '2021'
66
description = "FFI wrapper around the PKCS #11 API"

cryptoki/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cryptoki"
3-
version = "0.10.1"
3+
version = "0.10.0"
44
authors = ["Contributors to the Parsec project"]
55
edition = '2021'
66
description = "Rust-native wrapper around the PKCS #11 API"
@@ -13,14 +13,15 @@ documentation = "https://docs.rs/crate/cryptoki"
1313
rust-version = "1.77"
1414

1515
[dependencies]
16-
bitflags = "1.3.2"
16+
bitflags = "2.9.1"
1717
libloading = "0.8.8"
1818
log = "0.4.27"
19-
cryptoki-sys = { path = "../cryptoki-sys", version = "0.4.1" }
19+
cryptoki-sys = { path = "../cryptoki-sys", version = "0.4.0" }
2020
paste = "1.0.15"
2121
secrecy = "0.10.3"
2222

2323
[dev-dependencies]
24+
hex = "0.4.3"
2425
serial_test = "3.2.0"
2526
testresult = "0.4.1"
2627

cryptoki/src/context/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ impl Pkcs11Impl {
9393

9494
impl Drop for Pkcs11Impl {
9595
fn drop(&mut self) {
96-
if let Err(e) = self.finalize() {
97-
error!("Failed to finalize: {}", e);
96+
if let Err(err) = self.finalize() {
97+
error!("Failed to finalize: {err}");
9898
}
9999
}
100100
}

cryptoki/src/error/rv.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ impl From<CK_RV> for Rv {
120120
CKR_VENDOR_DEFINED..=CK_ULONG::MAX => Rv::Error(RvError::VendorDefined(ck_rv)),
121121
other => {
122122
error!(
123-
"Can not find a corresponding error for {}, converting to UnknownErrorCode.",
124-
other
123+
"Can not find a corresponding error for {other}, converting to UnknownErrorCode."
125124
);
126125
Rv::Error(RvError::UnknownErrorCode(other))
127126
}

cryptoki/src/mechanism/mechanism_info.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use cryptoki_sys::*;
77
use std::fmt::{Debug, Formatter};
88

99
bitflags! {
10+
#[derive(Debug, Clone, Copy)]
1011
struct MechanismInfoFlags: CK_FLAGS {
1112
const HW = CKF_HW;
1213
const ENCRYPT = CKF_ENCRYPT;
@@ -25,7 +26,6 @@ bitflags! {
2526
const EC_F_P = CKF_EC_F_P;
2627
const EC_F_2M = CKF_EC_F_2M;
2728
const EC_ECPARAMETERS = CKF_EC_ECPARAMETERS;
28-
const EC_NAMEDCURVE = CKF_EC_NAMEDCURVE;
2929
const EC_OID = CKF_EC_OID;
3030
const EC_UNCOMPRESS = CKF_EC_UNCOMPRESS;
3131
const EC_COMPRESS = CKF_EC_COMPRESS;
@@ -37,6 +37,12 @@ bitflags! {
3737
}
3838
}
3939

40+
impl MechanismInfoFlags {
41+
/// `CKF_EC_NAMEDCURVE` is deprecated with `PKCS#11 3.00`. It is replaced by [`CKF_EC_OID`](MechanismInfoFlags::EC_OID).
42+
#[deprecated = "use `EC_OID` instead"]
43+
pub const EC_NAMEDCURVE: Self = Self::from_bits_retain(CKF_EC_NAMEDCURVE);
44+
}
45+
4046
/// Information about a particular mechanism
4147
#[derive(Debug, Clone, Copy)]
4248
pub struct MechanismInfo {
@@ -201,6 +207,7 @@ impl MechanismInfo {
201207
/// [`ec_from_named_curve`](Self::ec_from_named_curve) must be `true`
202208
#[deprecated = "use `ec_from_oid` instead"]
203209
pub fn ec_from_named_curve(&self) -> bool {
210+
#[allow(deprecated)]
204211
self.flags.contains(MechanismInfoFlags::EC_NAMEDCURVE)
205212
}
206213

@@ -302,15 +309,25 @@ impl From<CK_MECHANISM_INFO> for MechanismInfo {
302309
#[cfg(test)]
303310
mod test {
304311
use super::{MechanismInfo, MechanismInfoFlags};
312+
use cryptoki_sys::CK_FLAGS;
313+
314+
#[test]
315+
fn deprecated_flags() {
316+
let ec_oid_bits: CK_FLAGS = MechanismInfoFlags::EC_OID.bits();
317+
#[allow(deprecated)]
318+
let ec_namedcurve_bits: CK_FLAGS = MechanismInfoFlags::EC_NAMEDCURVE.bits();
319+
assert_eq!(ec_oid_bits, ec_namedcurve_bits);
320+
}
305321

306322
#[test]
307323
fn debug_flags_all() {
308-
let expected = "\
309-
HW | ENCRYPT | DECRYPT | DIGEST | SIGN | SIGN_RECOVER | VERIFY | \
310-
VERIFY_RECOVER | GENERATE | GENERATE_KEY_PAIR | WRAP | UNWRAP | DERIVE | \
311-
EXTENSION | EC_F_P | EC_F_2M | EC_ECPARAMETERS | EC_NAMEDCURVE | \
312-
EC_OID | EC_UNCOMPRESS | EC_COMPRESS | MESSAGE_ENCRYPT | MESSAGE_DECRYPT | \
313-
MULTI_MESSAGE | ENCAPSULATE | DECAPSULATE";
324+
let expected = "MechanismInfoFlags(
325+
HW | ENCRYPT | DECRYPT | DIGEST | SIGN | SIGN_RECOVER | VERIFY | \
326+
VERIFY_RECOVER | GENERATE | GENERATE_KEY_PAIR | WRAP | UNWRAP | DERIVE | \
327+
EXTENSION | EC_F_P | EC_F_2M | EC_ECPARAMETERS | EC_OID | EC_UNCOMPRESS | \
328+
EC_COMPRESS | MESSAGE_ENCRYPT | MESSAGE_DECRYPT | MULTI_MESSAGE | ENCAPSULATE | \
329+
DECAPSULATE,
330+
)";
314331
let all = MechanismInfoFlags::all();
315332
let observed = format!("{all:#?}");
316333
println!("{observed}");
@@ -327,7 +344,9 @@ MULTI_MESSAGE | ENCAPSULATE | DECAPSULATE";
327344
let expected = r#"MechanismInfo {
328345
min_key_size: 16,
329346
max_key_size: 4096,
330-
flags: (empty),
347+
flags: MechanismInfoFlags(
348+
0x0,
349+
),
331350
}"#;
332351
let observed = format!("{info:#?}");
333352
assert_eq!(observed, expected);

cryptoki/src/mechanism/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ impl TryFrom<CK_MECHANISM_TYPE> for MechanismType {
913913
CKM_HASH_ML_DSA_SHA3_512 => Ok(MechanismType::HASH_ML_DSA_SHA3_512),
914914
CKM_HASH_ML_DSA_SHAKE128 => Ok(MechanismType::HASH_ML_DSA_SHAKE128),
915915
other => {
916-
error!("Mechanism type {} is not supported.", other);
916+
error!("Mechanism type {other} is not supported.");
917917
Err(Error::NotSupported)
918918
}
919919
}

cryptoki/src/mechanism/rsa.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ impl TryFrom<CK_RSA_PKCS_MGF_TYPE> for PkcsMgfType {
6666
CKG_MGF1_SHA384 => Ok(PkcsMgfType::MGF1_SHA384),
6767
CKG_MGF1_SHA512 => Ok(PkcsMgfType::MGF1_SHA512),
6868
other => {
69-
error!(
70-
"Mask Generation Function type {} is not one of the valid values.",
71-
other
72-
);
69+
error!("Mask Generation Function type {other} is not one of the valid values.");
7370
Err(Error::InvalidValue)
7471
}
7572
}

cryptoki/src/object.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl TryFrom<CK_ATTRIBUTE_TYPE> for AttributeType {
427427
CKA_WRAP_WITH_TRUSTED => Ok(AttributeType::WrapWithTrusted),
428428
CKA_VENDOR_DEFINED..=CK_ULONG::MAX => Ok(AttributeType::VendorDefined(attribute_type)),
429429
attr_type => {
430-
error!("Attribute type {} not supported.", attr_type);
430+
error!("Attribute type {attr_type} not supported.");
431431
Err(Error::NotSupported)
432432
}
433433
}
@@ -1331,7 +1331,7 @@ impl TryFrom<CK_OBJECT_CLASS> for ObjectClass {
13311331
CKO_OTP_KEY => Ok(ObjectClass::OTP_KEY),
13321332

13331333
_ => {
1334-
error!("Object class {} is not supported.", object_class);
1334+
error!("Object class {object_class} is not supported.");
13351335
Err(Error::NotSupported)
13361336
}
13371337
}
@@ -1626,7 +1626,7 @@ impl TryFrom<CK_KEY_TYPE> for KeyType {
16261626
CKK_ML_DSA => Ok(KeyType::ML_DSA),
16271627
CKK_VENDOR_DEFINED..=CK_ULONG::MAX => KeyType::new_vendor_defined(key_type),
16281628
_ => {
1629-
error!("Key type {} is not supported.", key_type);
1629+
error!("Key type {key_type} is not supported.");
16301630
Err(Error::NotSupported)
16311631
}
16321632
}
@@ -1702,7 +1702,7 @@ impl TryFrom<CK_CERTIFICATE_TYPE> for CertificateType {
17021702
CKC_X_509_ATTR_CERT => Ok(CertificateType::X_509_ATTR),
17031703
CKC_WTLS => Ok(CertificateType::WTLS),
17041704
_ => {
1705-
error!("Certificate type {} is not supported.", certificate_type);
1705+
error!("Certificate type {certificate_type} is not supported.");
17061706
Err(Error::NotSupported)
17071707
}
17081708
}

cryptoki/src/session/object_management.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ impl Drop for ObjectHandleIterator<'_> {
197197
if let Some(f) = get_pkcs11_func!(self.session.client(), C_FindObjectsFinal) {
198198
// swallow the return value, as we can't do anything about it,
199199
// but log the error
200-
if let Rv::Error(error) = Rv::from(unsafe { f(self.session.handle()) }) {
201-
log::error!("C_FindObjectsFinal() failed with error: {:?}", error);
200+
if let Rv::Error(err) = Rv::from(unsafe { f(self.session.handle()) }) {
201+
log::error!("C_FindObjectsFinal() failed with error: {err:?}");
202202
}
203203
} else {
204204
// bark but pass if C_FindObjectsFinal() is not implemented

0 commit comments

Comments
 (0)