diff --git a/CHANGELOG.md b/CHANGELOG.md index 103abea7a31..35aaf2bc212 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ A [separate changelog is kept for rand_core](rand_core/CHANGELOG.md). You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.html) useful. +## [Unreleased] +- Derive PartialEq+Eq for StdRng, SmallRng, and StepRng (#975) + ## [0.7.3] - 2020-01-10 ### Fixes - The `Bernoulli` distribution constructors now reports an error on NaN and on diff --git a/Cargo.toml b/Cargo.toml index e0581952329..fe6738f5f87 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand" -version = "0.7.3" +version = "0.7.4" authors = ["The Rand Project Developers", "The Rust Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md" @@ -55,7 +55,7 @@ members = [ ] [dependencies] -rand_core = { path = "rand_core", version = "0.5.1" } +rand_core = { path = "rand_core", version = "0.5.2" } rand_pcg = { path = "rand_pcg", version = "0.2", optional = true } log = { version = "0.4.4", optional = true } @@ -73,7 +73,7 @@ libc = { version = "0.2.22", optional = true, default-features = false } # Emscripten does not support 128-bit integers, which are used by ChaCha code. # We work around this by using a different RNG. [target.'cfg(not(target_os = "emscripten"))'.dependencies] -rand_chacha = { path = "rand_chacha", version = "0.2.1", default-features = false, optional = true } +rand_chacha = { path = "rand_chacha", version = "0.2.3", default-features = false, optional = true } [target.'cfg(target_os = "emscripten")'.dependencies] rand_hc = { path = "rand_hc", version = "0.2", optional = true } diff --git a/rand_chacha/CHANGELOG.md b/rand_chacha/CHANGELOG.md index 1273895aff4..3bcd00465dc 100644 --- a/rand_chacha/CHANGELOG.md +++ b/rand_chacha/CHANGELOG.md @@ -4,6 +4,9 @@ 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). +## [Unreleased] +- Derive PartialEq+Eq for ChaChaXRng and ChaChaXCore (#975) + ## [0.2.2] - 2020-03-09 - Integrate `c2-chacha`, reducing dependency count (#931) - Add CryptoRng to ChaChaXCore (#944) diff --git a/rand_chacha/Cargo.toml b/rand_chacha/Cargo.toml index 601fef9169b..d7ead35c03f 100644 --- a/rand_chacha/Cargo.toml +++ b/rand_chacha/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_chacha" -version = "0.2.2" +version = "0.2.3" authors = ["The Rand Project Developers", "The Rust Project Developers", "The CryptoCorrosion Contributors"] license = "MIT OR Apache-2.0" readme = "README.md" @@ -19,7 +19,7 @@ travis-ci = { repository = "rust-random/rand" } appveyor = { repository = "rust-random/rand" } [dependencies] -rand_core = { path = "../rand_core", version = "0.5" } +rand_core = { path = "../rand_core", version = "0.5.2" } ppv-lite86 = { version = "0.2.6", default-features = false, features = ["simd"] } [features] diff --git a/rand_chacha/src/chacha.rs b/rand_chacha/src/chacha.rs index cf68c52c2aa..a05c619c0fb 100644 --- a/rand_chacha/src/chacha.rs +++ b/rand_chacha/src/chacha.rs @@ -61,11 +61,21 @@ impl fmt::Debug for Array64 { write!(f, "Array64 {{}}") } } +impl ::core::cmp::PartialEq for Array64 +where T: ::core::cmp::PartialEq { + fn eq(&self, other: &Array64) -> bool { + &self.0[..] == &other.0[..] + } +} +impl ::core::cmp::Eq for Array64 +where T: ::core::cmp::Eq { +} + macro_rules! chacha_impl { ($ChaChaXCore:ident, $ChaChaXRng:ident, $rounds:expr, $doc:expr) => { #[doc=$doc] - #[derive(Clone)] + #[derive(Clone, PartialEq, Eq)] pub struct $ChaChaXCore { state: ChaCha, } @@ -140,7 +150,7 @@ macro_rules! chacha_impl { /// /// [^2]: [eSTREAM: the ECRYPT Stream Cipher Project]( /// http://www.ecrypt.eu.org/stream/) - #[derive(Clone, Debug)] + #[derive(Clone, Debug, PartialEq, Eq)] pub struct $ChaChaXRng { rng: BlockRng<$ChaChaXCore>, } diff --git a/rand_chacha/src/guts.rs b/rand_chacha/src/guts.rs index 7561c1bcd11..7d13613bb72 100644 --- a/rand_chacha/src/guts.rs +++ b/rand_chacha/src/guts.rs @@ -28,6 +28,24 @@ pub struct ChaCha { pub(crate) d: vec128_storage, } +// Custom PartialEq implementation as `vec128_storage` doesn't implement it. +impl ::core::cmp::PartialEq for ChaCha { + fn eq(&self, other: &ChaCha) -> bool { + unsafe { + ::core::mem::transmute::(self.b) + == ::core::mem::transmute::(other.b) + && ::core::mem::transmute::(self.c) + == ::core::mem::transmute::(other.c) + && ::core::mem::transmute::(self.d) + == ::core::mem::transmute::(other.d) + } + } +} + +// Custom Eq implementation as `vec128_storage` doesn't implement it. +impl ::core::cmp::Eq for ChaCha { +} + #[derive(Clone)] pub struct State { pub(crate) a: V, diff --git a/rand_core/CHANGELOG.md b/rand_core/CHANGELOG.md index dfdd6928ef0..686ae26d404 100644 --- a/rand_core/CHANGELOG.md +++ b/rand_core/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). +## [Unreleased] +- Derive PartialEq+Eq for BlockRng and BlockRng64 (#975) +- Add PartialEq+Eq constraint to BlockRngCore::Results (#975) + ## [0.5.1] - 2019-08-28 - `OsRng` added to `rand_core` (#863) - `Error::INTERNAL_START` and `Error::CUSTOM_START` constants (#864) diff --git a/rand_core/Cargo.toml b/rand_core/Cargo.toml index 945e3f63896..7d09d231631 100644 --- a/rand_core/Cargo.toml +++ b/rand_core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_core" -version = "0.5.1" +version = "0.5.2" authors = ["The Rand Project Developers", "The Rust Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md" diff --git a/rand_core/src/block.rs b/rand_core/src/block.rs index f409662af07..2a69dcf7c22 100644 --- a/rand_core/src/block.rs +++ b/rand_core/src/block.rs @@ -67,7 +67,7 @@ pub trait BlockRngCore { /// Results type. This is the 'block' an RNG implementing `BlockRngCore` /// generates, which will usually be an array like `[u32; 16]`. - type Results: AsRef<[Self::Item]> + AsMut<[Self::Item]> + Default; + type Results: AsRef<[Self::Item]> + AsMut<[Self::Item]> + Default + PartialEq + Eq; /// Generate a new block of results. fn generate(&mut self, results: &mut Self::Results); @@ -109,7 +109,7 @@ pub trait BlockRngCore { /// [`next_u64`]: RngCore::next_u64 /// [`fill_bytes`]: RngCore::fill_bytes /// [`try_fill_bytes`]: RngCore::try_fill_bytes -#[derive(Clone)] +#[derive(Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))] pub struct BlockRng { results: R::Results, @@ -272,7 +272,7 @@ impl SeedableRng for BlockRng { /// [`next_u64`]: RngCore::next_u64 /// [`fill_bytes`]: RngCore::fill_bytes /// [`try_fill_bytes`]: RngCore::try_fill_bytes -#[derive(Clone)] +#[derive(Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))] pub struct BlockRng64 { results: R::Results, diff --git a/rand_hc/CHANGELOG.md b/rand_hc/CHANGELOG.md index a629d7d8c72..c7a522361c8 100644 --- a/rand_hc/CHANGELOG.md +++ b/rand_hc/CHANGELOG.md @@ -4,6 +4,9 @@ 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). +## [Unreleased] +- Derive PartialEq+Eq for Hc128Rng and Hc128Core (#975) + ## [0.2.0] - 2019-06-12 - Bump minor crate version since rand_core bump is a breaking change - Switch to Edition 2018 diff --git a/rand_hc/Cargo.toml b/rand_hc/Cargo.toml index 40cea06e1e4..a2b28cd27d0 100644 --- a/rand_hc/Cargo.toml +++ b/rand_hc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_hc" -version = "0.2.0" +version = "0.2.1" authors = ["The Rand Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md" @@ -19,4 +19,4 @@ travis-ci = { repository = "rust-random/rand" } appveyor = { repository = "rust-random/rand" } [dependencies] -rand_core = { path = "../rand_core", version = "0.5" } +rand_core = { path = "../rand_core", version = "0.5.2" } diff --git a/rand_hc/src/hc128.rs b/rand_hc/src/hc128.rs index 4f192afcb77..d4bfb3329b4 100644 --- a/rand_hc/src/hc128.rs +++ b/rand_hc/src/hc128.rs @@ -63,7 +63,7 @@ const SEED_WORDS: usize = 8; // 128 bit key followed by 128 bit iv /// /// [^5]: Internet Engineering Task Force (February 2015), /// ["Prohibiting RC4 Cipher Suites"](https://tools.ietf.org/html/rfc7465). -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Hc128Rng(BlockRng); impl RngCore for Hc128Rng { @@ -118,6 +118,18 @@ impl fmt::Debug for Hc128Core { } } +// Custom PartialEq implementation as it can't currently be derived from an array of size 1024 +impl ::core::cmp::PartialEq for Hc128Core { + fn eq(&self, other: &Hc128Core) -> bool { + &self.t[..] == &other.t[..] + && self.counter1024 == other.counter1024 + } +} + +// Custom Eq implementation as it can't currently be derived from an array of size 1024 +impl ::core::cmp::Eq for Hc128Core { +} + impl BlockRngCore for Hc128Core { type Item = u32; type Results = [u32; 16]; diff --git a/rand_pcg/CHANGELOG.md b/rand_pcg/CHANGELOG.md index 9f094bbacd2..738278b11b4 100644 --- a/rand_pcg/CHANGELOG.md +++ b/rand_pcg/CHANGELOG.md @@ -4,6 +4,9 @@ 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). +## [Unreleased] +- Derive PartialEq+Eq for Lcg64Xsh32, Lcg128Xsl64, and Mcg128Xsl64 (#975) + ## [0.2.1] - 2019-10-22 - Bump `bincode` version to 1.1.4 to fix minimal-dependency builds - Removed unused `autocfg` build dependency. diff --git a/rand_pcg/Cargo.toml b/rand_pcg/Cargo.toml index 7cfae7987ab..9eb2eaf51e1 100644 --- a/rand_pcg/Cargo.toml +++ b/rand_pcg/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_pcg" -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_pcg/src/pcg128.rs b/rand_pcg/src/pcg128.rs index 63f03b47cba..58a8e36b7c1 100644 --- a/rand_pcg/src/pcg128.rs +++ b/rand_pcg/src/pcg128.rs @@ -29,7 +29,7 @@ use rand_core::{le, Error, RngCore, SeedableRng}; /// Despite the name, this implementation uses 32 bytes (256 bit) space /// comprising 128 bits of state and 128 bits stream selector. These are both /// set by `SeedableRng`, using a 256-bit seed. -#[derive(Clone)] +#[derive(Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))] pub struct Lcg128Xsl64 { state: u128, @@ -130,7 +130,7 @@ impl RngCore for Lcg128Xsl64 { /// Note that compared to the standard `pcg64` (128-bit LCG with PCG-XSL-RR /// output function), this RNG is faster, also has a long cycle, and still has /// good performance on statistical tests. -#[derive(Clone)] +#[derive(Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))] pub struct Mcg128Xsl64 { state: u128, diff --git a/rand_pcg/src/pcg64.rs b/rand_pcg/src/pcg64.rs index ad7dee2f77d..ed7442f9670 100644 --- a/rand_pcg/src/pcg64.rs +++ b/rand_pcg/src/pcg64.rs @@ -29,7 +29,7 @@ const MULTIPLIER: u64 = 6364136223846793005; /// Despite the name, this implementation uses 16 bytes (128 bit) space /// comprising 64 bits of state and 64 bits stream selector. These are both set /// by `SeedableRng`, using a 128-bit seed. -#[derive(Clone)] +#[derive(Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))] pub struct Lcg64Xsh32 { state: u64, diff --git a/src/rngs/mock.rs b/src/rngs/mock.rs index 9a47264a762..785056ce9e3 100644 --- a/src/rngs/mock.rs +++ b/src/rngs/mock.rs @@ -24,7 +24,7 @@ use rand_core::{impls, Error, RngCore}; /// let sample: [u64; 3] = my_rng.gen(); /// assert_eq!(sample, [2, 3, 4]); /// ``` -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct StepRng { v: u64, a: u64, diff --git a/src/rngs/small.rs b/src/rngs/small.rs index d676898149c..2b79de0a4ec 100644 --- a/src/rngs/small.rs +++ b/src/rngs/small.rs @@ -73,7 +73,7 @@ type Rng = rand_pcg::Pcg32; /// [`thread_rng`]: crate::thread_rng /// [rand_chacha]: https://crates.io/crates/rand_chacha /// [rand_pcg]: https://crates.io/crates/rand_pcg -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct SmallRng(Rng); impl RngCore for SmallRng { diff --git a/src/rngs/std.rs b/src/rngs/std.rs index 8b07081a048..7a520d92f3a 100644 --- a/src/rngs/std.rs +++ b/src/rngs/std.rs @@ -32,7 +32,7 @@ pub(crate) use rand_hc::Hc128Core as Core; /// the [rand_chacha] crate directly. /// /// [rand_chacha]: https://crates.io/crates/rand_chacha -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct StdRng(Rng); impl RngCore for StdRng {