@@ -10,9 +10,10 @@ use picky_asn1_x509::RSAPublicKey;
10
10
use serde:: { Deserialize , Serialize } ;
11
11
use std:: convert:: TryInto ;
12
12
use tss_esapi:: abstraction:: transient:: KeyParams ;
13
- use tss_esapi:: response_code :: { Error , Tss2ResponseCodeKind } ;
14
- use tss_esapi:: utils :: algorithm_specifiers :: { EllipticCurve , HashingAlgorithm } ;
13
+ use tss_esapi:: constants :: algorithm :: { EllipticCurve , HashingAlgorithm } ;
14
+ use tss_esapi:: constants :: response_code :: Tss2ResponseCodeKind ;
15
15
use tss_esapi:: utils:: { AsymSchemeUnion , PublicKey , Signature , SignatureData , TpmsContext } ;
16
+ use tss_esapi:: Error ;
16
17
use zeroize:: Zeroizing ;
17
18
const PUBLIC_EXPONENT : [ u8 ; 3 ] = [ 0x01 , 0x00 , 0x01 ] ;
18
19
@@ -99,11 +100,20 @@ pub fn parsec_to_tpm_params(attributes: Attributes) -> Result<KeyParams> {
99
100
x @ 1024 | x @ 2048 | x @ 3072 | x @ 4096 => x. try_into ( ) . unwrap ( ) , // will not fail on the matched values
100
101
_ => return Err ( ResponseStatus :: PsaErrorInvalidArgument ) ,
101
102
} ;
102
- Ok ( KeyParams :: Rsa {
103
- size,
104
- scheme : convert_asym_scheme_to_tpm ( attributes. policy . permitted_algorithms ) ?,
105
- pub_exponent : 0 ,
106
- } )
103
+ if attributes. is_encrypt_permitted ( ) || attributes. is_decrypt_permitted ( ) {
104
+ Ok ( KeyParams :: RsaEncrypt {
105
+ size,
106
+ pub_exponent : 0 ,
107
+ } )
108
+ } else if attributes. is_hash_signable ( ) || attributes. is_hash_verifiable ( ) {
109
+ Ok ( KeyParams :: RsaSign {
110
+ size,
111
+ scheme : convert_asym_scheme_to_tpm ( attributes. policy . permitted_algorithms ) ?,
112
+ pub_exponent : 0 ,
113
+ } )
114
+ } else {
115
+ Err ( ResponseStatus :: PsaErrorNotSupported )
116
+ }
107
117
}
108
118
Type :: EccKeyPair { .. } => Ok ( KeyParams :: Ecc {
109
119
scheme : convert_asym_scheme_to_tpm ( attributes. policy . permitted_algorithms ) ?,
0 commit comments