@@ -6,15 +6,15 @@ use cryptoki::{
66 rsa:: { PkcsMgfType , PkcsPssParams } ,
77 Mechanism , MechanismType ,
88 } ,
9- object:: { Attribute , AttributeType , KeyType , ObjectClass } ,
9+ object:: { Attribute , AttributeType , KeyType , ObjectClass , ObjectHandle } ,
1010} ;
1111use der:: oid:: AssociatedOid ;
12- use rsa:: { BigUint , RsaPublicKey } ;
12+ use rsa:: { traits :: PublicKeyParts , BigUint , RsaPublicKey } ;
1313use signature:: digest:: Digest ;
1414use std:: convert:: TryInto ;
1515use thiserror:: Error ;
1616
17- use crate :: SessionLike ;
17+ use crate :: { CryptokiImport , SessionLike } ;
1818
1919pub mod pkcs1v15;
2020pub mod pss;
@@ -126,3 +126,21 @@ impl_digest_signing!(
126126 SHA512 ,
127127 MGF1_SHA512
128128) ;
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