diff options
author | Haibo Huang <hhb@google.com> | 2021-02-19 17:59:41 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-02-19 17:59:41 +0000 |
commit | 61b225bea8a08a89d17d60c7e7346d126cf0efee (patch) | |
tree | 6be8269cdfd8fe766424806fd5f9415196a8a1df | |
parent | 9b206fcf3c2b029bb83000d810775ef408374aa7 (diff) | |
parent | fd82a8843e6ca745eddc7036f31bbb653ae0271c (diff) | |
download | rand_core-61b225bea8a08a89d17d60c7e7346d126cf0efee.tar.gz |
Upgrade rust/crates/rand_core to 0.6.2 am: cf398cf7b4 am: 87a47c637f am: 938d22c308 am: fd82a8843e
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/rand_core/+/1592901
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: I76f40a12f3d2f7afe9deeec1c134650dfcbe5a34
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 46 | ||||
-rw-r--r-- | CHANGELOG.md | 12 | ||||
-rw-r--r-- | Cargo.toml | 9 | ||||
-rw-r--r-- | Cargo.toml.orig | 9 | ||||
-rw-r--r-- | METADATA | 10 | ||||
-rw-r--r-- | TEST_MAPPING | 11 | ||||
-rw-r--r-- | src/le.rs | 4 | ||||
-rw-r--r-- | src/lib.rs | 22 |
9 files changed, 64 insertions, 61 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 0db4f9b..3fd44e0 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "98e220c30234370fb04ba928799ebd9727fc049a" + "sha1": "3a03c9eb5350e03a3f540dba2ee34e0984f2c2c2" } } @@ -1,42 +1,5 @@ // This file is generated by cargo2android.py --device --run --features=std --dependencies --tests. -package { - default_applicable_licenses: ["external_rust_crates_rand_core_license"], -} - -// Added automatically by a large-scale-change that took the approach of -// 'apply every license found to every target'. While this makes sure we respect -// every license restriction, it may not be entirely correct. -// -// e.g. GPL in an MIT project might only apply to the contrib/ directory. -// -// Please consider splitting the single license below into multiple licenses, -// taking care not to lose any license_kind information, and overriding the -// default license using the 'licenses: [...]' property on targets as needed. -// -// For unused files, consider creating a 'filegroup' with "//visibility:private" -// to attach the license to, and including a comment whether the files may be -// used in the current project. -// -// large-scale-change included anything that looked like it might be a license -// text as a license_text. e.g. LICENSE, NOTICE, COPYING etc. -// -// Please consider removing redundant or irrelevant files from 'license_text:'. -// http://go/android-license-faq -license { - name: "external_rust_crates_rand_core_license", - visibility: [":__subpackages__"], - license_kinds: [ - "SPDX-license-identifier-Apache-2.0", - "SPDX-license-identifier-MIT", - ], - license_text: [ - "COPYRIGHT", - "LICENSE-APACHE", - "LICENSE-MIT", - ], -} - rust_library { name: "librand_core", host_supported: true, @@ -73,6 +36,9 @@ rust_defaults { rust_test_host { name: "rand_core_host_test_src_lib", defaults: ["rand_core_defaults"], + test_options: { + unit_test: true, + }, } rust_test { @@ -81,6 +47,6 @@ rust_test { } // dependent_library ["feature_list"] -// cfg-if-0.1.10 -// getrandom-0.2.0 "std" -// libc-0.2.81 +// cfg-if-1.0.0 +// getrandom-0.2.2 "std" +// libc-0.2.86 diff --git a/CHANGELOG.md b/CHANGELOG.md index 63a8bb8..23d1fa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,18 @@ 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.6.2] - 2021-02-12 +### Fixed +- Fixed assertions in `le::read_u32_into` and `le::read_u64_into` which could + have allowed buffers not to be fully populated (#1096) + +## [0.6.1] - 2021-01-03 +### Fixed +- Avoid panic when using `RngCore::seed_from_u64` with a seed which is not a + multiple of four (#1082) +### Other +- Enable all stable features in the playground (#1081) + ## [0.6.0] - 2020-12-08 ### Breaking changes - Bump MSRV to 1.36, various code improvements (#1011) @@ -13,11 +13,11 @@ [package] edition = "2018" name = "rand_core" -version = "0.6.0" +version = "0.6.2" authors = ["The Rand Project Developers", "The Rust Project Developers"] description = "Core random number generator traits and tools for implementation.\n" -homepage = "https://crates.io/crates/rand_core" -documentation = "https://rust-random.github.io/rand/rand_core/" +homepage = "https://rust-random.github.io/book" +documentation = "https://docs.rs/rand_core" readme = "README.md" keywords = ["random", "rng"] categories = ["algorithms", "no-std"] @@ -26,6 +26,9 @@ repository = "https://github.com/rust-random/rand" [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "doc_cfg"] + +[package.metadata.playground] +all-features = true [dependencies.getrandom] version = "0.2" optional = true diff --git a/Cargo.toml.orig b/Cargo.toml.orig index c383b31..d460757 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,12 +1,12 @@ [package] name = "rand_core" -version = "0.6.0" +version = "0.6.2" authors = ["The Rand Project Developers", "The Rust Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md" repository = "https://github.com/rust-random/rand" -documentation = "https://rust-random.github.io/rand/rand_core/" -homepage = "https://crates.io/crates/rand_core" +documentation = "https://docs.rs/rand_core" +homepage = "https://rust-random.github.io/book" description = """ Core random number generator traits and tools for implementation. """ @@ -28,3 +28,6 @@ getrandom = { version = "0.2", optional = true } # RUSTDOCFLAGS="--cfg doc_cfg" cargo +nightly doc --all-features --no-deps --open all-features = true rustdoc-args = ["--cfg", "doc_cfg"] + +[package.metadata.playground] +all-features = true @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/rand_core/rand_core-0.6.0.crate" + value: "https://static.crates.io/crates/rand_core/rand_core-0.6.2.crate" } - version: "0.6.0" + version: "0.6.2" license_type: NOTICE last_upgrade_date { - year: 2020 - month: 12 - day: 15 + year: 2021 + month: 2 + day: 17 } } diff --git a/TEST_MAPPING b/TEST_MAPPING index 7b95466..963506b 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -1,7 +1,16 @@ -// Generated by cargo2android.py for tests in Android.bp +// Generated by update_crate_tests.py for tests that depend on this crate. { "presubmit": [ { + "name": "rand_xorshift_device_test_tests_mod" + }, + { + "name": "keystore2_test" + }, + { + "name": "rand_xorshift_device_test_src_lib" + }, + { "name": "rand_core_device_test_src_lib" } ] @@ -16,7 +16,7 @@ use core::convert::TryInto; /// Reads unsigned 32 bit integers from `src` into `dst`. #[inline] pub fn read_u32_into(src: &[u8], dst: &mut [u32]) { - assert!(4 * src.len() >= dst.len()); + assert!(src.len() >= 4 * dst.len()); for (out, chunk) in dst.iter_mut().zip(src.chunks_exact(4)) { *out = u32::from_le_bytes(chunk.try_into().unwrap()); } @@ -25,7 +25,7 @@ pub fn read_u32_into(src: &[u8], dst: &mut [u32]) { /// Reads unsigned 64 bit integers from `src` into `dst`. #[inline] pub fn read_u64_into(src: &[u8], dst: &mut [u64]) { - assert!(8 * src.len() >= dst.len()); + assert!(src.len() >= 8 * dst.len()); for (out, chunk) in dst.iter_mut().zip(src.chunks_exact(8)) { *out = u64::from_le_bytes(chunk.try_into().unwrap()); } @@ -300,20 +300,30 @@ pub trait SeedableRng: Sized { /// considered a value-breaking change. fn seed_from_u64(mut state: u64) -> Self { // We use PCG32 to generate a u32 sequence, and copy to the seed - const MUL: u64 = 6364136223846793005; - const INC: u64 = 11634580027462260723; + fn pcg32(state: &mut u64) -> [u8; 4] { + const MUL: u64 = 6364136223846793005; + const INC: u64 = 11634580027462260723; - let mut seed = Self::Seed::default(); - for chunk in seed.as_mut().chunks_mut(4) { // We advance the state first (to get away from the input value, // in case it has low Hamming Weight). - state = state.wrapping_mul(MUL).wrapping_add(INC); + *state = state.wrapping_mul(MUL).wrapping_add(INC); + let state = *state; // Use PCG output function with to_le to generate x: let xorshifted = (((state >> 18) ^ state) >> 27) as u32; let rot = (state >> 59) as u32; let x = xorshifted.rotate_right(rot); - chunk.copy_from_slice(&x.to_le_bytes()); + x.to_le_bytes() + } + + let mut seed = Self::Seed::default(); + let mut iter = seed.as_mut().chunks_exact_mut(4); + for chunk in &mut iter { + chunk.copy_from_slice(&pcg32(&mut state)); + } + let rem = iter.into_remainder(); + if !rem.is_empty() { + rem.copy_from_slice(&pcg32(&mut state)[..rem.len()]); } Self::from_seed(seed) |