Skip to content

Commit

Permalink
Add disable_urandom_fallback crate feature
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Feb 19, 2024
1 parent a4ba655 commit 64463c6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ 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).

## Unreleased
### Added
- `disable_urandom_fallback` crate feature to disable `/dev/urandom`-based fallback on Linux targets.
Enabling this feature bumps minimum supported Linux kernel version to 4.17. [#396]

### Changed
- Disable `/dev/urandom`-based fallback for all Android targets and for Linux targets
outside of the following `target_arch`es: `x86`, `x86_64`, `arm`, `armv7`, `i586`, `i686`,
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ wasm-bindgen-test = "0.3.18"
[features]
# Implement std-only traits for getrandom::Error
std = []
# Disable `/dev/urandom` fallback for Linux targets (requires 4.17+ kernel)
disable_urandom_fallback = []
# Feature to enable fallback RDRAND-based implementation on x86/x86_64
rdrand = []
# Feature to enable JavaScript bindings on wasm*-unknown-unknown
Expand Down
26 changes: 15 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,21 @@ cfg_if! {
if #[cfg(any(target_os = "haiku", target_os = "redox", target_os = "nto", target_os = "aix"))] {
mod util_libc;
#[path = "use_file.rs"] mod imp;
} else if #[cfg(all(target_os = "linux", any(
target_arch = "i586",
target_arch = "i686",
target_arch = "x86",
target_arch = "x86_64",
target_arch = "arm",
target_arch = "armv7",
target_arch = "powerpc",
target_arch = "powerpc64le",
target_arch = "s390x",
)))] {
} else if #[cfg(all(
not(feature = "disable_urandom_fallback"),
target_os = "linux",
any(
target_arch = "i586",
target_arch = "i686",
target_arch = "x86",
target_arch = "x86_64",
target_arch = "arm",
target_arch = "armv7",
target_arch = "powerpc",
target_arch = "powerpc64le",
target_arch = "s390x",
),
))] {
mod util_libc;
mod use_file;
mod lazy;
Expand Down

0 comments on commit 64463c6

Please sign in to comment.