From 727c70f4f1d45c8038f7ea2ac974facde71927fb Mon Sep 17 00:00:00 2001 From: akashfortanix Date: Mon, 24 Dec 2018 13:35:11 +0530 Subject: [PATCH 1/2] support sgx-target --- Cargo.toml | 3 +++ rand_os/Cargo.toml | 3 +++ rand_os/src/lib.rs | 4 ++++ rand_os/src/sgx.rs | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 rand_os/src/sgx.rs diff --git a/Cargo.toml b/Cargo.toml index 7b18500770c..1aea45fe7cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,3 +75,6 @@ autocfg = "0.1" [package.metadata.docs.rs] all-features = true + +[patch.crates-io] +rand_core = { path = "rand_core", version = "0.3", default-features = false } diff --git a/rand_os/Cargo.toml b/rand_os/Cargo.toml index 393230ec2a8..6a328917bde 100644 --- a/rand_os/Cargo.toml +++ b/rand_os/Cargo.toml @@ -34,3 +34,6 @@ fuchsia-zircon = "0.3.2" [target.wasm32-unknown-unknown.dependencies] wasm-bindgen = { version = "0.2.12", optional = true } stdweb = { version = "0.4", optional = true } + +[target.'cfg(target_env = "sgx")'.dependencies] +rdrand = "0.4.0" diff --git a/rand_os/src/lib.rs b/rand_os/src/lib.rs index 736fb5c6d46..1c7ccea71ef 100644 --- a/rand_os/src/lib.rs +++ b/rand_os/src/lib.rs @@ -142,6 +142,8 @@ extern crate wasm_bindgen; feature = "stdweb"))] #[macro_use] extern crate stdweb; +#[cfg(target_env = "sgx")] +extern crate rdrand; #[cfg(not(feature = "log"))] #[macro_use] @@ -310,6 +312,7 @@ mod_use!(cfg(target_os = "openbsd"), openbsd_bitrig); mod_use!(cfg(target_os = "redox"), redox); mod_use!(cfg(target_os = "solaris"), solaris); mod_use!(cfg(windows), windows); +mod_use!(cfg(target_env = "sgx"), sgx); mod_use!( cfg(all( @@ -356,5 +359,6 @@ compile_error!("enable either wasm_bindgen or stdweb feature"); target_os = "solaris", windows, target_arch = "wasm32", + target_env = "sgx" )))] compile_error!("OS RNG support is not available for this platform"); diff --git a/rand_os/src/sgx.rs b/rand_os/src/sgx.rs new file mode 100644 index 00000000000..43ae0ef79f1 --- /dev/null +++ b/rand_os/src/sgx.rs @@ -0,0 +1,38 @@ +// Copyright 2018 Developers of the Rand project. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use super::OsRngImpl; +use Error; +use rdrand::RdRand; +use rand_core::RngCore; +use std::fmt::{Debug, Formatter, Result as FmtResult}; + +#[derive(Clone)] +pub struct OsRng{ + gen: RdRand +} + +impl OsRngImpl for OsRng { + fn new() -> Result { + let rng = RdRand::new()?; + Ok(OsRng{ gen: rng }) + } + + fn fill_chunk(&mut self, dest: &mut [u8]) -> Result<(), Error> { + self.gen.try_fill_bytes(dest) + } + + fn method_str(&self) -> &'static str { "RDRAND" } +} + +impl Debug for OsRng { + fn fmt(&self, f: &mut Formatter) -> FmtResult { + f.debug_struct("OsRng") + .finish() + } +} From 8297a8326bfe76d5dd7707357d1536c47f16396c Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Sun, 6 Jan 2019 22:41:58 +0100 Subject: [PATCH 2/2] Try caching cargo web's emscripten installation --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c962ab164b8..bd22c0f8d07 100644 --- a/.travis.yml +++ b/.travis.yml @@ -137,6 +137,7 @@ matrix: - rustup target add wasm32-unknown-emscripten - nvm install 9 - ./utils/ci/install_cargo_web.sh + - cargo web prepare-emscripten - cargo web -V addons: chrome: stable @@ -211,7 +212,11 @@ script: after_script: set +e -cache: cargo +cache: + cargo: true + directories: + - .local/share/cargo-web + before_cache: # Travis can't cache files that are not readable by "others" - chmod -R a+r $HOME/.cargo