diff --git a/.travis.yml b/.travis.yml index 6a32e3be105..b41e68172f7 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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 6aa0a247e5a..cf701f4c4ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ You may also find the [Upgrade Guide](https://rust-random.github.io/book/update. ## [0.6.4] - 2019-01-08 +### Additions +- Add support for x86_64-fortanix-unknown-sgx target (#670) + ### Fixes - Move wasm-bindgen shims to correct crate (#686) - Make `wasm32-unknown-unknown` compile but fail at run-time if missing bindingsg (#686) diff --git a/Cargo.toml b/Cargo.toml index 8f3c3747961..d802d36ac4f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -79,3 +79,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 723a49a3ec9..3adca38ab2b 100644 --- a/rand_os/Cargo.toml +++ b/rand_os/Cargo.toml @@ -33,3 +33,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 752303a2a39..67b0dfe40b2 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( @@ -376,6 +379,7 @@ mod imp { 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() + } +}