Skip to content

Commit 18ce640

Browse files
authored
Merge pull request #863 from dhardy/osrng
Move OsRng to rand_core
2 parents 8616945 + 06c801e commit 18ce640

File tree

9 files changed

+35
-23
lines changed

9 files changed

+35
-23
lines changed

rand_core/CHANGELOG.md

+15-3
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,50 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.5.1] - 2019-09-02
8+
### Added
9+
- `OsRng` added to `rand_core` (#863)
10+
711
## [0.5.0] - 2019-06-06
12+
### Changed
813
- Enable testing with Miri and fix incorrect pointer usages (#779, #780, #781, #783, #784)
914
- Rewrite `Error` type and adjust API (#800)
1015
- Adjust usage of `#[inline]` for `BlockRng` and `BlockRng64`
1116

1217
## [0.4.0] - 2019-01-24
18+
### Changed
1319
- Disable the `std` feature by default (#702)
1420

1521
## [0.3.0] - 2018-09-24
22+
### Added
1623
- Add `SeedableRng::seed_from_u64` for convenient seeding. (#537)
1724

1825
## [0.2.1] - 2018-06-08
26+
### Added
1927
- References to a `CryptoRng` now also implement `CryptoRng`. (#470)
2028

2129
## [0.2.0] - 2018-05-21
30+
### Changed
2231
- Enable the `std` feature by default. (#409)
2332
- Remove `BlockRng{64}::inner` and `BlockRng::inner_mut`; instead making `core` public
24-
- Add `BlockRng{64}::index` and `BlockRng{64}::generate_and_set`. (#374, #419)
2533
- Change `BlockRngCore::Results` bound to also require `AsMut<[Self::Item]>`. (#419)
34+
### Added
35+
- Add `BlockRng{64}::index` and `BlockRng{64}::generate_and_set`. (#374, #419)
2636
- Implement `std::io::Read` for RngCore. (#434)
2737

2838
## [0.1.0] - 2018-04-17
29-
(Split out of the Rand crate, changes here are relative to rand 0.4.2)
39+
(Split out of the Rand crate, changes here are relative to rand 0.4.2.)
40+
### Added
3041
- `RngCore` and `SeedableRng` are now part of `rand_core`. (#288)
3142
- Add modules to help implementing RNGs `impl` and `le`. (#209, #228)
3243
- Add `Error` and `ErrorKind`. (#225)
3344
- Add `CryptoRng` marker trait. (#273)
3445
- Add `BlockRngCore` trait. (#281)
3546
- Add `BlockRng` and `BlockRng64` wrappers to help implementations. (#281, #325)
47+
- Add `RngCore::try_fill_bytes`. (#225)
48+
### Changed
3649
- Revise the `SeedableRng` trait. (#233)
3750
- Remove default implementations for `RngCore::next_u64` and `RngCore::fill_bytes`. (#288)
38-
- Add `RngCore::try_fill_bytes`. (#225)
3951

4052
## [0.0.1] - 2017-09-14 (yanked)
4153
Experimental version as part of the rand crate refactor.

rand_core/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rand_core"
3-
version = "0.5.0"
3+
version = "0.5.1"
44
authors = ["The Rand Project Developers", "The Rust Project Developers"]
55
license = "MIT OR Apache-2.0"
66
readme = "README.md"

rand_core/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ use core::ptr::copy_nonoverlapping;
4949
#[cfg(all(feature="alloc", not(feature="std")))] use alloc::boxed::Box;
5050

5151
pub use error::Error;
52+
#[cfg(feature="getrandom")] pub use os::OsRng;
5253

5354

5455
mod error;
5556
pub mod block;
5657
pub mod impls;
5758
pub mod le;
59+
#[cfg(feature="getrandom")] mod os;
5860

5961

6062
/// The core of a random number generator.

src/rngs/os.rs rand_core/src/os.rs

+6-16
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
//! Interface to the random number generator of the operating system.
1010
// Note: keep this code in sync with the rand_os crate!
1111

12-
use crate::getrandom::getrandom;
13-
use rand_core::{CryptoRng, RngCore, Error, impls};
12+
use getrandom::getrandom;
13+
use crate::{CryptoRng, RngCore, Error, impls};
1414

1515
/// A random number generator that retrieves randomness from from the
1616
/// operating system.
@@ -20,6 +20,9 @@ use rand_core::{CryptoRng, RngCore, Error, impls};
2020
/// The implementation is provided by the [getrandom] crate. Refer to
2121
/// [getrandom] documentation for details.
2222
///
23+
/// This struct is only available when specifying the crate feature `getrandom`
24+
/// or `std`. When using the `rand` lib, it is also available as `rand::rngs::OsRng`.
25+
///
2326
/// # Blocking and error handling
2427
///
2528
/// It is possible that when used during early boot the first call to `OsRng`
@@ -33,30 +36,17 @@ use rand_core::{CryptoRng, RngCore, Error, impls};
3336
///
3437
/// # Usage example
3538
/// ```
36-
/// use rand::rngs::{StdRng, OsRng};
37-
/// use rand::{RngCore, SeedableRng};
39+
/// use rand_core::{RngCore, OsRng};
3840
///
3941
/// let mut key = [0u8; 16];
4042
/// OsRng.fill_bytes(&mut key);
4143
/// let random_u64 = OsRng.next_u64();
42-
///
43-
/// // OsRng is especially useful for seeding other RNGs (see also from_entropy)
44-
/// let mut rng = StdRng::from_rng(OsRng).unwrap();
45-
/// let _ = rng.next_u32();
4644
/// ```
4745
///
4846
/// [getrandom]: https://crates.io/crates/getrandom
4947
#[derive(Clone, Copy, Debug, Default)]
5048
pub struct OsRng;
5149

52-
impl OsRng {
53-
/// Create a new `OsRng`.
54-
#[deprecated(since="0.7.0", note="replace OsRng::new().unwrap() with just OsRng")]
55-
pub fn new() -> Result<OsRng, Error> {
56-
Ok(OsRng)
57-
}
58-
}
59-
6050
impl CryptoRng for OsRng {}
6151

6252
impl RngCore for OsRng {

rand_os/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.2.2] - 2019-09-02
8+
### Changed
9+
- `OsRng` added to `rand_core`, rendering this crate deprecated (#863)
10+
711
## [0.2.1] - 2019-08-08
812
### Fixed
913
- Fix `no_std` support.

rand_os/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rand_os"
3-
version = "0.2.1"
3+
version = "0.2.2"
44
authors = ["The Rand Project Developers"]
55
license = "MIT OR Apache-2.0"
66
readme = "README.md"

rand_os/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
A random number generator that retrieves randomness straight from the
1212
operating system.
1313

14+
**This crate is deprecated:** `OsRng` is available in `rand_core` since version 0.5.1.
15+
1416
This crate provides `OsRng` as a shim around
1517
[getrandom](https://crates.io/crates/getrandom)
1618
implementing `RngCore` from [rand_core](https://crates.io/crates/rand_core).

rand_os/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#![no_std] // but see getrandom crate
2121

22+
#![deprecated(since="0.2.2", note="OsRng is now provided by rand_core and rand")]
23+
2224
pub use rand_core; // re-export
2325

2426
use getrandom::getrandom;
@@ -45,6 +47,7 @@ use rand_core::{CryptoRng, RngCore, Error, impls};
4547
///
4648
/// # Usage example
4749
/// ```
50+
/// #![allow(deprecated)]
4851
/// use rand_os::rand_core::RngCore;
4952
/// use rand_os::OsRng;
5053
///

src/rngs/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,4 @@ pub use self::small::SmallRng;
116116
pub use self::std::StdRng;
117117
#[cfg(feature="std")] pub use self::thread::ThreadRng;
118118

119-
#[cfg(feature="getrandom")] mod os;
120-
#[cfg(feature="getrandom")] pub use self::os::OsRng;
119+
#[cfg(feature="getrandom")] pub use rand_core::OsRng;

0 commit comments

Comments
 (0)