summaryrefslogtreecommitdiff
path: root/ext/node/ops/crypto/mod.rs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2023-04-27 19:40:59 +0530
committerGitHub <noreply@github.com>2023-04-27 19:40:59 +0530
commitb0264bea7de1901c1b3ed764454290d10613d14b (patch)
treecacf71dca64df1f6f1dde3b44c70b89ce72d9a03 /ext/node/ops/crypto/mod.rs
parent742cc3111ccb7c3c12c1b05904be052094657481 (diff)
fix(ext/node): prime generation (#18861)
Towards https://github.com/denoland/deno/issues/18455 `safe`, `add` and `rem` options are not implemented because there is no rust crate that provides this functionality (except rust-openssl maybe) and its just not clear if this API is used widely.
Diffstat (limited to 'ext/node/ops/crypto/mod.rs')
-rw-r--r--ext/node/ops/crypto/mod.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/ext/node/ops/crypto/mod.rs b/ext/node/ops/crypto/mod.rs
index d224b40f7..92e3029e0 100644
--- a/ext/node/ops/crypto/mod.rs
+++ b/ext/node/ops/crypto/mod.rs
@@ -901,3 +901,20 @@ pub async fn op_node_scrypt_async(
})
.await?
}
+
+#[inline]
+fn gen_prime(size: usize) -> ZeroCopyBuf {
+ primes::Prime::generate(size).0.to_bytes_be().into()
+}
+
+#[op]
+pub fn op_node_gen_prime(size: usize) -> ZeroCopyBuf {
+ gen_prime(size)
+}
+
+#[op]
+pub async fn op_node_gen_prime_async(
+ size: usize,
+) -> Result<ZeroCopyBuf, AnyError> {
+ Ok(tokio::task::spawn_blocking(move || gen_prime(size)).await?)
+}