@@ -7,6 +7,7 @@ use cryptoki_sys::*;
77use std:: fmt:: { Debug , Formatter } ;
88
99bitflags ! {
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 ) ]
4248pub 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) ]
303310mod 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) ;
0 commit comments