summaryrefslogtreecommitdiff
path: root/ext/node/ops
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-04-29 19:16:38 +0530
committerGitHub <noreply@github.com>2024-04-29 19:16:38 +0530
commitb02ffec37c73be8a73b95b33b32efa693e84e01b (patch)
tree6bdcda1ee6e6e7d1b63d05320fe2236dfa86999b /ext/node/ops
parent7d937045910968fbb2c050e803d79bc1c1e5984b (diff)
fix(ext/node): exporting rsa public keys (#23596)
Initial support for exporting rsa public KeyObject. Current assumption is that RSA keys are stored in pkcs1 der format in key storage. Ref https://github.com/denoland/deno/issues/23471 Ref https://github.com/denoland/deno/issues/18928 Ref https://github.com/denoland/deno/issues/21124
Diffstat (limited to 'ext/node/ops')
-rw-r--r--ext/node/ops/crypto/mod.rs22
1 files changed, 21 insertions, 1 deletions
diff --git a/ext/node/ops/crypto/mod.rs b/ext/node/ops/crypto/mod.rs
index ed1b7fc75..f39fb6d10 100644
--- a/ext/node/ops/crypto/mod.rs
+++ b/ext/node/ops/crypto/mod.rs
@@ -42,6 +42,7 @@ use rsa::Oaep;
use rsa::Pkcs1v15Encrypt;
use rsa::RsaPrivateKey;
use rsa::RsaPublicKey;
+use spki::EncodePublicKey;
mod cipher;
mod dh;
@@ -681,13 +682,32 @@ pub async fn op_node_generate_rsa_async(
spawn_blocking(move || generate_rsa(modulus_length, public_exponent)).await?
}
+#[op2]
+#[string]
+pub fn op_node_export_rsa_public_pem(
+ #[buffer] pkcs1_der: &[u8],
+) -> Result<String, AnyError> {
+ let public_key = RsaPublicKey::from_pkcs1_der(pkcs1_der)?;
+ let export = public_key.to_public_key_pem(Default::default())?;
+ Ok(export)
+}
+
+#[op2]
+#[serde]
+pub fn op_node_export_rsa_spki_der(
+ #[buffer] pkcs1_der: &[u8],
+) -> Result<ToJsBuffer, AnyError> {
+ let public_key = RsaPublicKey::from_pkcs1_der(pkcs1_der)?;
+ let export = public_key.to_public_key_der()?.to_vec();
+ Ok(export.into())
+}
+
fn dsa_generate(
modulus_length: usize,
divisor_length: usize,
) -> Result<(ToJsBuffer, ToJsBuffer), AnyError> {
let mut rng = rand::thread_rng();
use dsa::pkcs8::EncodePrivateKey;
- use dsa::pkcs8::EncodePublicKey;
use dsa::Components;
use dsa::KeySize;
use dsa::SigningKey;