Skip to content

Commit fa1e79b

Browse files
committed
Performed another cargo update, updated bitflags crate to latest version, and resolved all cargo clippy warnings
Signed-off-by: mematthias <107192630+mematthias@users.noreply.github.com>
1 parent 2aa4505 commit fa1e79b

File tree

15 files changed

+79
-57
lines changed

15 files changed

+79
-57
lines changed

Cargo.lock

Lines changed: 9 additions & 15 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: 3 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,10 +13,10 @@ 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

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
@@ -119,8 +119,7 @@ impl From<CK_RV> for Rv {
119119
CKR_VENDOR_DEFINED => Rv::Error(RvError::VendorDefined),
120120
other => {
121121
error!(
122-
"Can not find a corresponding error for {}, converting to GeneralError.",
123-
other
122+
"Can not find a corresponding error for {other}, converting to GeneralError."
124123
);
125124
Rv::Error(RvError::GeneralError)
126125
}

cryptoki/src/mechanism/mechanism_info.rs

Lines changed: 26 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;
@@ -35,6 +35,12 @@ bitflags! {
3535
}
3636
}
3737

38+
impl MechanismInfoFlags {
39+
/// `CKF_EC_NAMEDCURVE` is deprecated with `PKCS#11 3.00`. It is replaced by [`CKF_EC_OID`](MechanismInfoFlags::EC_OID).
40+
#[deprecated = "use `EC_OID` instead"]
41+
pub const EC_NAMEDCURVE: Self = Self::from_bits_retain(CKF_EC_NAMEDCURVE);
42+
}
43+
3844
/// Information about a particular mechanism
3945
#[derive(Debug, Clone, Copy)]
4046
pub struct MechanismInfo {
@@ -199,6 +205,7 @@ impl MechanismInfo {
199205
/// [`ec_from_named_curve`](Self::ec_from_named_curve) must be `true`
200206
#[deprecated = "use `ec_from_oid` instead"]
201207
pub fn ec_from_named_curve(&self) -> bool {
208+
#[allow(deprecated)]
202209
self.flags.contains(MechanismInfoFlags::EC_NAMEDCURVE)
203210
}
204211

@@ -286,15 +293,24 @@ impl From<CK_MECHANISM_INFO> for MechanismInfo {
286293
#[cfg(test)]
287294
mod test {
288295
use super::{MechanismInfo, MechanismInfoFlags};
296+
use cryptoki_sys::CK_FLAGS;
297+
298+
#[test]
299+
fn deprecated_flags() {
300+
let ec_oid_bits: CK_FLAGS = MechanismInfoFlags::EC_OID.bits();
301+
#[allow(deprecated)]
302+
let ec_namedcurve_bits: CK_FLAGS = MechanismInfoFlags::EC_NAMEDCURVE.bits();
303+
assert_eq!(ec_oid_bits, ec_namedcurve_bits);
304+
}
289305

290306
#[test]
291307
fn debug_flags_all() {
292-
let expected = "\
293-
HW | ENCRYPT | DECRYPT | DIGEST | SIGN | SIGN_RECOVER | VERIFY | \
294-
VERIFY_RECOVER | GENERATE | GENERATE_KEY_PAIR | WRAP | UNWRAP | DERIVE | \
295-
EXTENSION | EC_F_P | EC_F_2M | EC_ECPARAMETERS | EC_NAMEDCURVE | \
296-
EC_OID | EC_UNCOMPRESS | EC_COMPRESS | MESSAGE_ENCRYPT | MESSAGE_DECRYPT | \
297-
MULTI_MESSAGE";
308+
let expected = "MechanismInfoFlags(
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_OID | EC_UNCOMPRESS | \
312+
EC_COMPRESS | MESSAGE_ENCRYPT | MESSAGE_DECRYPT | MULTI_MESSAGE,
313+
)";
298314
let all = MechanismInfoFlags::all();
299315
let observed = format!("{all:#?}");
300316
println!("{observed}");
@@ -311,7 +327,9 @@ MULTI_MESSAGE";
311327
let expected = r#"MechanismInfo {
312328
min_key_size: 16,
313329
max_key_size: 4096,
314-
flags: (empty),
330+
flags: MechanismInfoFlags(
331+
0x0,
332+
),
315333
}"#;
316334
let observed = format!("{info:#?}");
317335
assert_eq!(observed, expected);

cryptoki/src/mechanism/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ impl TryFrom<CK_MECHANISM_TYPE> for MechanismType {
823823
CKM_SP800_108_FEEDBACK_KDF => Ok(MechanismType::SP800_108_FEEDBACK_KDF),
824824
CKM_SP800_108_DOUBLE_PIPELINE_KDF => Ok(MechanismType::SP800_108_DOUBLE_PIPELINE_KDF),
825825
other => {
826-
error!("Mechanism type {} is not supported.", other);
826+
error!("Mechanism type {other} is not supported.");
827827
Err(Error::NotSupported)
828828
}
829829
}

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
@@ -411,7 +411,7 @@ impl TryFrom<CK_ATTRIBUTE_TYPE> for AttributeType {
411411
CKA_WRAP_WITH_TRUSTED => Ok(AttributeType::WrapWithTrusted),
412412
CKA_VENDOR_DEFINED..=MAX_CU_ULONG => Ok(AttributeType::VendorDefined(attribute_type)),
413413
attr_type => {
414-
error!("Attribute type {} not supported.", attr_type);
414+
error!("Attribute type {attr_type} not supported.");
415415
Err(Error::NotSupported)
416416
}
417417
}
@@ -1088,7 +1088,7 @@ impl TryFrom<CK_OBJECT_CLASS> for ObjectClass {
10881088
CKO_OTP_KEY => Ok(ObjectClass::OTP_KEY),
10891089

10901090
_ => {
1091-
error!("Object class {} is not supported.", object_class);
1091+
error!("Object class {object_class} is not supported.");
10921092
Err(Error::NotSupported)
10931093
}
10941094
}
@@ -1373,7 +1373,7 @@ impl TryFrom<CK_KEY_TYPE> for KeyType {
13731373
CKK_HKDF => Ok(KeyType::HKDF),
13741374
CKK_VENDOR_DEFINED..=MAX_CU_ULONG => KeyType::new_vendor_defined(key_type),
13751375
_ => {
1376-
error!("Key type {} is not supported.", key_type);
1376+
error!("Key type {key_type} is not supported.");
13771377
Err(Error::NotSupported)
13781378
}
13791379
}
@@ -1449,7 +1449,7 @@ impl TryFrom<CK_CERTIFICATE_TYPE> for CertificateType {
14491449
CKC_X_509_ATTR_CERT => Ok(CertificateType::X_509_ATTR),
14501450
CKC_WTLS => Ok(CertificateType::WTLS),
14511451
_ => {
1452-
error!("Certificate type {} is not supported.", certificate_type);
1452+
error!("Certificate type {certificate_type} is not supported.");
14531453
Err(Error::NotSupported)
14541454
}
14551455
}

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)