Skip to content

Commit 5d07c2d

Browse files
authored
Move OsRng down to rand (#1674)
Moves `OsRng` from `rand_core` to `rand`. Removes fns `SeedableRng::from_os_rng` and `try_from_os_rng`.
2 parents a8208d4 + 1d3235c commit 5d07c2d

File tree

19 files changed

+37
-88
lines changed

19 files changed

+37
-88
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,8 @@ jobs:
117117
cargo test --target ${{ matrix.target }} --features=serde,log,small_rng
118118
- name: Test rand_core
119119
run: |
120-
cargo test --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml
121120
cargo test --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml --no-default-features
122-
cargo test --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml --no-default-features --features=os_rng
121+
cargo test --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml --features serde
123122
- name: Test rand_pcg
124123
run: cargo test --target ${{ matrix.target }} --manifest-path rand_pcg/Cargo.toml --features=serde
125124
- name: Test rand_chacha

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.
1414
- Rename fns `IndexedRandom::choose_multiple` -> `sample`, `choose_multiple_array` -> `sample_array`, `choose_multiple_weighted` -> `sample_weighted`, struct `SliceChooseIter` -> `IndexedSamples` and fns `IteratorRandom::choose_multiple` -> `sample`, `choose_multiple_fill` -> `sample_fill` (#1632)
1515
- Use Edition 2024 and MSRV 1.85 (#1653)
1616
- Let `Fill` be implemented for element types, not sliceable types (#1652)
17+
- Fix `OsError::raw_os_error` on UEFI targets by returning `Option<usize>` (#1665)
1718
- Replace fn `TryRngCore::read_adapter(..) -> RngReadAdapter` with simpler struct `RngReader` (#1669)
19+
- Remove fns `SeedableRng::from_os_rng`, `try_from_os_rng` (#1674)
1820

1921
### Additions
2022
- Add fns `IndexedRandom::choose_iter`, `choose_weighted_iter` (#1632)

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ serde = ["dep:serde", "rand_core/serde"]
3434

3535
# Option (enabled by default): without "std" rand uses libcore; this option
3636
# enables functionality expected to be available on a standard platform.
37-
std = ["rand_core/std", "alloc"]
37+
std = ["alloc", "getrandom?/std"]
3838

3939
# Option: "alloc" enables support for Vec and Box when not using "std"
4040
alloc = []
4141

4242
# Option: enable OsRng
43-
os_rng = ["rand_core/os_rng"]
43+
os_rng = ["dep:getrandom"]
4444

4545
# Option (requires nightly Rust): experimental SIMD support
4646
simd_support = []
@@ -83,6 +83,7 @@ rand_core = { path = "rand_core", version = "0.9.0", default-features = false }
8383
log = { version = "0.4.4", optional = true }
8484
serde = { version = "1.0.103", features = ["derive"], optional = true }
8585
chacha20 = { version = "=0.10.0-rc.2", default-features = false, features = ["rng"], optional = true }
86+
getrandom = { version = "0.3.0", optional = true }
8687

8788
[dev-dependencies]
8889
rand_pcg = { path = "rand_pcg", version = "0.9.0" }

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ compiler versions will be compatible. This is especially true of Rand's
9191
experimental `simd_support` feature.
9292

9393
Rand supports limited functionality in `no_std` mode (enabled via
94-
`default-features = false`). In this case, `OsRng` and `from_os_rng` are
94+
`default-features = false`). In this case, `OsRng` is
9595
unavailable (unless `os_rng` is enabled), large parts of `seq` are
9696
unavailable (unless `alloc` is enabled), and `ThreadRng` is unavailable.
9797

SECURITY.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ used according to these additional constraints:
2424

2525
- Via `SeedableRng::from_seed` using a cryptographically secure seed value
2626
- Via `SeedableRng::from_rng` or `try_from_rng` using a cryptographically
27-
secure source `rng`
28-
- Via `SeedableRng::from_os_rng` or `try_from_os_rng`
27+
secure source `rng` such as `OsRng` or `ThreadRng`.
2928
- The state (memory) of the generator and its seed value (or source `rng`) are
3029
not exposed
3130

rand_chacha/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [0.10.0] - UNRELEASED
88
### Changed
99
- Bump MSRV to 1.85 and edition to 2024 (#1671)
10+
- Remove feature `os_rng` (#1674)
1011

1112
## [0.9.0] - 2025-01-27
1213
### Dependencies and features

rand_chacha/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ serde = { version = "1.0", features = ["derive"], optional = true }
2727
[dev-dependencies]
2828
# Only to test serde
2929
serde_json = "1.0.120"
30-
rand_core = { path = "../rand_core", version = "0.9.0", features = ["os_rng"] }
30+
rand_core = { path = "../rand_core", version = "0.9.0" }
31+
rand = { path = "..", version = "0.10.0-rc.0" }
3132

3233
[features]
3334
default = ["std"]
34-
os_rng = ["rand_core/os_rng"]
35-
std = ["ppv-lite86/std", "rand_core/std"]
35+
std = ["ppv-lite86/std"]
3636
serde = ["dep:serde"]

rand_chacha/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ Links:
3535

3636
`rand_chacha` is `no_std` compatible when disabling default features; the `std`
3737
feature can be explicitly required to re-enable `std` support. Using `std`
38-
allows detection of CPU features and thus better optimisation. Using `std`
39-
also enables `os_rng` functionality, such as `ChaCha20Rng::from_os_rng()`.
38+
allows detection of CPU features and thus better optimisation.
4039

4140

4241
# License

rand_chacha/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
//!
2525
//! Where secure unpredictable generators are required, it is suggested to use
2626
//! [`ChaCha12Rng`] or [`ChaCha20Rng`] and to seed via
27-
//! [`SeedableRng::from_os_rng`].
27+
//! [`OsRng`].
2828
//!
2929
//! See also the [Security] chapter in the rand book. The crate is provided
3030
//! "as is", without any form of guarantee, and without a security audit.
@@ -37,8 +37,8 @@
3737
//!
3838
//! 1. With a fresh seed, **direct from the OS** (implies a syscall):
3939
//! ```
40-
//! # use {rand_core::SeedableRng, rand_chacha::ChaCha12Rng};
41-
//! let rng = ChaCha12Rng::from_os_rng();
40+
//! # use {rand_core::SeedableRng, rand_chacha::ChaCha12Rng, rand::rngs::OsRng};
41+
//! let rng = ChaCha12Rng::try_from_rng(&mut OsRng).unwrap();
4242
//! # let _: ChaCha12Rng = rng;
4343
//! ```
4444
//! 2. **From a master generator.** This could be [`rand::rng`]
@@ -76,7 +76,7 @@
7676
//! [`BlockRngCore`]: rand_core::block::BlockRngCore
7777
//! [`RngCore`]: rand_core::RngCore
7878
//! [`SeedableRng`]: rand_core::SeedableRng
79-
//! [`SeedableRng::from_os_rng`]: rand_core::SeedableRng::from_os_rng
79+
//! [`OsRng`]: https://docs.rs/rand/latest/rand/rngs/struct.OsRng.html
8080
//! [`rand::rng`]: https://docs.rs/rand/latest/rand/fn.rng.html
8181
//! [`rand::Rng`]: https://docs.rs/rand/latest/rand/trait.Rng.html
8282

rand_core/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## Unreleased
88
### API changes
99
- Relax `Sized` bound on impls of `SeedableRng` (#1641)
10-
- Fix `OsError::raw_os_error` on UEFI targets by returning `Option<usize>` (#1665)
1110
- Move `rand_core::impls::*` to `rand_core::le` module (#1667)
1211
- Use Edition 2024 and MSRV 1.85 (#1668)
1312
- Remove fn `TryRngCore::read_adapter(..) -> RngReadAdapter` (replaced with `rand::RngReader`) (#1669)
13+
- Remove feature `os_rng`, structs `OsRng` and `OsError` and fns `from_os_rng`, `try_from_os_rng` (#1674)
14+
- Remove feature `std` (#1674)
15+
- Removed dependency `getrandom` (#1674)
1416

1517
## [0.9.3] — 2025-02-29
1618
### Other

0 commit comments

Comments
 (0)