wasm32: Add a wasm32_unknown_unknown_js
feature to control use of web APIs.
Planning ahead for when WASI is to be supported, require the user to opt into using web APIs for thw wasm32-unknown-unknown target with a new feature, since wasm32-unknown-unknown could be used for either web or non-web environments. Don't bother updating the tests to use this new flag, since the tests aren't part of the "public API" of *ring*. When we add support for other WebAssembly environments (e.g. WASI) we'll update the tests then.
This commit is contained in:
parent
d97ae1fd08
commit
8d78cb2c01
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@ -429,7 +429,8 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
features:
|
||||
- # Default
|
||||
- --features=wasm32_unknown_unknown_js
|
||||
- --no-default-features --features=wasm32_unknown_unknown_js
|
||||
|
||||
host_os:
|
||||
- ubuntu-18.04
|
||||
|
@ -174,7 +174,7 @@ once_cell = { version = "1.8.0", default-features = false, features=["std"], opt
|
||||
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"] }
|
||||
web-sys = { version = "0.3.51", default-features = false, features = ["Crypto", "Window"], optional = true }
|
||||
|
||||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
winapi = { version = "0.3.9", default-features = false, features = ["ntsecapi", "wtypesbase", "processthreadsapi"] }
|
||||
@ -199,6 +199,7 @@ dev_urandom_fallback = ["once_cell"]
|
||||
slow_tests = []
|
||||
std = ["alloc"]
|
||||
test_logging = []
|
||||
wasm32_unknown_unknown_js = ["web-sys"]
|
||||
|
||||
# XXX: debug = false because of https://github.com/rust-lang/rust/issues/34122
|
||||
|
||||
|
@ -33,7 +33,11 @@
|
||||
//! <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.
|
||||
//! </table>
|
||||
|
||||
// When running mk/package.sh, don't actually build any code.
|
||||
|
@ -134,10 +134,10 @@ impl<T> RandomlyConstructable for T where T: self::sealed::RandomlyConstructable
|
||||
///
|
||||
/// On macOS and iOS, `fill()` is implemented using `SecRandomCopyBytes`.
|
||||
///
|
||||
/// On wasm32-unknown-unknown (non-WASI), `fill()` is implemented using
|
||||
/// `window.crypto.getRandomValues()`. It must be used in a context where the
|
||||
/// global object is a `Window`; i.e. it must not be used in a Worker or a
|
||||
/// non-browser context.
|
||||
/// On wasm32-unknown-unknown when the "wasm32_unknown_unknown_js" feature is
|
||||
/// enabled, `fill()` is implemented using `window.crypto.getRandomValues()`.
|
||||
/// It must be used in a context where the global object is a `Window`; i.e. it
|
||||
/// must not be used in a Worker or a non-browser context.
|
||||
///
|
||||
/// On Windows, `fill` is implemented using the platform's API for secure
|
||||
/// random number generation.
|
||||
@ -230,6 +230,7 @@ mod sysrand_chunk {
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
feature = "wasm32_unknown_unknown_js",
|
||||
target_arch = "wasm32",
|
||||
target_vendor = "unknown",
|
||||
target_os = "unknown",
|
||||
|
Loading…
x
Reference in New Issue
Block a user