Skip to content

Commit

Permalink
Use the getrandom crate to implement ring::rand.
Browse files Browse the repository at this point in the history
  • Loading branch information
briansmith committed Oct 29, 2022
1 parent fa25bf3 commit f5bd88c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 302 deletions.
14 changes: 4 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,22 +161,16 @@ all-features = true
name = "ring"

[dependencies]
getrandom = { version = "0.2.8" }
untrusted = { version = "0.9" }

[target.'cfg(any(target_arch = "x86",target_arch = "x86_64", all(any(target_arch = "aarch64", target_arch = "arm"), any(target_os = "android", target_os = "fuchsia", target_os = "linux", target_os = "windows"))))'.dependencies]
spin = { version = "0.9.2", default-features = false, features = ["once"] }

[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies]
libc = { version = "0.2.100", default-features = false }
once_cell = { version = "1.8.0", default-features = false, features=["std"], optional = true }

[target.'cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "illumos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", target_os = "solaris"))'.dependencies]
once_cell = { version = "1.8.0", default-features = false, features=["std"] }

[target.'cfg(all(target_arch = "wasm32", target_vendor = "unknown", target_os = "unknown", target_env = ""))'.dependencies]
web-sys = { version = "0.3.51", default-features = false, features = ["Crypto", "Window"], optional = true }

[target.'cfg(target_os = "windows")'.dependencies]
[target.'cfg(all(target_arch = "aarch64", target_os = "windows"))'.dependencies]
winapi = { version = "0.3.9", default-features = false, features = ["ntsecapi", "wtypesbase", "processthreadsapi"] }

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
Expand All @@ -195,11 +189,11 @@ criterion = { version = "0.4", default-features = false }
# These features are documented in the top-level module's documentation.
default = ["alloc", "dev_urandom_fallback"]
alloc = []
dev_urandom_fallback = ["once_cell"]
dev_urandom_fallback = []
slow_tests = []
std = ["alloc"]
test_logging = []
wasm32_unknown_unknown_js = ["web-sys"]
wasm32_unknown_unknown_js = ["getrandom/js"]

# XXX: debug = false because of https://github.com/rust-lang/rust/issues/34122

Expand Down
4 changes: 1 addition & 3 deletions mk/install-build-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ case $target in
use_clang=1
;;
--target=wasm32-unknown-unknown)
# The version of wasm-bindgen-cli must match the wasm-bindgen version.
wasm_bindgen_version=$(cargo metadata --format-version 1 | jq -r '.packages | map(select( .name == "wasm-bindgen")) | map(.version) | .[0]')
cargo install wasm-bindgen-cli --vers "$wasm_bindgen_version" --bin wasm-bindgen-test-runner
cargo install wasm-bindgen-cli --bin wasm-bindgen-test-runner
use_clang=1
;;
--target=*)
Expand Down
11 changes: 2 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,15 @@
//! <th>Description
//! <tr><td><code>alloc (default)</code>
//! <td>Enable features that require use of the heap, RSA in particular.
//! <tr><td><code>dev_urandom_fallback (default)</code>
//! <td>This is only applicable to Linux. On Linux, by default,
//! <code>ring::rand::SystemRandom</code> will fall back to reading
//! from <code>/dev/urandom</code> if the <code>getrandom()</code>
//! syscall isn't supported at runtime. When the
//! <code>dev_urandom_fallback</code> feature is disabled, such
//! fallbacks will not occur. See the documentation for
//! <code>rand::SystemRandom</code> for more details.
//! <tr><td><code>std</code>
//! <td>Enable features that use libstd, in particular
//! <code>std::error::Error</code> integration. Implies `alloc`.
//! <tr><td><code>wasm32_unknown_unknown_js</code>
//! <td>When this feature is enabled, for the wasm32-unknown-unknown target,
//! Web APIs will be used to implement features like `ring::rand` that
//! require an operating environment of some kind. This has no effect
//! for any other target.
//! for any other target. This enables the `getrandom` crate's `js`
//! feature.
//! </table>

// When running mk/package.sh, don't actually build any code.
Expand Down
Loading

0 comments on commit f5bd88c

Please sign in to comment.