Skip to content

Commit ecc399e

Browse files
committed
WIP: update RSA traits after updating to 0.6.0
Signed-off-by: alt3r 3go <alt3r.3go@proton.me>
1 parent 921b5b7 commit ecc399e

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ des = { version = "0.7", optional = true }
3535
hmac = "0.11"
3636
sha-1 = { version = "0.9", default-features = false, optional = true }
3737
sha2 = { version = "0.9", default-features = false }
38-
rsa = { version = "0.5.0", optional = true }
38+
rsa = { version = "0.6.0", optional = true }
3939

4040
# ours
4141
cosey = "0.3"

src/mechanisms/rsa2kpkcs.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rsa::{
22
RsaPrivateKey,
33
RsaPublicKey,
44
PublicKey,
5-
pkcs8::{FromPrivateKey, ToPrivateKey, ToPublicKey}
5+
pkcs8::{EncodePrivateKey, DecodePrivateKey, EncodePublicKey}
66
};
77

88
use crate::api::*;
@@ -12,6 +12,10 @@ use crate::error::Error;
1212
use crate::service::*;
1313
use crate::types::*;
1414

15+
//TODO:alt3r-3go: sign() and verify() are the only two methods that are actually different between -pkcs and -pss.
16+
// Moreover, the key::Kind::Rsa2K could also probably be parametrized, instead of having a dedicated kind
17+
// for each. Overall this means the class structure can probably be simplified - need to decide.
18+
1519
#[cfg(feature = "rsa2k-pkcs")]
1620
impl DeriveKey for super::Rsa2kPkcs
1721
{
@@ -31,7 +35,7 @@ impl DeriveKey for super::Rsa2kPkcs
3135
// std::println!("Loaded key material: {}", delog::hex_str!(&priv_key_der));
3236
// std::println!("Key material length is {}", priv_key_der.len());
3337

34-
let priv_key = FromPrivateKey::from_pkcs8_der(&priv_key_der)
38+
let priv_key = DecodePrivateKey::from_pkcs8_der(&priv_key_der)
3539
.expect("Failed to deserialize an RSA 2K private key from PKCS#8 DER");
3640

3741
// Derive and store public key
@@ -66,7 +70,7 @@ impl DeserializeKey for super::Rsa2kPkcs
6670
return Err(Error::InternalError);
6771
}
6872

69-
let private_key: RsaPrivateKey = FromPrivateKey::from_pkcs8_der(&request.serialized_key)
73+
let private_key: RsaPrivateKey = DecodePrivateKey::from_pkcs8_der(&request.serialized_key)
7074
.map_err(|_| Error::InvalidSerializedKey)?;
7175

7276
// We store our keys in PKCS#8 DER format as well
@@ -180,7 +184,7 @@ impl Sign for super::Rsa2kPkcs
180184
.expect("Failed to load an RSA 2K private key with the given ID")
181185
.material;
182186

183-
let priv_key: RsaPrivateKey = FromPrivateKey::from_pkcs8_der(&priv_key_der)
187+
let priv_key: RsaPrivateKey = DecodePrivateKey::from_pkcs8_der(&priv_key_der)
184188
.expect("Failed to deserialize an RSA 2K private key from PKCS#8 DER");
185189

186190
// RSA lib takes in a hash value to sign, not raw data.
@@ -230,7 +234,7 @@ impl Verify for super::Rsa2kPkcs
230234
.expect("Failed to load an RSA 2K private key with the given ID")
231235
.material;
232236

233-
let priv_key = FromPrivateKey::from_pkcs8_der(&priv_key_der)
237+
let priv_key = DecodePrivateKey::from_pkcs8_der(&priv_key_der)
234238
.expect("Failed to deserialize an RSA 2K private key from PKCS#8 DER");
235239

236240
// Get the public key

0 commit comments

Comments
 (0)