@@ -15,7 +15,6 @@ use std::mem::size_of;
15
15
use std:: ops:: Deref ;
16
16
17
17
#[ derive( Debug , Copy , Clone , Ord , PartialOrd , Eq , PartialEq , Hash ) ]
18
- #[ non_exhaustive]
19
18
/// Type of an attribute
20
19
pub enum AttributeType {
21
20
/// DER-encoding of the attribute certificate's issuer
@@ -128,6 +127,8 @@ pub enum AttributeType {
128
127
Value ,
129
128
/// Length in bytes of the value
130
129
ValueLen ,
130
+ /// Vendor defined attribute
131
+ VendorDefined ( CK_ATTRIBUTE_TYPE ) ,
131
132
/// Determines if a key supports verifying
132
133
Verify ,
133
134
/// Determines if a key supports verifying where the data can be recovered from the signature
@@ -254,6 +255,7 @@ impl AttributeType {
254
255
CKA_UNWRAP_TEMPLATE => String :: from ( stringify ! ( CKA_UNWRAP_TEMPLATE ) ) ,
255
256
CKA_DERIVE_TEMPLATE => String :: from ( stringify ! ( CKA_DERIVE_TEMPLATE ) ) ,
256
257
CKA_ALLOWED_MECHANISMS => String :: from ( stringify ! ( CKA_ALLOWED_MECHANISMS ) ) ,
258
+ CKA_VENDOR_DEFINED => String :: from ( stringify ! ( CKA_VENDOR_DEFINED ) ) ,
257
259
_ => format ! ( "unknown ({val:08x})" ) ,
258
260
}
259
261
}
@@ -324,6 +326,7 @@ impl From<AttributeType> for CK_ATTRIBUTE_TYPE {
324
326
AttributeType :: Url => CKA_URL ,
325
327
AttributeType :: Value => CKA_VALUE ,
326
328
AttributeType :: ValueLen => CKA_VALUE_LEN ,
329
+ AttributeType :: VendorDefined ( val) => val,
327
330
AttributeType :: Verify => CKA_VERIFY ,
328
331
AttributeType :: VerifyRecover => CKA_VERIFY_RECOVER ,
329
332
AttributeType :: Wrap => CKA_WRAP ,
@@ -396,6 +399,7 @@ impl TryFrom<CK_ATTRIBUTE_TYPE> for AttributeType {
396
399
CKA_VERIFY_RECOVER => Ok ( AttributeType :: VerifyRecover ) ,
397
400
CKA_WRAP => Ok ( AttributeType :: Wrap ) ,
398
401
CKA_WRAP_WITH_TRUSTED => Ok ( AttributeType :: WrapWithTrusted ) ,
402
+ 0x8000_0000 ..=0xffff_ffff => Ok ( AttributeType :: VendorDefined ( attribute_type) ) ,
399
403
attr_type => {
400
404
error ! ( "Attribute type {} not supported." , attr_type) ;
401
405
Err ( Error :: NotSupported )
@@ -405,7 +409,6 @@ impl TryFrom<CK_ATTRIBUTE_TYPE> for AttributeType {
405
409
}
406
410
407
411
#[ derive( Debug , Clone , PartialEq , Eq ) ]
408
- #[ non_exhaustive]
409
412
/// Attribute value
410
413
pub enum Attribute {
411
414
/// DER-encoding of the attribute certificate's issuer
@@ -518,6 +521,8 @@ pub enum Attribute {
518
521
Value ( Vec < u8 > ) ,
519
522
/// Length in bytes of the value
520
523
ValueLen ( Ulong ) ,
524
+ /// Vendor defined value
525
+ VendorDefined ( ( CK_ATTRIBUTE_TYPE , Vec < u8 > ) ) ,
521
526
/// Determines if a key supports verifying
522
527
Verify ( bool ) ,
523
528
/// Determines if a key supports verifying where the data can be recovered from the signature
@@ -587,6 +592,7 @@ impl Attribute {
587
592
Attribute :: Url ( _) => AttributeType :: Url ,
588
593
Attribute :: Value ( _) => AttributeType :: Value ,
589
594
Attribute :: ValueLen ( _) => AttributeType :: ValueLen ,
595
+ Attribute :: VendorDefined ( ( num, _) ) => AttributeType :: VendorDefined ( * num) ,
590
596
Attribute :: Verify ( _) => AttributeType :: Verify ,
591
597
Attribute :: VerifyRecover ( _) => AttributeType :: VerifyRecover ,
592
598
Attribute :: Wrap ( _) => AttributeType :: Wrap ,
@@ -658,6 +664,7 @@ impl Attribute {
658
664
Attribute :: AllowedMechanisms ( mechanisms) => {
659
665
size_of :: < CK_MECHANISM_TYPE > ( ) * mechanisms. len ( )
660
666
}
667
+ Attribute :: VendorDefined ( ( _, bytes) ) => bytes. len ( ) ,
661
668
}
662
669
}
663
670
@@ -730,6 +737,7 @@ impl Attribute {
730
737
| Attribute :: Subject ( bytes)
731
738
| Attribute :: Url ( bytes)
732
739
| Attribute :: Value ( bytes)
740
+ | Attribute :: VendorDefined ( ( _, bytes) )
733
741
| Attribute :: Id ( bytes) => bytes. as_ptr ( ) as * mut c_void ,
734
742
// Unique types
735
743
Attribute :: CertificateType ( certificate_type) => {
@@ -929,7 +937,8 @@ impl TryFrom<CK_ATTRIBUTE> for Attribute {
929
937
) ?) )
930
938
}
931
939
}
932
- }
940
+ } ,
941
+ AttributeType :: VendorDefined ( t) => Ok ( Attribute :: VendorDefined ( ( t, val. to_vec ( ) ) ) ) ,
933
942
}
934
943
}
935
944
}
0 commit comments