Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update rsa to 0.9. #106

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ucan-key-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async-trait = "0.1"
bs58 = "0.5"
ed25519-zebra = "3.1"
log = "0.4"
rsa = "0.8"
rsa = "0.9"
p256 = "0.13"
sha2 = { version = "0.10", features = ["oid"] }
ucan = { path = "../ucan", version = "0.3.2" }
Expand Down
9 changes: 4 additions & 5 deletions ucan-key-support/src/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use anyhow::{anyhow, Result};
use async_trait::async_trait;

use rsa::{
pkcs1::{der::Encode, DecodeRsaPublicKey, EncodeRsaPublicKey},
Pkcs1v15Sign, PublicKey, RsaPrivateKey, RsaPublicKey,
pkcs1::{DecodeRsaPublicKey, EncodeRsaPublicKey},
Pkcs1v15Sign, RsaPrivateKey, RsaPublicKey,
};

use sha2::{Digest, Sha256};
Expand All @@ -12,10 +12,9 @@ use ucan::crypto::{JwtSignatureAlgorithm, KeyMaterial};
pub use ucan::crypto::did::RSA_MAGIC_BYTES;

pub fn bytes_to_rsa_key(bytes: Vec<u8>) -> Result<Box<dyn KeyMaterial>> {
// NOTE: DID bytes are PKCS1, but we are using PKCS8, so do the conversion here..
println!("Trying to parse RSA key...");
let public_key = rsa::pkcs1::RsaPublicKey::try_from(bytes.as_slice())?;
let public_key = RsaPublicKey::from_pkcs1_der(&public_key.to_vec()?)?;
// NOTE: DID bytes are PKCS1, but we store RSA keys as PKCS8
let public_key = RsaPublicKey::from_pkcs1_der(&bytes)?;

Ok(Box::new(RsaKeyMaterial(public_key, None)))
}
Expand Down
9 changes: 2 additions & 7 deletions ucan-key-support/src/web_crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ use crate::rsa::RsaKeyMaterial;
use anyhow::{anyhow, Result};
use async_trait::async_trait;
use js_sys::{Array, ArrayBuffer, Boolean, Object, Reflect, Uint8Array};
use rsa::{
pkcs1::{der::Encode, DecodeRsaPublicKey},
RsaPublicKey,
};
use rsa::{pkcs1::DecodeRsaPublicKey, RsaPublicKey};
use ucan::crypto::{JwtSignatureAlgorithm, KeyMaterial};
use wasm_bindgen::{JsCast, JsValue};
use wasm_bindgen_futures::JsFuture;
Expand Down Expand Up @@ -129,9 +126,7 @@ impl KeyMaterial for WebCryptoRsaKeyMaterial {

let public_key_bytes = public_key_bytes.to_vec();
let public_key_bytes = convert_spki_to_rsa_public_key(public_key_bytes.as_slice())?;

let public_key = rsa::pkcs1::RsaPublicKey::try_from(public_key_bytes.as_slice())?;
let public_key = RsaPublicKey::from_pkcs1_der(&public_key.to_vec()?)?;
let public_key = RsaPublicKey::from_pkcs1_der(&public_key_bytes)?;

Ok(RsaKeyMaterial(public_key, None).get_did().await?)
}
Expand Down