@@ -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 ;
@@ -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 ) ]
4046pub 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) ]
287294mod 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) ;
0 commit comments