From b0264bea7de1901c1b3ed764454290d10613d14b Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Thu, 27 Apr 2023 19:40:59 +0530 Subject: 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. --- ext/node/ops/crypto/mod.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'ext/node/ops/crypto/mod.rs') 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 { + Ok(tokio::task::spawn_blocking(move || gen_prime(size)).await?) +} -- cgit v1.2.3