summaryrefslogtreecommitdiff
path: root/ext/node/ops
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
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')
-rw-r--r--ext/node/ops/crypto/mod.rs17
-rw-r--r--ext/node/ops/crypto/primes.rs2
2 files changed, 18 insertions, 1 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?)
+}
diff --git a/ext/node/ops/crypto/primes.rs b/ext/node/ops/crypto/primes.rs
index d03398f02..15aa643ad 100644
--- a/ext/node/ops/crypto/primes.rs
+++ b/ext/node/ops/crypto/primes.rs
@@ -8,7 +8,7 @@ use num_traits::Zero;
use rand::Rng;
use std::ops::Deref;
-pub struct Prime(num_bigint_dig::BigUint);
+pub struct Prime(pub num_bigint_dig::BigUint);
impl Prime {
pub fn generate(n: usize) -> Self {