diff --git a/rand_core/CHANGELOG.md b/rand_core/CHANGELOG.md index 4542a3b6f9d..c96d886bc71 100644 --- a/rand_core/CHANGELOG.md +++ b/rand_core/CHANGELOG.md @@ -4,38 +4,50 @@ All notable changes to this project will be documented in this file. 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). +## [0.5.1] - 2019-09-02 +### Added +- `OsRng` added to `rand_core` (#863) + ## [0.5.0] - 2019-06-06 +### Changed - Enable testing with Miri and fix incorrect pointer usages (#779, #780, #781, #783, #784) - Rewrite `Error` type and adjust API (#800) - Adjust usage of `#[inline]` for `BlockRng` and `BlockRng64` ## [0.4.0] - 2019-01-24 +### Changed - Disable the `std` feature by default (#702) ## [0.3.0] - 2018-09-24 +### Added - Add `SeedableRng::seed_from_u64` for convenient seeding. (#537) ## [0.2.1] - 2018-06-08 +### Added - References to a `CryptoRng` now also implement `CryptoRng`. (#470) ## [0.2.0] - 2018-05-21 +### Changed - Enable the `std` feature by default. (#409) - Remove `BlockRng{64}::inner` and `BlockRng::inner_mut`; instead making `core` public -- Add `BlockRng{64}::index` and `BlockRng{64}::generate_and_set`. (#374, #419) - Change `BlockRngCore::Results` bound to also require `AsMut<[Self::Item]>`. (#419) +### Added +- Add `BlockRng{64}::index` and `BlockRng{64}::generate_and_set`. (#374, #419) - Implement `std::io::Read` for RngCore. (#434) ## [0.1.0] - 2018-04-17 -(Split out of the Rand crate, changes here are relative to rand 0.4.2) +(Split out of the Rand crate, changes here are relative to rand 0.4.2.) +### Added - `RngCore` and `SeedableRng` are now part of `rand_core`. (#288) - Add modules to help implementing RNGs `impl` and `le`. (#209, #228) - Add `Error` and `ErrorKind`. (#225) - Add `CryptoRng` marker trait. (#273) - Add `BlockRngCore` trait. (#281) - Add `BlockRng` and `BlockRng64` wrappers to help implementations. (#281, #325) +- Add `RngCore::try_fill_bytes`. (#225) +### Changed - Revise the `SeedableRng` trait. (#233) - Remove default implementations for `RngCore::next_u64` and `RngCore::fill_bytes`. (#288) -- Add `RngCore::try_fill_bytes`. (#225) ## [0.0.1] - 2017-09-14 (yanked) Experimental version as part of the rand crate refactor. diff --git a/rand_core/Cargo.toml b/rand_core/Cargo.toml index b9042c04f52..e52af5f25fe 100644 --- a/rand_core/Cargo.toml +++ b/rand_core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_core" -version = "0.5.0" +version = "0.5.1" authors = ["The Rand Project Developers", "The Rust Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md" diff --git a/rand_core/src/lib.rs b/rand_core/src/lib.rs index 96b94575ae6..40160022a2c 100644 --- a/rand_core/src/lib.rs +++ b/rand_core/src/lib.rs @@ -49,12 +49,14 @@ use core::ptr::copy_nonoverlapping; #[cfg(all(feature="alloc", not(feature="std")))] use alloc::boxed::Box; pub use error::Error; +#[cfg(feature="getrandom")] pub use os::OsRng; mod error; pub mod block; pub mod impls; pub mod le; +#[cfg(feature="getrandom")] mod os; /// The core of a random number generator. diff --git a/src/rngs/os.rs b/rand_core/src/os.rs similarity index 81% rename from src/rngs/os.rs rename to rand_core/src/os.rs index 46c3483d944..fc23a57d960 100644 --- a/src/rngs/os.rs +++ b/rand_core/src/os.rs @@ -9,8 +9,8 @@ //! Interface to the random number generator of the operating system. // Note: keep this code in sync with the rand_os crate! -use crate::getrandom::getrandom; -use rand_core::{CryptoRng, RngCore, Error, impls}; +use getrandom::getrandom; +use crate::{CryptoRng, RngCore, Error, impls}; /// A random number generator that retrieves randomness from from the /// operating system. @@ -20,6 +20,9 @@ use rand_core::{CryptoRng, RngCore, Error, impls}; /// The implementation is provided by the [getrandom] crate. Refer to /// [getrandom] documentation for details. /// +/// This struct is only available when specifying the crate feature `getrandom` +/// or `std`. When using the `rand` lib, it is also available as `rand::rngs::OsRng`. +/// /// # Blocking and error handling /// /// 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}; /// /// # Usage example /// ``` -/// use rand::rngs::{StdRng, OsRng}; -/// use rand::{RngCore, SeedableRng}; +/// use rand_core::{RngCore, OsRng}; /// /// let mut key = [0u8; 16]; /// OsRng.fill_bytes(&mut key); /// let random_u64 = OsRng.next_u64(); -/// -/// // OsRng is especially useful for seeding other RNGs (see also from_entropy) -/// let mut rng = StdRng::from_rng(OsRng).unwrap(); -/// let _ = rng.next_u32(); /// ``` /// /// [getrandom]: https://crates.io/crates/getrandom #[derive(Clone, Copy, Debug, Default)] pub struct OsRng; -impl OsRng { - /// Create a new `OsRng`. - #[deprecated(since="0.7.0", note="replace OsRng::new().unwrap() with just OsRng")] - pub fn new() -> Result { - Ok(OsRng) - } -} - impl CryptoRng for OsRng {} impl RngCore for OsRng { diff --git a/rand_os/CHANGELOG.md b/rand_os/CHANGELOG.md index 9b8f2081acd..b0c6549ab10 100644 --- a/rand_os/CHANGELOG.md +++ b/rand_os/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. 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). +## [0.2.2] - 2019-09-02 +### Changed +- `OsRng` added to `rand_core`, rendering this crate deprecated (#863) + ## [0.2.1] - 2019-08-08 ### Fixed - Fix `no_std` support. diff --git a/rand_os/Cargo.toml b/rand_os/Cargo.toml index 6edf27dbb3c..c8010e28c10 100644 --- a/rand_os/Cargo.toml +++ b/rand_os/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_os" -version = "0.2.1" +version = "0.2.2" authors = ["The Rand Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md" diff --git a/rand_os/README.md b/rand_os/README.md index 8ed8c50289a..7b68b35cf62 100644 --- a/rand_os/README.md +++ b/rand_os/README.md @@ -11,6 +11,8 @@ A random number generator that retrieves randomness straight from the operating system. +**This crate is deprecated:** `OsRng` is available in `rand_core` since version 0.5.1. + This crate provides `OsRng` as a shim around [getrandom](https://crates.io/crates/getrandom) implementing `RngCore` from [rand_core](https://crates.io/crates/rand_core). diff --git a/rand_os/src/lib.rs b/rand_os/src/lib.rs index 9090ab8250a..abfdf798c06 100644 --- a/rand_os/src/lib.rs +++ b/rand_os/src/lib.rs @@ -19,6 +19,8 @@ #![no_std] // but see getrandom crate +#![deprecated(since="0.2.2", note="OsRng is now provided by rand_core and rand")] + pub use rand_core; // re-export use getrandom::getrandom; @@ -45,6 +47,7 @@ use rand_core::{CryptoRng, RngCore, Error, impls}; /// /// # Usage example /// ``` +/// #![allow(deprecated)] /// use rand_os::rand_core::RngCore; /// use rand_os::OsRng; /// diff --git a/src/rngs/mod.rs b/src/rngs/mod.rs index f9cfe8029c8..abf3243c10f 100644 --- a/src/rngs/mod.rs +++ b/src/rngs/mod.rs @@ -116,5 +116,4 @@ pub use self::small::SmallRng; pub use self::std::StdRng; #[cfg(feature="std")] pub use self::thread::ThreadRng; -#[cfg(feature="getrandom")] mod os; -#[cfg(feature="getrandom")] pub use self::os::OsRng; +#[cfg(feature="getrandom")] pub use rand_core::OsRng;