22// SPDX-License-Identifier: Apache-2.0
33
44use crate :: interface_types:: ecc:: EccCurve ;
5- use crate :: structures:: { Public , RsaExponent } ;
5+ use crate :: structures:: Public ;
66use crate :: utils:: PublicKey as TpmPublicKey ;
77use crate :: { Error , WrapperErrorKind } ;
88
@@ -18,11 +18,19 @@ use elliptic_curve::{
1818 FieldBytesSize ,
1919 PublicKey ,
2020} ;
21- use rsa:: { pkcs8:: EncodePublicKey , BigUint , RsaPublicKey } ;
21+
22+ #[ cfg( feature = "rustcrypto" ) ]
2223use x509_cert:: spki:: SubjectPublicKeyInfoOwned ;
2324
25+ #[ cfg( all( feature = "rustcrypto" , feature = "rsa" ) ) ]
26+ use {
27+ crate :: structures:: RsaExponent ,
28+ rsa:: { pkcs8:: EncodePublicKey , BigUint , RsaPublicKey } ,
29+ } ;
30+
2431/// Default exponent for RSA keys.
2532// Also known as 0x10001
33+ #[ cfg( all( feature = "rustcrypto" , feature = "rsa" ) ) ]
2634const RSA_DEFAULT_EXP : u64 = 65537 ;
2735
2836impl < C > TryFrom < & Public > for PublicKey < C >
6674 }
6775}
6876
77+ #[ cfg( all( feature = "rustcrypto" , feature = "rsa" ) ) ]
6978impl TryFrom < & Public > for RsaPublicKey {
7079 type Error = Error ;
7180
@@ -102,6 +111,7 @@ impl TryFrom<&Public> for SubjectPublicKeyInfoOwned {
102111 /// * if other instances of [`crate::structures::Public`] are used `UnsupportedParam` will be returned.
103112 fn try_from ( value : & Public ) -> Result < Self , Self :: Error > {
104113 match value {
114+ #[ cfg( all( feature = "rustcrypto" , feature = "rsa" ) ) ]
105115 Public :: Rsa { .. } => {
106116 let public_key = RsaPublicKey :: try_from ( value) ?;
107117
@@ -127,17 +137,17 @@ impl TryFrom<&Public> for SubjectPublicKeyInfoOwned {
127137 } ;
128138 }
129139
130- #[ cfg( feature = "p192" ) ]
140+ #[ cfg( all ( feature = "rustcrypto" , feature = " p192") ) ]
131141 read_key ! ( EccCurve :: NistP192 , p192:: NistP192 ) ;
132- #[ cfg( feature = "p224" ) ]
142+ #[ cfg( all ( feature = "rustcrypto" , feature = " p224") ) ]
133143 read_key ! ( EccCurve :: NistP224 , p224:: NistP224 ) ;
134- #[ cfg( feature = "p256" ) ]
144+ #[ cfg( all ( feature = "rustcrypto" , feature = " p256") ) ]
135145 read_key ! ( EccCurve :: NistP256 , p256:: NistP256 ) ;
136- #[ cfg( feature = "p384" ) ]
146+ #[ cfg( all ( feature = "rustcrypto" , feature = " p384") ) ]
137147 read_key ! ( EccCurve :: NistP384 , p384:: NistP384 ) ;
138- #[ cfg( feature = "p521" ) ]
148+ #[ cfg( all ( feature = "rustcrypto" , feature = " p521") ) ]
139149 read_key ! ( EccCurve :: NistP521 , p521:: NistP521 ) ;
140- #[ cfg( feature = "sm2" ) ]
150+ #[ cfg( all ( feature = "rustcrypto" , feature = " sm2") ) ]
141151 read_key ! ( EccCurve :: Sm2P256 , sm2:: Sm2 ) ;
142152
143153 Err ( Error :: local_error ( WrapperErrorKind :: UnsupportedParam ) )
@@ -182,6 +192,7 @@ where
182192 }
183193}
184194
195+ #[ cfg( all( feature = "rustcrypto" , feature = "rsa" ) ) ]
185196impl TryFrom < & TpmPublicKey > for RsaPublicKey {
186197 type Error = Error ;
187198
@@ -207,32 +218,32 @@ pub trait AssociatedTpmCurve {
207218 const TPM_CURVE : EccCurve ;
208219}
209220
210- #[ cfg( feature = "p192" ) ]
221+ #[ cfg( all ( feature = "rustcrypto" , feature = " p192") ) ]
211222impl AssociatedTpmCurve for p192:: NistP192 {
212223 const TPM_CURVE : EccCurve = EccCurve :: NistP192 ;
213224}
214225
215- #[ cfg( feature = "p224" ) ]
226+ #[ cfg( all ( feature = "rustcrypto" , feature = " p224") ) ]
216227impl AssociatedTpmCurve for p224:: NistP224 {
217228 const TPM_CURVE : EccCurve = EccCurve :: NistP224 ;
218229}
219230
220- #[ cfg( feature = "p256" ) ]
231+ #[ cfg( all ( feature = "rustcrypto" , feature = " p256") ) ]
221232impl AssociatedTpmCurve for p256:: NistP256 {
222233 const TPM_CURVE : EccCurve = EccCurve :: NistP256 ;
223234}
224235
225- #[ cfg( feature = "p384" ) ]
236+ #[ cfg( all ( feature = "rustcrypto" , feature = " p384") ) ]
226237impl AssociatedTpmCurve for p384:: NistP384 {
227238 const TPM_CURVE : EccCurve = EccCurve :: NistP384 ;
228239}
229240
230- #[ cfg( feature = "p521" ) ]
241+ #[ cfg( all ( feature = "rustcrypto" , feature = " p521") ) ]
231242impl AssociatedTpmCurve for p521:: NistP521 {
232243 const TPM_CURVE : EccCurve = EccCurve :: NistP521 ;
233244}
234245
235- #[ cfg( feature = "sm2" ) ]
246+ #[ cfg( all ( feature = "rustcrypto" , feature = " sm2") ) ]
236247impl AssociatedTpmCurve for sm2:: Sm2 {
237248 const TPM_CURVE : EccCurve = EccCurve :: Sm2P256 ;
238249}
0 commit comments