diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/Cargo.toml | 3 | ||||
-rw-r--r-- | cli/build.rs | 1 | ||||
-rw-r--r-- | cli/ops/crypto.rs | 14 | ||||
-rw-r--r-- | cli/ops/fs.rs | 4 | ||||
-rw-r--r-- | cli/ops/mod.rs | 2 | ||||
-rw-r--r-- | cli/ops/random.rs | 38 | ||||
-rw-r--r-- | cli/rt/11_crypto.js | 22 | ||||
-rw-r--r-- | cli/worker.rs | 4 |
8 files changed, 22 insertions, 66 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 8459139bf..8e389c23a 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -20,6 +20,7 @@ harness = false path = "./bench/main.rs" [build-dependencies] +deno_crypto = { path = "../op_crates/crypto", version = "0.1.1" } deno_core = { path = "../core", version = "0.67.0" } deno_web = { path = "../op_crates/web", version = "0.18.0" } deno_fetch = { path = "../op_crates/fetch", version = "0.10.0" } @@ -31,6 +32,7 @@ winres = "0.1.11" winapi = "0.3.9" [dependencies] +deno_crypto = { path = "../op_crates/crypto", version = "0.1.1" } deno_core = { path = "../core", version = "0.67.0" } deno_doc = "0.1.15" deno_lint = "0.2.9" @@ -55,7 +57,6 @@ libc = "0.2.77" log = "0.4.11" env_logger = "0.7.1" notify = "5.0.0-pre.3" -rand = "0.7.3" regex = "1.3.9" ring = "0.16.15" rustyline = { version = "6.3.0", default-features = false } diff --git a/cli/build.rs b/cli/build.rs index 657041132..822ccd820 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -20,6 +20,7 @@ fn create_snapshot( ) { deno_web::init(&mut js_runtime); deno_fetch::init(&mut js_runtime); + deno_crypto::init(&mut js_runtime); // TODO(nayeemrmn): https://github.com/rust-lang/cargo/issues/3946 to get the // workspace root. let display_root = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap(); 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); +} diff --git a/cli/ops/fs.rs b/cli/ops/fs.rs index 720a4db52..37558ec6b 100644 --- a/cli/ops/fs.rs +++ b/cli/ops/fs.rs @@ -13,8 +13,8 @@ use deno_core::serde_json::Value; use deno_core::BufVec; use deno_core::OpState; use deno_core::ZeroCopyBuf; -use rand::thread_rng; -use rand::Rng; +use deno_crypto::rand::thread_rng; +use deno_crypto::rand::Rng; use serde::Deserialize; use std::cell::RefCell; use std::convert::From; diff --git a/cli/ops/mod.rs b/cli/ops/mod.rs index f5f42a2d7..b450f8989 100644 --- a/cli/ops/mod.rs +++ b/cli/ops/mod.rs @@ -3,6 +3,7 @@ mod dispatch_minimal; pub use dispatch_minimal::MinimalOp; +pub mod crypto; pub mod errors; pub mod fetch; pub mod fs; @@ -15,7 +16,6 @@ pub mod os; pub mod permissions; pub mod plugin; pub mod process; -pub mod random; pub mod runtime; pub mod runtime_compiler; pub mod signal; diff --git a/cli/ops/random.rs b/cli/ops/random.rs deleted file mode 100644 index 20296c667..000000000 --- a/cli/ops/random.rs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. - -use deno_core::error::AnyError; -use deno_core::serde_json::json; -use deno_core::serde_json::Value; -use deno_core::OpState; -use deno_core::ZeroCopyBuf; -use rand::rngs::StdRng; -use rand::thread_rng; -use rand::Rng; -use 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); -} - -fn op_get_random_values( - state: &mut OpState, - _args: Value, - zero_copy: &mut [ZeroCopyBuf], -) -> Result<Value, AnyError> { - assert_eq!(zero_copy.len(), 1); - let maybe_seeded_rng = state.try_borrow_mut::<StdRng>(); - if let Some(seeded_rng) = maybe_seeded_rng { - seeded_rng.fill(&mut *zero_copy[0]); - } else { - let mut rng = thread_rng(); - rng.fill(&mut *zero_copy[0]); - } - - Ok(json!({})) -} diff --git a/cli/rt/11_crypto.js b/cli/rt/11_crypto.js deleted file mode 100644 index 32b026a78..000000000 --- a/cli/rt/11_crypto.js +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. - -((window) => { - const core = window.Deno.core; - const { assert } = window.__bootstrap.util; - - function getRandomValues(typedArray) { - assert(typedArray !== null, "Input must not be null"); - assert(typedArray.length <= 65536, "Input must not be longer than 65536"); - const ui8 = new Uint8Array( - typedArray.buffer, - typedArray.byteOffset, - typedArray.byteLength, - ); - core.jsonOpSync("op_get_random_values", {}, ui8); - return typedArray; - } - - window.__bootstrap.crypto = { - getRandomValues, - }; -})(this); diff --git a/cli/worker.rs b/cli/worker.rs index a09e96ce4..e27d6f73e 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -278,7 +278,7 @@ impl MainWorker { ops::fetch::init(js_runtime, program_state.flags.ca_file.as_deref()); ops::timers::init(js_runtime); ops::worker_host::init(js_runtime, None); - ops::random::init(js_runtime, program_state.flags.seed); + ops::crypto::init(js_runtime, program_state.flags.seed); ops::reg_json_sync(js_runtime, "op_close", deno_core::op_close); ops::reg_json_sync(js_runtime, "op_resources", deno_core::op_resources); ops::reg_json_sync( @@ -469,7 +469,7 @@ impl WebWorker { ops::permissions::init(js_runtime); ops::plugin::init(js_runtime); ops::process::init(js_runtime); - ops::random::init(js_runtime, program_state.flags.seed); + ops::crypto::init(js_runtime, program_state.flags.seed); ops::runtime_compiler::init(js_runtime); ops::signal::init(js_runtime); ops::tls::init(js_runtime); |