summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/BUILD.gn1
-rw-r--r--cli/main.rs1
-rw-r--r--cli/msg.fbs3
-rw-r--r--cli/ops.rs12
4 files changed, 17 insertions, 0 deletions
diff --git a/cli/BUILD.gn b/cli/BUILD.gn
index 049553c48..8e7e5c305 100644
--- a/cli/BUILD.gn
+++ b/cli/BUILD.gn
@@ -88,6 +88,7 @@ ts_sources = [
"../js/files.ts",
"../js/flatbuffers.ts",
"../js/form_data.ts",
+ "../js/get_random_values.ts",
"../js/globals.ts",
"../js/headers.ts",
"../js/io.ts",
diff --git a/cli/main.rs b/cli/main.rs
index ff2ed6006..3ee8fb0ed 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -11,6 +11,7 @@ extern crate clap;
extern crate deno;
#[cfg(unix)]
extern crate nix;
+extern crate rand;
mod ansi;
pub mod compiler;
diff --git a/cli/msg.fbs b/cli/msg.fbs
index 6efa871b6..9e4bf658e 100644
--- a/cli/msg.fbs
+++ b/cli/msg.fbs
@@ -19,6 +19,7 @@ union Any {
FetchRes,
FormatError,
FormatErrorRes,
+ GetRandomValues,
GlobalTimer,
GlobalTimerRes,
GlobalTimerStop,
@@ -578,4 +579,6 @@ table Seek {
whence: uint;
}
+table GetRandomValues {}
+
root_type Base;
diff --git a/cli/ops.rs b/cli/ops.rs
index 023662c20..9b5bc0079 100644
--- a/cli/ops.rs
+++ b/cli/ops.rs
@@ -13,6 +13,7 @@ use crate::js_errors::apply_source_map;
use crate::js_errors::JSErrorColor;
use crate::msg;
use crate::msg_util;
+use crate::rand;
use crate::repl;
use crate::resolve_addr::resolve_addr;
use crate::resources;
@@ -39,6 +40,7 @@ use futures::Sink;
use futures::Stream;
use hyper;
use hyper::rt::Future;
+use rand::{thread_rng, Rng};
use remove_dir_all::remove_dir_all;
use std;
use std::convert::From;
@@ -195,6 +197,7 @@ pub fn op_selector_std(inner_type: msg::Any) -> Option<OpCreator> {
msg::Any::Exit => Some(op_exit),
msg::Any::Fetch => Some(op_fetch),
msg::Any::FormatError => Some(op_format_error),
+ msg::Any::GetRandomValues => Some(op_get_random_values),
msg::Any::GlobalTimer => Some(op_global_timer),
msg::Any::GlobalTimerStop => Some(op_global_timer_stop),
msg::Any::IsTTY => Some(op_is_tty),
@@ -2168,3 +2171,12 @@ fn op_host_post_message(
});
Box::new(op)
}
+
+fn op_get_random_values(
+ _state: &ThreadSafeState,
+ _base: &msg::Base<'_>,
+ data: Option<PinnedBuf>,
+) -> Box<OpWithError> {
+ thread_rng().fill(&mut data.unwrap()[..]);
+ Box::new(ok_future(empty_buf()))
+}