diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2020-11-14 02:31:57 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-13 22:01:57 +0100 |
commit | d5661f677e9f5675fc488c4629e85a58764ec3ff (patch) | |
tree | 6878ec81e2da2d41d93e3f429a189edcd4202539 /cli/ops/crypto.rs | |
parent | 2c8439bc1e8118225c8ba4d64658c1c6b2182937 (diff) |
refactor: deno_crypto op crate (#7956)
This commit factors out "deno_crypto" op crate.
"rand" crate dependency was consequently moved to
"deno_crypto" crate and reexported.
Diffstat (limited to 'cli/ops/crypto.rs')
-rw-r--r-- | cli/ops/crypto.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/cli/ops/crypto.rs b/cli/ops/crypto.rs new file mode 100644 index 000000000..a73843a33 --- /dev/null +++ b/cli/ops/crypto.rs @@ -0,0 +1,14 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. +use deno_crypto::op_get_random_values; +use deno_crypto::rand::rngs::StdRng; +use deno_crypto::rand::SeedableRng; + +pub fn init(rt: &mut deno_core::JsRuntime, maybe_seed: Option<u64>) { + if let Some(seed) = maybe_seed { + let rng = StdRng::seed_from_u64(seed); + let op_state = rt.op_state(); + let mut state = op_state.borrow_mut(); + state.put::<StdRng>(rng); + } + super::reg_json_sync(rt, "op_get_random_values", op_get_random_values); +} |