summaryrefslogtreecommitdiff
path: root/ext/node/crypto/mod.rs
diff options
context:
space:
mode:
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()
+}