@@ -6,7 +6,7 @@ use crate::error::{Error, Result};
66use crate :: mechanism:: MechanismType ;
77use crate :: types:: { Date , Ulong } ;
88use cryptoki_sys:: * ;
9- use log:: error;
9+ use log:: { error, warn } ;
1010use std:: convert:: TryFrom ;
1111use std:: convert:: TryInto ;
1212use std:: ffi:: c_void;
@@ -136,6 +136,8 @@ pub enum AttributeType {
136136 Wrap ,
137137 /// Indicates that the key can only be wrapped with a wrapping key that has the Trusted attribute
138138 WrapWithTrusted ,
139+ /// Wraps undefined and custom attribute types.
140+ Unhandled ( CK_ATTRIBUTE_TYPE ) ,
139141}
140142
141143impl AttributeType {
@@ -328,6 +330,7 @@ impl From<AttributeType> for CK_ATTRIBUTE_TYPE {
328330 AttributeType :: VerifyRecover => CKA_VERIFY_RECOVER ,
329331 AttributeType :: Wrap => CKA_WRAP ,
330332 AttributeType :: WrapWithTrusted => CKA_WRAP_WITH_TRUSTED ,
333+ AttributeType :: Unhandled ( attr_type) => attr_type,
331334 }
332335 }
333336}
@@ -397,8 +400,10 @@ impl TryFrom<CK_ATTRIBUTE_TYPE> for AttributeType {
397400 CKA_WRAP => Ok ( AttributeType :: Wrap ) ,
398401 CKA_WRAP_WITH_TRUSTED => Ok ( AttributeType :: WrapWithTrusted ) ,
399402 attr_type => {
400- error ! ( "Attribute type {} not supported." , attr_type) ;
401- Err ( Error :: NotSupported )
403+ // error!("Attribute type {} not supported.", attr_type);
404+ // Err(Error::NotSupported)
405+ warn ! ( "Unhandled attribute type {} detected." , attr_type) ;
406+ Ok ( AttributeType :: Unhandled ( attr_type) )
402407 }
403408 }
404409 }
@@ -526,6 +531,8 @@ pub enum Attribute {
526531 Wrap ( bool ) ,
527532 /// Indicates that the key can only be wrapped with a wrapping key that has the Trusted attribute
528533 WrapWithTrusted ( bool ) ,
534+ /// Not defined attributes enter this option.
535+ Unhandled ( CK_ATTRIBUTE_TYPE , Vec < u8 > ) ,
529536}
530537
531538impl Attribute {
@@ -591,6 +598,9 @@ impl Attribute {
591598 Attribute :: VerifyRecover ( _) => AttributeType :: VerifyRecover ,
592599 Attribute :: Wrap ( _) => AttributeType :: Wrap ,
593600 Attribute :: WrapWithTrusted ( _) => AttributeType :: WrapWithTrusted ,
601+ Attribute :: Unhandled ( attribute_type, _) => {
602+ AttributeType :: Unhandled ( attribute_type. clone ( ) )
603+ }
594604 }
595605 }
596606
@@ -658,6 +668,7 @@ impl Attribute {
658668 Attribute :: AllowedMechanisms ( mechanisms) => {
659669 size_of :: < CK_MECHANISM_TYPE > ( ) * mechanisms. len ( )
660670 }
671+ Attribute :: Unhandled ( _, bytes) => bytes. len ( ) ,
661672 }
662673 }
663674
@@ -730,7 +741,8 @@ impl Attribute {
730741 | Attribute :: Subject ( bytes)
731742 | Attribute :: Url ( bytes)
732743 | Attribute :: Value ( bytes)
733- | Attribute :: Id ( bytes) => bytes. as_ptr ( ) as * mut c_void ,
744+ | Attribute :: Id ( bytes)
745+ | Attribute :: Unhandled ( _, bytes) => bytes. as_ptr ( ) as * mut c_void ,
734746 // Unique types
735747 Attribute :: CertificateType ( certificate_type) => {
736748 certificate_type as * const _ as * mut c_void
@@ -930,6 +942,7 @@ impl TryFrom<CK_ATTRIBUTE> for Attribute {
930942 }
931943 }
932944 }
945+ AttributeType :: Unhandled ( _) => todo ! ( ) ,
933946 }
934947 }
935948}
@@ -1006,6 +1019,8 @@ impl ObjectClass {
10061019 pub const MECHANISM : ObjectClass = ObjectClass { val : CKO_MECHANISM } ;
10071020 /// An OTP key object
10081021 pub const OTP_KEY : ObjectClass = ObjectClass { val : CKO_OTP_KEY } ;
1022+ /// A profile object
1023+ pub const PROFILE : ObjectClass = ObjectClass { val : CKO_PROFILE } ;
10091024
10101025 pub ( crate ) fn stringify ( class : CK_OBJECT_CLASS ) -> String {
10111026 match class {
@@ -1018,6 +1033,7 @@ impl ObjectClass {
10181033 CKO_DOMAIN_PARAMETERS => String :: from ( stringify ! ( CKO_DOMAIN_PARAMETERS ) ) ,
10191034 CKO_MECHANISM => String :: from ( stringify ! ( CKO_MECHANISM ) ) ,
10201035 CKO_OTP_KEY => String :: from ( stringify ! ( CKO_OTP_KEY ) ) ,
1036+ CKO_PROFILE => String :: from ( stringify ! ( CKO_PROFILE ) ) ,
10211037 _ => format ! ( "unknown ({class:08x})" ) ,
10221038 }
10231039 }
0 commit comments