Skip to content

Commit 28b92e4

Browse files
committed
fixup import
Signed-off-by: Arthur Gautier <[email protected]>
1 parent 3dd1430 commit 28b92e4

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

cryptoki-rustcrypto/src/ecdsa.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ use ecdsa::{
1717
point::PointCompression,
1818
sec1::{FromEncodedPoint, ModulusSize, ToEncodedPoint},
1919
subtle::CtOption,
20-
AffinePoint, CurveArithmetic, FieldBytesSize, PublicKey, Scalar,
20+
AffinePoint, CurveArithmetic, FieldBytesSize, PublicKey, Scalar, SecretKey,
2121
},
2222
hazmat::{DigestPrimitive, SignPrimitive},
23-
PrimeCurve, Signature, SignatureSize, SigningKey, VerifyingKey,
23+
PrimeCurve, Signature, SignatureSize, VerifyingKey,
2424
};
2525
use signature::{digest::Digest, DigestSigner};
2626
use spki::{
@@ -73,7 +73,7 @@ where
7373
}
7474
}
7575

76-
impl<C> CryptokiImport for SigningKey<C>
76+
impl<C> CryptokiImport for SecretKey<C>
7777
where
7878
C: PrimeCurve + CurveArithmetic,
7979
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
@@ -98,7 +98,7 @@ where
9898
}
9999
}
100100

101-
impl<C> CryptokiImport for VerifyingKey<C>
101+
impl<C> CryptokiImport for PublicKey<C>
102102
where
103103
C: PrimeCurve + CurveArithmetic + PointCompression,
104104
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,

cryptoki-rustcrypto/src/rsa/mod.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
};
1111
use der::oid::AssociatedOid;
12-
use rsa::{BigUint, RsaPublicKey};
12+
use rsa::{traits::PublicKeyParts, BigUint, RsaPublicKey};
1313
use signature::digest::Digest;
1414
use std::convert::TryInto;
1515
use thiserror::Error;
1616

17-
use crate::SessionLike;
17+
use crate::{CryptokiImport, SessionLike};
1818

1919
pub mod pkcs1v15;
2020
pub 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

Comments
 (0)