@@ -110,6 +110,8 @@ pub enum AttributeType {
110
110
PublicExponent ,
111
111
/// DER-encoding of the SubjectPublicKeyInfo
112
112
PublicKeyInfo ,
113
+ /// Profile ID
114
+ ProfileId ,
113
115
/// Seed to derive private key
114
116
Seed ,
115
117
/// Determines if the key is sensitive
@@ -269,6 +271,7 @@ impl AttributeType {
269
271
CKA_UNIQUE_ID => String :: from ( stringify ! ( CKA_UNIQUE_ID ) ) ,
270
272
CKA_SEED => String :: from ( stringify ! ( CKA_SEED ) ) ,
271
273
CKA_PARAMETER_SET => String :: from ( stringify ! ( CKA_PARAMETER_SET ) ) ,
274
+ CKA_PROFILE_ID => String :: from ( stringify ! ( CKA_PROFILE_ID ) ) ,
272
275
CKA_VENDOR_DEFINED ..=CK_ULONG :: MAX => {
273
276
format ! ( "{}_{}" , stringify!( CKA_VENDOR_DEFINED ) , val)
274
277
}
@@ -331,6 +334,7 @@ impl From<AttributeType> for CK_ATTRIBUTE_TYPE {
331
334
AttributeType :: Prime2 => CKA_PRIME_2 ,
332
335
AttributeType :: Private => CKA_PRIVATE ,
333
336
AttributeType :: PrivateExponent => CKA_PRIVATE_EXPONENT ,
337
+ AttributeType :: ProfileId => CKA_PROFILE_ID ,
334
338
AttributeType :: PublicExponent => CKA_PUBLIC_EXPONENT ,
335
339
AttributeType :: PublicKeyInfo => CKA_PUBLIC_KEY_INFO ,
336
340
AttributeType :: Seed => CKA_SEED ,
@@ -405,6 +409,7 @@ impl TryFrom<CK_ATTRIBUTE_TYPE> for AttributeType {
405
409
CKA_PRIME_2 => Ok ( AttributeType :: Prime2 ) ,
406
410
CKA_PRIVATE => Ok ( AttributeType :: Private ) ,
407
411
CKA_PRIVATE_EXPONENT => Ok ( AttributeType :: PrivateExponent ) ,
412
+ CKA_PROFILE_ID => Ok ( AttributeType :: ProfileId ) ,
408
413
CKA_PUBLIC_EXPONENT => Ok ( AttributeType :: PublicExponent ) ,
409
414
CKA_PUBLIC_KEY_INFO => Ok ( AttributeType :: PublicKeyInfo ) ,
410
415
CKA_SEED => Ok ( AttributeType :: Seed ) ,
@@ -526,6 +531,8 @@ pub enum Attribute {
526
531
Private ( bool ) ,
527
532
/// The private exponent `d`
528
533
PrivateExponent ( Vec < u8 > ) ,
534
+ /// The Profile ID
535
+ ProfileId ( ProfileIdType ) ,
529
536
/// Public exponent value of a key
530
537
PublicExponent ( Vec < u8 > ) ,
531
538
/// DER-encoding of the SubjectPublicKeyInfo
@@ -618,6 +625,7 @@ impl Attribute {
618
625
Attribute :: Prime2 ( _) => AttributeType :: Prime2 ,
619
626
Attribute :: Private ( _) => AttributeType :: Private ,
620
627
Attribute :: PrivateExponent ( _) => AttributeType :: PrivateExponent ,
628
+ Attribute :: ProfileId ( _) => AttributeType :: ProfileId ,
621
629
Attribute :: PublicExponent ( _) => AttributeType :: PublicExponent ,
622
630
Attribute :: PublicKeyInfo ( _) => AttributeType :: PublicKeyInfo ,
623
631
Attribute :: Seed ( _) => AttributeType :: Seed ,
@@ -698,6 +706,7 @@ impl Attribute {
698
706
Attribute :: Prime1 ( bytes) => bytes. len ( ) ,
699
707
Attribute :: Prime2 ( bytes) => bytes. len ( ) ,
700
708
Attribute :: PrivateExponent ( bytes) => bytes. len ( ) ,
709
+ Attribute :: ProfileId ( _) => size_of :: < CK_PROFILE_ID > ( ) ,
701
710
Attribute :: PublicExponent ( bytes) => bytes. len ( ) ,
702
711
Attribute :: PublicKeyInfo ( bytes) => bytes. len ( ) ,
703
712
Attribute :: Seed ( bytes) => bytes. len ( ) ,
@@ -792,6 +801,7 @@ impl Attribute {
792
801
| Attribute :: Id ( bytes) => bytes. as_ptr ( ) as * mut c_void ,
793
802
// Unique types
794
803
Attribute :: ParameterSet ( val) => val as * const _ as * mut c_void ,
804
+ Attribute :: ProfileId ( val) => val as * const _ as * mut c_void ,
795
805
Attribute :: CertificateType ( certificate_type) => {
796
806
certificate_type as * const _ as * mut c_void
797
807
}
@@ -922,6 +932,9 @@ impl TryFrom<CK_ATTRIBUTE> for Attribute {
922
932
AttributeType :: Value => Ok ( Attribute :: Value ( val. to_vec ( ) ) ) ,
923
933
AttributeType :: Id => Ok ( Attribute :: Id ( val. to_vec ( ) ) ) ,
924
934
// Unique types
935
+ AttributeType :: ProfileId => Ok ( Attribute :: ProfileId ( ProfileIdType {
936
+ val : CK_ULONG :: from_ne_bytes ( val. try_into ( ) ?) . into ( ) ,
937
+ } ) ) ,
925
938
AttributeType :: ParameterSet => Ok ( Attribute :: ParameterSet ( ParameterSetType {
926
939
val : CK_ULONG :: from_ne_bytes ( val. try_into ( ) ?) . into ( ) ,
927
940
} ) ) ,
@@ -1716,3 +1729,80 @@ impl TryFrom<CK_CERTIFICATE_TYPE> for CertificateType {
1716
1729
}
1717
1730
}
1718
1731
}
1732
+
1733
+ #[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
1734
+ #[ repr( transparent) ]
1735
+ /// The PKCS#11 Profile ID
1736
+ ///
1737
+ /// The profiles and their meaning is defined in the following document:
1738
+ ///
1739
+ /// https://docs.oasis-open.org/pkcs11/pkcs11-profiles/v3.1/os/pkcs11-profiles-v3.1-os.html
1740
+ pub struct ProfileIdType {
1741
+ val : CK_PROFILE_ID ,
1742
+ }
1743
+
1744
+ impl ProfileIdType {
1745
+ /// Baseline Provider
1746
+ pub const BASELINE_PROFIDER : ProfileIdType = ProfileIdType { val : CKP_BASELINE_PROVIDER } ;
1747
+ /// Extended Provider
1748
+ pub const EXTENDED_PROFIDER : ProfileIdType = ProfileIdType { val : CKP_EXTENDED_PROVIDER } ;
1749
+ /// Authentication Token Provider or Consumer
1750
+ pub const AUTHENTICATION_TOKEN : ProfileIdType = ProfileIdType { val : CKP_AUTHENTICATION_TOKEN } ;
1751
+ /// Public Certificates Token Provider or Consumer
1752
+ pub const PUBLIC_CERTIFICATES_TOKEN : ProfileIdType = ProfileIdType { val : CKP_PUBLIC_CERTIFICATES_TOKEN } ;
1753
+ /// Complete Provider
1754
+ pub const COMPLETE_PROVIDER : ProfileIdType = ProfileIdType { val : CKP_COMPLETE_PROVIDER } ;
1755
+ /// HKDF TLS Token
1756
+ pub const HKDF_TLS_TOKEN : ProfileIdType = ProfileIdType { val : CKP_HKDF_TLS_TOKEN } ;
1757
+
1758
+ pub ( crate ) fn stringify ( profile_id : CK_PROFILE_ID ) -> String {
1759
+ match profile_id {
1760
+ CKP_BASELINE_PROVIDER => String :: from ( stringify ! ( CKP_BASELINE_PROVIDER ) ) ,
1761
+ CKP_EXTENDED_PROVIDER => String :: from ( stringify ! ( CKP_EXTENDED_PROVIDER ) ) ,
1762
+ CKP_AUTHENTICATION_TOKEN => String :: from ( stringify ! ( CKP_AUTHENTICATION_TOKEN ) ) ,
1763
+ CKP_PUBLIC_CERTIFICATES_TOKEN => String :: from ( stringify ! ( CKP_PUBLIC_CERTIFICATES_TOKEN ) ) ,
1764
+ CKP_COMPLETE_PROVIDER => String :: from ( stringify ! ( CKP_COMPLETE_PROVIDER ) ) ,
1765
+ CKP_HKDF_TLS_TOKEN => String :: from ( stringify ! ( CKP_HKDF_TLS_TOKEN ) ) ,
1766
+ _ => format ! ( "unknown ({profile_id:08x})" ) ,
1767
+ }
1768
+ }
1769
+ }
1770
+
1771
+ impl std:: fmt:: Display for ProfileIdType {
1772
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
1773
+ write ! ( f, "{}" , ProfileIdType :: stringify( self . val) )
1774
+ }
1775
+ }
1776
+
1777
+ impl Deref for ProfileIdType {
1778
+ type Target = CK_PROFILE_ID ;
1779
+
1780
+ fn deref ( & self ) -> & Self :: Target {
1781
+ & self . val
1782
+ }
1783
+ }
1784
+
1785
+ impl From < ProfileIdType > for CK_PROFILE_ID {
1786
+ fn from ( profile_id : ProfileIdType ) -> Self {
1787
+ * profile_id
1788
+ }
1789
+ }
1790
+
1791
+ impl TryFrom < CK_PROFILE_ID > for ProfileIdType {
1792
+ type Error = Error ;
1793
+
1794
+ fn try_from ( profile_id : CK_PROFILE_ID ) -> Result < Self > {
1795
+ match profile_id {
1796
+ CKP_BASELINE_PROVIDER => Ok ( ProfileIdType :: BASELINE_PROFIDER ) ,
1797
+ CKP_EXTENDED_PROVIDER => Ok ( ProfileIdType :: EXTENDED_PROFIDER ) ,
1798
+ CKP_AUTHENTICATION_TOKEN => Ok ( ProfileIdType :: AUTHENTICATION_TOKEN ) ,
1799
+ CKP_PUBLIC_CERTIFICATES_TOKEN => Ok ( ProfileIdType :: PUBLIC_CERTIFICATES_TOKEN ) ,
1800
+ CKP_COMPLETE_PROVIDER => Ok ( ProfileIdType :: COMPLETE_PROVIDER ) ,
1801
+ CKP_HKDF_TLS_TOKEN => Ok ( ProfileIdType :: HKDF_TLS_TOKEN ) ,
1802
+ _ => {
1803
+ error ! ( "Profile Id {} is not supported." , profile_id) ;
1804
+ Err ( Error :: NotSupported )
1805
+ }
1806
+ }
1807
+ }
1808
+ }
0 commit comments