Skip to content

Commit 2702bba

Browse files
authored
Merge pull request #320 from hug-dev/mematthias-updates
Miscellaneous updates
2 parents a884179 + 800a4d0 commit 2702bba

File tree

15 files changed

+272
-240
lines changed

15 files changed

+272
-240
lines changed

Cargo.lock

Lines changed: 196 additions & 192 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ documentation = "https://docs.rs/crate/cryptoki-sys"
1313
rust-version = "1.77"
1414

1515
[build-dependencies]
16-
bindgen = { version = "0.72.0", optional = true }
16+
bindgen = { version = "0.72.1", optional = true }
1717

1818
[dependencies]
19-
libloading = "0.8.6"
19+
libloading = "0.8.9"
2020

2121
[features]
2222
generate-bindings = ["bindgen"]

cryptoki/Cargo.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@ documentation = "https://docs.rs/crate/cryptoki"
1313
rust-version = "1.77"
1414

1515
[dependencies]
16-
bitflags = "1.3"
17-
libloading = "0.8.6"
18-
log = "0.4.14"
16+
bitflags = "2.10.0"
17+
libloading = "0.8.9"
18+
log = "0.4.28"
1919
cryptoki-sys = { path = "../cryptoki-sys", version = "0.4.0" }
20-
paste = "1.0.6"
20+
paste = "1.0.15"
2121
secrecy = "0.10.3"
2222

2323
[dev-dependencies]
24-
num-traits = "0.2.14"
2524
hex = "0.4.3"
26-
serial_test = "0.5.1"
25+
serial_test = "3.2.0"
2726
testresult = "0.4.1"
2827

2928
[features]

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
@@ -1020,7 +1020,7 @@ impl TryFrom<CK_MECHANISM_TYPE> for MechanismType {
10201020
CKM_HASH_SLH_DSA_SHA3_512 => Ok(MechanismType::HASH_SLH_DSA_SHA3_512),
10211021
CKM_HASH_SLH_DSA_SHAKE128 => Ok(MechanismType::HASH_SLH_DSA_SHAKE128),
10221022
other => {
1023-
error!("Mechanism type {} is not supported.", other);
1023+
error!("Mechanism type {other} is not supported.");
10241024
Err(Error::NotSupported)
10251025
}
10261026
}

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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ impl TryFrom<CK_ATTRIBUTE_TYPE> for AttributeType {
501501
CKA_WRAP_WITH_TRUSTED => Ok(AttributeType::WrapWithTrusted),
502502
CKA_VENDOR_DEFINED..=CK_ULONG::MAX => Ok(AttributeType::VendorDefined(attribute_type)),
503503
attr_type => {
504-
error!("Attribute type {} not supported.", attr_type);
504+
error!("Attribute type {attr_type} not supported.");
505505
Err(Error::NotSupported)
506506
}
507507
}
@@ -1347,7 +1347,7 @@ impl TryFrom<CK_ML_KEM_PARAMETER_SET_TYPE> for MlKemParameterSetType {
13471347
CKP_ML_KEM_768 => Ok(MlKemParameterSetType::ML_KEM_768),
13481348
CKP_ML_KEM_1024 => Ok(MlKemParameterSetType::ML_KEM_1024),
13491349
_ => {
1350-
error!("ML-KEM parameter set {} is not supported.", val);
1350+
error!("ML-KEM parameter set {val} is not supported.");
13511351
Err(Error::NotSupported)
13521352
}
13531353
}
@@ -1414,7 +1414,7 @@ impl TryFrom<CK_ML_DSA_PARAMETER_SET_TYPE> for MlDsaParameterSetType {
14141414
CKP_ML_DSA_65 => Ok(MlDsaParameterSetType::ML_DSA_65),
14151415
CKP_ML_DSA_87 => Ok(MlDsaParameterSetType::ML_DSA_87),
14161416
_ => {
1417-
error!("ML-DSA parameter set {} is not supported.", val);
1417+
error!("ML-DSA parameter set {val} is not supported.");
14181418
Err(Error::NotSupported)
14191419
}
14201420
}
@@ -1657,7 +1657,7 @@ impl TryFrom<CK_OBJECT_CLASS> for ObjectClass {
16571657
CKO_VALIDATION => Ok(ObjectClass::VALIDATION),
16581658

16591659
_ => {
1660-
error!("Object class {} is not supported.", object_class);
1660+
error!("Object class {object_class} is not supported.");
16611661
Err(Error::NotSupported)
16621662
}
16631663
}
@@ -1957,7 +1957,7 @@ impl TryFrom<CK_KEY_TYPE> for KeyType {
19571957
CKK_SLH_DSA => Ok(KeyType::SLH_DSA),
19581958
CKK_VENDOR_DEFINED..=CK_ULONG::MAX => KeyType::new_vendor_defined(key_type),
19591959
_ => {
1960-
error!("Key type {} is not supported.", key_type);
1960+
error!("Key type {key_type} is not supported.");
19611961
Err(Error::NotSupported)
19621962
}
19631963
}
@@ -2033,7 +2033,7 @@ impl TryFrom<CK_CERTIFICATE_TYPE> for CertificateType {
20332033
CKC_X_509_ATTR_CERT => Ok(CertificateType::X_509_ATTR),
20342034
CKC_WTLS => Ok(CertificateType::WTLS),
20352035
_ => {
2036-
error!("Certificate type {} is not supported.", certificate_type);
2036+
error!("Certificate type {certificate_type} is not supported.");
20372037
Err(Error::NotSupported)
20382038
}
20392039
}

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)