summaryrefslogtreecommitdiff
path: root/ext/node/crypto/mod.rs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2023-04-06 18:39:25 +0530
committerGitHub <noreply@github.com>2023-04-06 18:39:25 +0530
commit3b62a58818f83e32fc2644f44e75a5c8465b2003 (patch)
treecf8f0a6d7995fa0c632247f2679295b8ceea4460 /ext/node/crypto/mod.rs
parent339165bd9565806374fa842dfc217dcc5ebabac5 (diff)
fix(ext/node): add symmetric keygen (#18609)
Towards #18455
Diffstat (limited to 'ext/node/crypto/mod.rs')
-rw-r--r--ext/node/crypto/mod.rs17
1 files changed, 17 insertions, 0 deletions
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()
+}