Skip to content

Commit 903c641

Browse files
committed
Add runtime_error backend
1 parent 35e17e5 commit 903c641

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed

.github/workflows/build.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,17 @@ jobs:
273273
- env:
274274
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="custom"
275275
run: cargo build --target riscv32i-unknown-none-elf
276+
277+
278+
runtime-error:
279+
name: Runtime error
280+
runs-on: ubuntu-24.04
281+
steps:
282+
- uses: actions/checkout@v4
283+
- uses: dtolnay/rust-toolchain@stable
284+
with:
285+
targets: wasm32-unknown-unknown
286+
- uses: Swatinem/rust-cache@v2
287+
- env:
288+
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="runtime_error"
289+
run: cargo build --target wasm32-unknown-unknown

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ wasm-bindgen-test = "0.3"
8383
[lints.rust.unexpected_cfgs]
8484
level = "warn"
8585
check-cfg = [
86-
'cfg(getrandom_backend, values("custom", "efi_rng", "rdrand", "rndr", "linux_getrandom", "linux_raw", "wasm_js"))',
86+
'cfg(getrandom_backend, values("custom", "efi_rng", "rdrand", "rndr", "linux_getrandom", "linux_raw", "wasm_js", "runtime_error"))',
8787
'cfg(getrandom_msan)',
8888
'cfg(getrandom_windows_legacy)',
8989
'cfg(getrandom_test_linux_fallback)',

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ of randomness based on their specific needs:
8787
| `wasm_js` | Web Browser, Node.js | `wasm32‑unknown‑unknown`, `wasm32v1-none` | [`Crypto.getRandomValues`]. Requires feature `wasm_js` ([see below](#webassembly-support)).
8888
| `efi_rng` | UEFI | `*-unknown‑uefi` | [`EFI_RNG_PROTOCOL`] with `EFI_RNG_ALGORITHM_RAW` (requires `std` and Nigthly compiler)
8989
| `custom` | All targets | `*` | User-provided custom implementation (see [custom backend])
90+
| `runtime_error` | All targets | `*` | Errors when providing randomness. Useful when only needing this crate to compile in wasm32, but it's not actually used.
9091

9192
Opt-in backends can be enabled using the `getrandom_backend` configuration flag.
9293
The flag can be set either by specifying the `rustflags` field in [`.cargo/config.toml`]:

src/backends.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ cfg_if! {
3838
));
3939
}
4040
}
41+
} else if #[cfg(getrandom_backend = "runtime_error")] {
42+
mod runtime_error;
43+
pub use runtime_error::*;
4144
} else if #[cfg(all(target_os = "linux", target_env = ""))] {
4245
mod linux_raw;
4346
pub use linux_raw::*;

src/backends/runtime_error.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//! Implementation that's not random and does a no-op.
2+
use crate::Error;
3+
use core::mem::MaybeUninit;
4+
5+
pub use crate::util::{inner_u32, inner_u64};
6+
7+
pub fn fill_inner(_dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
8+
Err(Error::UNSUPPORTED)
9+
}

0 commit comments

Comments
 (0)