+2
-2
@@ -149,8 +149,8 @@ matrix:
|
||||
#- cargo web test --target wasm32-unknown-emscripten
|
||||
#- cargo web test --nodejs --target wasm32-unknown-emscripten
|
||||
#- cargo build --target wasm32-unknown-unknown # without any features
|
||||
- cargo build --target wasm32-unknown-unknown --features=rand_os/wasm-bindgen
|
||||
- cd rand_os && cargo web test --target wasm32-unknown-unknown --features=stdweb
|
||||
- cargo build --target wasm32-unknown-unknown --features=wasm-bindgen
|
||||
- cargo web test --target wasm32-unknown-unknown --features=stdweb
|
||||
|
||||
- rust: nightly
|
||||
env: DESCRIPTION="cross-platform builder (doesn't run tests)"
|
||||
|
||||
@@ -9,6 +9,11 @@ A [separate changelog is kept for rand_core](rand_core/CHANGELOG.md).
|
||||
You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.html) useful.
|
||||
|
||||
|
||||
## [0.6.4] - 2019-01-08
|
||||
### Fixes
|
||||
- Move wasm-bindgen shims to correct crate (#686)
|
||||
- Make `wasm32-unknown-unknown` compile but fail at run-time if missing bindingsg (#686)
|
||||
|
||||
## [0.6.3] - 2019-01-04
|
||||
### Fixes
|
||||
- Make the `std` feature require the optional `rand_os` dependency (#675)
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rand"
|
||||
version = "0.6.3"
|
||||
version = "0.6.4"
|
||||
authors = ["The Rand Project Developers", "The Rust Project Developers"]
|
||||
license = "MIT/Apache-2.0"
|
||||
readme = "README.md"
|
||||
|
||||
@@ -74,8 +74,15 @@ pinned version of Rustc if you require compatibility with a specific version.
|
||||
|
||||
## Crate Features
|
||||
|
||||
Rand is built with only the `std` feature enabled by default. The following
|
||||
optional features are available:
|
||||
Rand is built with the `std` and `rand_os` features enabled by default:
|
||||
|
||||
- `std` enables functionality dependent on the `std` lib and implies `alloc`
|
||||
and `rand_os`
|
||||
- `rand_os` enables the `rand_os` crate, `rngs::OsRng` and enables its usage;
|
||||
the continued existance of this feature is not guaranteed so users are
|
||||
encouraged to specify `std` instead
|
||||
|
||||
The following optional features are available:
|
||||
|
||||
- `alloc` can be used instead of `std` to provide `Vec` and `Box`.
|
||||
- `log` enables some logging via the `log` crate.
|
||||
|
||||
@@ -4,5 +4,10 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
|
||||
## [0.1.1] - 2019-01-08
|
||||
### Additions
|
||||
- Add support for x86_64-fortanix-unknown-sgx target (#670)
|
||||
|
||||
## [0.1.0] - 2019-01-04
|
||||
Initial release.
|
||||
|
||||
+2
-3
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rand_os"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
authors = ["The Rand Project Developers"]
|
||||
license = "MIT/Apache-2.0"
|
||||
readme = "README.md"
|
||||
@@ -21,9 +21,8 @@ log = { version = "0.4", optional = true }
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
libc = "0.2"
|
||||
|
||||
# TODO: check if all features are required
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
winapi = { version = "0.3", features = ["minwindef", "ntsecapi", "profileapi", "winnt"] }
|
||||
winapi = { version = "0.3", features = ["minwindef", "ntsecapi", "winnt"] }
|
||||
|
||||
[target.'cfg(target_os = "cloudabi")'.dependencies]
|
||||
cloudabi = "0.0.3"
|
||||
|
||||
+78
-3
@@ -126,8 +126,8 @@
|
||||
#![deny(missing_docs)]
|
||||
#![deny(missing_debug_implementations)]
|
||||
#![doc(test(attr(allow(unused_variables), deny(warnings))))]
|
||||
// for stdweb
|
||||
#![recursion_limit="128"]
|
||||
|
||||
#![cfg_attr(feature = "stdweb", recursion_limit="128")]
|
||||
|
||||
pub extern crate rand_core;
|
||||
#[cfg(feature = "log")]
|
||||
@@ -333,13 +333,33 @@ mod_use!(
|
||||
wasm32_stdweb
|
||||
);
|
||||
|
||||
/// Per #678 we use run-time failure where WASM bindings are missing
|
||||
#[cfg(all(
|
||||
target_arch = "wasm32",
|
||||
not(target_os = "emscripten"),
|
||||
not(feature = "wasm-bindgen"),
|
||||
not(feature = "stdweb"),
|
||||
))]
|
||||
compile_error!("enable either wasm_bindgen or stdweb feature");
|
||||
mod imp {
|
||||
use rand_core::{Error, ErrorKind};
|
||||
use super::OsRngImpl;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct OsRng;
|
||||
|
||||
impl OsRngImpl for OsRng {
|
||||
fn new() -> Result<OsRng, Error> {
|
||||
Err(Error::new(ErrorKind::Unavailable,
|
||||
"OsRng: support for wasm32 requires emscripten, stdweb or wasm-bindgen"))
|
||||
}
|
||||
|
||||
fn fill_chunk(&mut self, _dest: &mut [u8]) -> Result<(), Error> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn method_str(&self) -> &'static str { unimplemented!() }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(any(
|
||||
target_os = "android",
|
||||
@@ -362,3 +382,58 @@ compile_error!("enable either wasm_bindgen or stdweb feature");
|
||||
target_env = "sgx"
|
||||
)))]
|
||||
compile_error!("OS RNG support is not available for this platform");
|
||||
|
||||
// Due to rustwasm/wasm-bindgen#201 this can't be defined in the inner os
|
||||
// modules, so hack around it for now and place it at the root.
|
||||
#[cfg(all(feature = "wasm-bindgen", target_arch = "wasm32"))]
|
||||
#[doc(hidden)]
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub mod __wbg_shims {
|
||||
|
||||
// `extern { type Foo; }` isn't supported on 1.22 syntactically, so use a
|
||||
// macro to work around that.
|
||||
macro_rules! rust_122_compat {
|
||||
($($t:tt)*) => ($($t)*)
|
||||
}
|
||||
|
||||
rust_122_compat! {
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
pub use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
pub type Function;
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(s: &str) -> Function;
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn call(this: &Function, self_: &JsValue) -> JsValue;
|
||||
|
||||
pub type This;
|
||||
#[wasm_bindgen(method, getter, structural, js_name = self)]
|
||||
pub fn self_(me: &This) -> JsValue;
|
||||
#[wasm_bindgen(method, getter, structural)]
|
||||
pub fn crypto(me: &This) -> JsValue;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub type BrowserCrypto;
|
||||
|
||||
// TODO: these `structural` annotations here ideally wouldn't be here to
|
||||
// avoid a JS shim, but for now with feature detection they're
|
||||
// unavoidable.
|
||||
#[wasm_bindgen(method, js_name = getRandomValues, structural, getter)]
|
||||
pub fn get_random_values_fn(me: &BrowserCrypto) -> JsValue;
|
||||
#[wasm_bindgen(method, js_name = getRandomValues, structural)]
|
||||
pub fn get_random_values(me: &BrowserCrypto, buf: &mut [u8]);
|
||||
|
||||
#[wasm_bindgen(js_name = require)]
|
||||
pub fn node_require(s: &str) -> NodeCrypto;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub type NodeCrypto;
|
||||
|
||||
#[wasm_bindgen(method, js_name = randomFillSync, structural)]
|
||||
pub fn random_fill_sync(me: &NodeCrypto, buf: &mut [u8]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-71
@@ -291,45 +291,12 @@ impl SeedableRng for StdRng {
|
||||
impl CryptoRng for StdRng {}
|
||||
|
||||
|
||||
#[cfg(all(feature="std",
|
||||
any(target_os = "linux", target_os = "android",
|
||||
target_os = "netbsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "haiku",
|
||||
target_os = "emscripten",
|
||||
target_os = "solaris",
|
||||
target_os = "cloudabi",
|
||||
target_os = "macos", target_os = "ios",
|
||||
target_os = "freebsd",
|
||||
target_os = "openbsd", target_os = "bitrig",
|
||||
target_os = "redox",
|
||||
target_os = "fuchsia",
|
||||
windows,
|
||||
all(target_arch = "wasm32", feature = "stdweb"),
|
||||
all(target_arch = "wasm32", feature = "wasm-bindgen"),
|
||||
)))]
|
||||
#[cfg(feature="rand_os")]
|
||||
#[derive(Clone, Debug)]
|
||||
#[deprecated(since="0.6.0", note="import with rand::rngs::OsRng instead")]
|
||||
pub struct OsRng(rngs::OsRng);
|
||||
|
||||
#[cfg(all(feature="std",
|
||||
any(target_os = "linux", target_os = "android",
|
||||
target_os = "netbsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "haiku",
|
||||
target_os = "emscripten",
|
||||
target_os = "solaris",
|
||||
target_os = "cloudabi",
|
||||
target_os = "macos", target_os = "ios",
|
||||
target_os = "freebsd",
|
||||
target_os = "openbsd", target_os = "bitrig",
|
||||
target_os = "redox",
|
||||
target_os = "fuchsia",
|
||||
windows,
|
||||
all(target_arch = "wasm32", feature = "stdweb"),
|
||||
all(target_arch = "wasm32", feature = "wasm-bindgen"),
|
||||
)))]
|
||||
#[cfg(feature="std")]
|
||||
#[cfg(feature="rand_os")]
|
||||
impl RngCore for OsRng {
|
||||
#[inline(always)]
|
||||
fn next_u32(&mut self) -> u32 {
|
||||
@@ -352,48 +319,14 @@ impl RngCore for OsRng {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature="std",
|
||||
any(target_os = "linux", target_os = "android",
|
||||
target_os = "netbsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "haiku",
|
||||
target_os = "emscripten",
|
||||
target_os = "solaris",
|
||||
target_os = "cloudabi",
|
||||
target_os = "macos", target_os = "ios",
|
||||
target_os = "freebsd",
|
||||
target_os = "openbsd", target_os = "bitrig",
|
||||
target_os = "redox",
|
||||
target_os = "fuchsia",
|
||||
windows,
|
||||
all(target_arch = "wasm32", feature = "stdweb"),
|
||||
all(target_arch = "wasm32", feature = "wasm-bindgen"),
|
||||
)))]
|
||||
#[cfg(feature="std")]
|
||||
#[cfg(feature="rand_os")]
|
||||
impl OsRng {
|
||||
pub fn new() -> Result<Self, Error> {
|
||||
rngs::OsRng::new().map(OsRng)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature="std",
|
||||
any(target_os = "linux", target_os = "android",
|
||||
target_os = "netbsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "haiku",
|
||||
target_os = "emscripten",
|
||||
target_os = "solaris",
|
||||
target_os = "cloudabi",
|
||||
target_os = "macos", target_os = "ios",
|
||||
target_os = "freebsd",
|
||||
target_os = "openbsd", target_os = "bitrig",
|
||||
target_os = "redox",
|
||||
target_os = "fuchsia",
|
||||
windows,
|
||||
all(target_arch = "wasm32", feature = "stdweb"),
|
||||
all(target_arch = "wasm32", feature = "wasm-bindgen"),
|
||||
)))]
|
||||
#[cfg(feature="std")]
|
||||
#[cfg(feature="rand_os")]
|
||||
impl CryptoRng for OsRng {}
|
||||
|
||||
|
||||
|
||||
+2
-94
@@ -58,17 +58,12 @@
|
||||
#![cfg_attr(not(feature="std"), no_std)]
|
||||
#![cfg_attr(all(feature="alloc", not(feature="std")), feature(alloc))]
|
||||
#![cfg_attr(all(feature="simd_support", feature="nightly"), feature(stdsimd))]
|
||||
#![cfg_attr(feature = "stdweb", recursion_limit="128")]
|
||||
|
||||
#[cfg(feature = "std")] extern crate core;
|
||||
#[cfg(all(feature = "alloc", not(feature="std")))] #[macro_use] extern crate alloc;
|
||||
|
||||
#[cfg(feature="simd_support")] extern crate packed_simd;
|
||||
|
||||
#[cfg(all(target_arch="wasm32", not(target_os="emscripten"), feature="stdweb"))]
|
||||
#[macro_use]
|
||||
extern crate stdweb;
|
||||
|
||||
#[cfg(feature = "rand_os")]
|
||||
extern crate rand_os;
|
||||
|
||||
@@ -119,23 +114,7 @@ pub mod seq;
|
||||
#[cfg(feature="std")] #[doc(hidden)] pub use deprecated::EntropyRng;
|
||||
|
||||
#[allow(deprecated)]
|
||||
#[cfg(all(feature="std",
|
||||
any(target_os = "linux", target_os = "android",
|
||||
target_os = "netbsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "haiku",
|
||||
target_os = "emscripten",
|
||||
target_os = "solaris",
|
||||
target_os = "cloudabi",
|
||||
target_os = "macos", target_os = "ios",
|
||||
target_os = "freebsd",
|
||||
target_os = "openbsd", target_os = "bitrig",
|
||||
target_os = "redox",
|
||||
target_os = "fuchsia",
|
||||
windows,
|
||||
all(target_arch = "wasm32", feature = "stdweb"),
|
||||
all(target_arch = "wasm32", feature = "wasm-bindgen"),
|
||||
)))]
|
||||
#[cfg(feature="rand_os")]
|
||||
#[doc(hidden)]
|
||||
pub use deprecated::OsRng;
|
||||
|
||||
@@ -152,23 +131,7 @@ pub mod jitter {
|
||||
pub use rngs::TimerError;
|
||||
}
|
||||
#[allow(deprecated)]
|
||||
#[cfg(all(feature="std",
|
||||
any(target_os = "linux", target_os = "android",
|
||||
target_os = "netbsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "haiku",
|
||||
target_os = "emscripten",
|
||||
target_os = "solaris",
|
||||
target_os = "cloudabi",
|
||||
target_os = "macos", target_os = "ios",
|
||||
target_os = "freebsd",
|
||||
target_os = "openbsd", target_os = "bitrig",
|
||||
target_os = "redox",
|
||||
target_os = "fuchsia",
|
||||
windows,
|
||||
all(target_arch = "wasm32", feature = "stdweb"),
|
||||
all(target_arch = "wasm32", feature = "wasm-bindgen"),
|
||||
)))]
|
||||
#[cfg(feature="rand_os")]
|
||||
#[doc(hidden)]
|
||||
pub mod os {
|
||||
pub use deprecated::OsRng;
|
||||
@@ -712,61 +675,6 @@ pub fn random<T>() -> T where Standard: Distribution<T> {
|
||||
thread_rng().gen()
|
||||
}
|
||||
|
||||
// Due to rustwasm/wasm-bindgen#201 this can't be defined in the inner os
|
||||
// modules, so hack around it for now and place it at the root.
|
||||
#[cfg(all(feature = "wasm-bindgen", target_arch = "wasm32"))]
|
||||
#[doc(hidden)]
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub mod __wbg_shims {
|
||||
|
||||
// `extern { type Foo; }` isn't supported on 1.22 syntactically, so use a
|
||||
// macro to work around that.
|
||||
macro_rules! rust_122_compat {
|
||||
($($t:tt)*) => ($($t)*)
|
||||
}
|
||||
|
||||
rust_122_compat! {
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
pub use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
pub type Function;
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(s: &str) -> Function;
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn call(this: &Function, self_: &JsValue) -> JsValue;
|
||||
|
||||
pub type This;
|
||||
#[wasm_bindgen(method, getter, structural, js_name = self)]
|
||||
pub fn self_(me: &This) -> JsValue;
|
||||
#[wasm_bindgen(method, getter, structural)]
|
||||
pub fn crypto(me: &This) -> JsValue;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub type BrowserCrypto;
|
||||
|
||||
// TODO: these `structural` annotations here ideally wouldn't be here to
|
||||
// avoid a JS shim, but for now with feature detection they're
|
||||
// unavoidable.
|
||||
#[wasm_bindgen(method, js_name = getRandomValues, structural, getter)]
|
||||
pub fn get_random_values_fn(me: &BrowserCrypto) -> JsValue;
|
||||
#[wasm_bindgen(method, js_name = getRandomValues, structural)]
|
||||
pub fn get_random_values(me: &BrowserCrypto, buf: &mut [u8]);
|
||||
|
||||
#[wasm_bindgen(js_name = require)]
|
||||
pub fn node_require(s: &str) -> NodeCrypto;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub type NodeCrypto;
|
||||
|
||||
#[wasm_bindgen(method, js_name = randomFillSync, structural)]
|
||||
pub fn random_fill_sync(me: &NodeCrypto, buf: &mut [u8]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use rngs::mock::StepRng;
|
||||
|
||||
+3
-51
@@ -191,43 +191,11 @@ impl EntropySource for NoSource {
|
||||
}
|
||||
|
||||
|
||||
#[cfg(all(feature="std",
|
||||
any(target_os = "linux", target_os = "android",
|
||||
target_os = "netbsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "haiku",
|
||||
target_os = "emscripten",
|
||||
target_os = "solaris",
|
||||
target_os = "cloudabi",
|
||||
target_os = "macos", target_os = "ios",
|
||||
target_os = "freebsd",
|
||||
target_os = "openbsd", target_os = "bitrig",
|
||||
target_os = "redox",
|
||||
target_os = "fuchsia",
|
||||
windows,
|
||||
all(target_arch = "wasm32", feature = "stdweb"),
|
||||
all(target_arch = "wasm32", feature = "wasm-bindgen"),
|
||||
)))]
|
||||
#[cfg(feature="rand_os")]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Os(rngs::OsRng);
|
||||
|
||||
#[cfg(all(feature="std",
|
||||
any(target_os = "linux", target_os = "android",
|
||||
target_os = "netbsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "haiku",
|
||||
target_os = "emscripten",
|
||||
target_os = "solaris",
|
||||
target_os = "cloudabi",
|
||||
target_os = "macos", target_os = "ios",
|
||||
target_os = "freebsd",
|
||||
target_os = "openbsd", target_os = "bitrig",
|
||||
target_os = "redox",
|
||||
target_os = "fuchsia",
|
||||
windows,
|
||||
all(target_arch = "wasm32", feature = "stdweb"),
|
||||
all(target_arch = "wasm32", feature = "wasm-bindgen"),
|
||||
)))]
|
||||
#[cfg(feature="rand_os")]
|
||||
impl EntropySource for Os {
|
||||
fn new_and_fill(dest: &mut [u8]) -> Result<Self, Error> {
|
||||
let mut rng = rngs::OsRng::new()?;
|
||||
@@ -240,23 +208,7 @@ impl EntropySource for Os {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(all(feature="std",
|
||||
any(target_os = "linux", target_os = "android",
|
||||
target_os = "netbsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "haiku",
|
||||
target_os = "emscripten",
|
||||
target_os = "solaris",
|
||||
target_os = "cloudabi",
|
||||
target_os = "macos", target_os = "ios",
|
||||
target_os = "freebsd",
|
||||
target_os = "openbsd", target_os = "bitrig",
|
||||
target_os = "redox",
|
||||
target_os = "fuchsia",
|
||||
windows,
|
||||
all(target_arch = "wasm32", feature = "stdweb"),
|
||||
all(target_arch = "wasm32", feature = "wasm-bindgen"),
|
||||
))))]
|
||||
#[cfg(not(feature="std"))]
|
||||
type Os = NoSource;
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -178,5 +178,5 @@ pub use self::small::SmallRng;
|
||||
pub use self::std::StdRng;
|
||||
#[cfg(feature="std")] pub use self::thread::ThreadRng;
|
||||
|
||||
#[cfg(feature="std")]
|
||||
#[cfg(feature="rand_os")]
|
||||
pub use rand_os::OsRng;
|
||||
|
||||
@@ -132,7 +132,6 @@ impl CryptoRng for ThreadRng {}
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
#[test]
|
||||
#[cfg(not(feature="stdweb"))]
|
||||
fn test_thread_rng() {
|
||||
use Rng;
|
||||
let mut r = ::thread_rng();
|
||||
|
||||
Reference in New Issue
Block a user