From 3b62a58818f83e32fc2644f44e75a5c8465b2003 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Thu, 6 Apr 2023 18:39:25 +0530 Subject: fix(ext/node): add symmetric keygen (#18609) Towards #18455 --- ext/node/crypto/mod.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'ext/node/crypto/mod.rs') diff --git a/ext/node/crypto/mod.rs b/ext/node/crypto/mod.rs index 3529a3aa4..499e99fea 100644 --- a/ext/node/crypto/mod.rs +++ b/ext/node/crypto/mod.rs @@ -8,6 +8,7 @@ use deno_core::ResourceId; use deno_core::StringOrBuffer; use deno_core::ZeroCopyBuf; use num_bigint::BigInt; +use rand::Rng; use std::future::Future; use std::rc::Rc; @@ -402,3 +403,19 @@ pub async fn op_node_pbkdf2_async( }) .await? } + +#[op] +pub fn op_node_generate_secret(buf: &mut [u8]) { + rand::thread_rng().fill(buf); +} + +#[op] +pub async fn op_node_generate_secret_async(len: i32) -> ZeroCopyBuf { + tokio::task::spawn_blocking(move || { + let mut buf = vec![0u8; len as usize]; + rand::thread_rng().fill(&mut buf[..]); + buf.into() + }) + .await + .unwrap() +} -- cgit v1.2.3