Remove use of the pointer version of RandBytes, use span always
The pointer-based crypto::RandBytes() overload can't be removed until
nearby stops using it: https://crrev.com/c/5529443 will do this.
The pointer-based base::RandBytes() will be removed next.
Bug: 40284755
Change-Id: I72c79e23e120f988b091dd2576de180a1c60d2b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5514816
Commit-Queue: danakj <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Owners-Override: Daniel Cheng <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1298850}
diff --git a/base/rand_util_unittest.cc b/base/rand_util_unittest.cc
index 0e4bfda..accbebe 100644
--- a/base/rand_util_unittest.cc
+++ b/base/rand_util_unittest.cc
@@ -139,7 +139,6 @@
// Verify that calling base::RandBytes with an empty buffer doesn't fail.
TEST(RandUtilTest, RandBytes0) {
base::RandBytes(span<uint8_t>());
- base::RandBytes(nullptr, 0);
}
TEST(RandUtilTest, RandBytesAsVector) {
@@ -260,10 +259,11 @@
const int kTestIterations = 10;
const size_t kTestBufferSize = 1 * 1024 * 1024;
- std::unique_ptr<uint8_t[]> buffer(new uint8_t[kTestBufferSize]);
+ std::array<uint8_t, kTestBufferSize> buffer;
const base::TimeTicks now = base::TimeTicks::Now();
- for (int i = 0; i < kTestIterations; ++i)
- base::RandBytes(make_span(buffer.get(), kTestBufferSize));
+ for (int i = 0; i < kTestIterations; ++i) {
+ base::RandBytes(buffer);
+ }
const base::TimeTicks end = base::TimeTicks::Now();
LOG(INFO) << "RandBytes(" << kTestBufferSize