@@ -6,15 +6,15 @@ use cryptoki::{
6
6
rsa:: { PkcsMgfType , PkcsPssParams } ,
7
7
Mechanism , MechanismType ,
8
8
} ,
9
- object:: { Attribute , AttributeType , KeyType , ObjectClass } ,
9
+ object:: { Attribute , AttributeType , KeyType , ObjectClass , ObjectHandle } ,
10
10
} ;
11
11
use der:: oid:: AssociatedOid ;
12
- use rsa:: { BigUint , RsaPublicKey } ;
12
+ use rsa:: { traits :: PublicKeyParts , BigUint , RsaPublicKey } ;
13
13
use signature:: digest:: Digest ;
14
14
use std:: convert:: TryInto ;
15
15
use thiserror:: Error ;
16
16
17
- use crate :: SessionLike ;
17
+ use crate :: { CryptokiImport , SessionLike } ;
18
18
19
19
pub mod pkcs1v15;
20
20
pub mod pss;
@@ -126,3 +126,21 @@ impl_digest_signing!(
126
126
SHA512 ,
127
127
MGF1_SHA512
128
128
) ;
129
+
130
+ impl CryptokiImport for RsaPublicKey {
131
+ fn put_key < S : SessionLike > (
132
+ & self ,
133
+ session : & S ,
134
+ template : impl Into < Vec < Attribute > > ,
135
+ ) -> cryptoki:: error:: Result < ObjectHandle > {
136
+ let mut template = template. into ( ) ;
137
+ template. push ( Attribute :: Class ( ObjectClass :: PUBLIC_KEY ) ) ;
138
+ template. push ( Attribute :: KeyType ( KeyType :: RSA ) ) ;
139
+ template. push ( Attribute :: Modulus ( self . n ( ) . to_bytes_be ( ) ) ) ;
140
+ template. push ( Attribute :: PublicExponent ( self . e ( ) . to_bytes_be ( ) ) ) ;
141
+
142
+ let handle = session. create_object ( & template) ?;
143
+
144
+ Ok ( handle)
145
+ }
146
+ }
0 commit comments