@@ -14,6 +14,8 @@ use std::fmt::Formatter;
14
14
use std:: mem:: size_of;
15
15
use std:: ops:: Deref ;
16
16
17
+ const MAX_CU_ULONG : CK_ULONG = !0 ;
18
+
17
19
#[ derive( Debug , Copy , Clone , Ord , PartialOrd , Eq , PartialEq , Hash ) ]
18
20
#[ non_exhaustive]
19
21
/// Type of an attribute
@@ -128,6 +130,8 @@ pub enum AttributeType {
128
130
Value ,
129
131
/// Length in bytes of the value
130
132
ValueLen ,
133
+ /// Vendor defined attribute
134
+ VendorDefined ( CK_ATTRIBUTE_TYPE ) ,
131
135
/// Determines if a key supports verifying
132
136
Verify ,
133
137
/// Determines if a key supports verifying where the data can be recovered from the signature
@@ -254,6 +258,9 @@ impl AttributeType {
254
258
CKA_UNWRAP_TEMPLATE => String :: from ( stringify ! ( CKA_UNWRAP_TEMPLATE ) ) ,
255
259
CKA_DERIVE_TEMPLATE => String :: from ( stringify ! ( CKA_DERIVE_TEMPLATE ) ) ,
256
260
CKA_ALLOWED_MECHANISMS => String :: from ( stringify ! ( CKA_ALLOWED_MECHANISMS ) ) ,
261
+ CKA_VENDOR_DEFINED ..=MAX_CU_ULONG => {
262
+ format ! ( "{}_{}" , stringify!( CKA_VENDOR_DEFINED ) , val)
263
+ }
257
264
_ => format ! ( "unknown ({val:08x})" ) ,
258
265
}
259
266
}
@@ -324,6 +331,7 @@ impl From<AttributeType> for CK_ATTRIBUTE_TYPE {
324
331
AttributeType :: Url => CKA_URL ,
325
332
AttributeType :: Value => CKA_VALUE ,
326
333
AttributeType :: ValueLen => CKA_VALUE_LEN ,
334
+ AttributeType :: VendorDefined ( val) => val,
327
335
AttributeType :: Verify => CKA_VERIFY ,
328
336
AttributeType :: VerifyRecover => CKA_VERIFY_RECOVER ,
329
337
AttributeType :: Wrap => CKA_WRAP ,
@@ -396,6 +404,7 @@ impl TryFrom<CK_ATTRIBUTE_TYPE> for AttributeType {
396
404
CKA_VERIFY_RECOVER => Ok ( AttributeType :: VerifyRecover ) ,
397
405
CKA_WRAP => Ok ( AttributeType :: Wrap ) ,
398
406
CKA_WRAP_WITH_TRUSTED => Ok ( AttributeType :: WrapWithTrusted ) ,
407
+ CKA_VENDOR_DEFINED ..=MAX_CU_ULONG => Ok ( AttributeType :: VendorDefined ( attribute_type) ) ,
399
408
attr_type => {
400
409
error ! ( "Attribute type {} not supported." , attr_type) ;
401
410
Err ( Error :: NotSupported )
@@ -518,6 +527,8 @@ pub enum Attribute {
518
527
Value ( Vec < u8 > ) ,
519
528
/// Length in bytes of the value
520
529
ValueLen ( Ulong ) ,
530
+ /// Vendor defined value
531
+ VendorDefined ( ( AttributeType , Vec < u8 > ) ) ,
521
532
/// Determines if a key supports verifying
522
533
Verify ( bool ) ,
523
534
/// Determines if a key supports verifying where the data can be recovered from the signature
@@ -587,6 +598,7 @@ impl Attribute {
587
598
Attribute :: Url ( _) => AttributeType :: Url ,
588
599
Attribute :: Value ( _) => AttributeType :: Value ,
589
600
Attribute :: ValueLen ( _) => AttributeType :: ValueLen ,
601
+ Attribute :: VendorDefined ( ( num, _) ) => * num,
590
602
Attribute :: Verify ( _) => AttributeType :: Verify ,
591
603
Attribute :: VerifyRecover ( _) => AttributeType :: VerifyRecover ,
592
604
Attribute :: Wrap ( _) => AttributeType :: Wrap ,
@@ -658,6 +670,7 @@ impl Attribute {
658
670
Attribute :: AllowedMechanisms ( mechanisms) => {
659
671
size_of :: < CK_MECHANISM_TYPE > ( ) * mechanisms. len ( )
660
672
}
673
+ Attribute :: VendorDefined ( ( _, bytes) ) => bytes. len ( ) ,
661
674
}
662
675
}
663
676
@@ -730,6 +743,7 @@ impl Attribute {
730
743
| Attribute :: Subject ( bytes)
731
744
| Attribute :: Url ( bytes)
732
745
| Attribute :: Value ( bytes)
746
+ | Attribute :: VendorDefined ( ( _, bytes) )
733
747
| Attribute :: Id ( bytes) => bytes. as_ptr ( ) as * mut c_void ,
734
748
// Unique types
735
749
Attribute :: CertificateType ( certificate_type) => {
@@ -930,6 +944,10 @@ impl TryFrom<CK_ATTRIBUTE> for Attribute {
930
944
}
931
945
}
932
946
}
947
+ AttributeType :: VendorDefined ( t) => Ok ( Attribute :: VendorDefined ( (
948
+ AttributeType :: VendorDefined ( t) ,
949
+ val. to_vec ( ) ,
950
+ ) ) ) ,
933
951
}
934
952
}
935
953
}
0 commit comments