mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-04 18:22:57 +02:00
Merge bitcoin/bitcoin#31519: refactor: Use std::span over Span
ffff4a293abench: Update span-serialize comment (MarcoFalke)fa4d6ec97brefactor: Avoid false-positive gcc warning (MarcoFalke)fa942332b4scripted-diff: Bump copyright headers after std::span changes (MarcoFalke)fa0c6b7179refactor: Remove unused Span alias (MarcoFalke)fade0b5e5escripted-diff: Use std::span over Span (MarcoFalke)fadccc26c0refactor: Make Span an alias of std::span (MarcoFalke)fa27e36717test: Fix broken span_tests (MarcoFalke)fadf02ef8brefactor: Return std::span from MakeUCharSpan (MarcoFalke)fa720b94berefactor: Return std::span from MakeByteSpan (MarcoFalke) Pull request description: `Span` has some issues: * It does not support fixed-size spans, which are available through `std::span`. * It is confusing to have it available and in use at the same time with `std::span`. * It does not obey the standard library iterator build hardening flags. See https://github.com/bitcoin/bitcoin/issues/31272 for a discussion. For example, this allows to catch issues like the one fixed in commitfabeca3458. Both types are type-safe and can even implicitly convert into each other in most contexts. However, exclusively using `std::span` seems less confusing, so do it here with a scripted-diff. ACKs for top commit: l0rinc: reACKffff4a293atheuni: ACKffff4a293a. Tree-SHA512: 9cc2f1f43551e2c07cc09f38b1f27d11e57e9e9bc0c6138c8fddd0cef54b91acd8b14711205ff949be874294a121910d0aceffe0e8914c4cff07f1e0e87ad5b8
This commit is contained in:
16
src/random.h
16
src/random.h
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2022 The Bitcoin Core developers
|
||||
// Copyright (c) 2009-present The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -114,7 +114,7 @@ void RandAddEvent(const uint32_t event_info) noexcept;
|
||||
*
|
||||
* Thread-safe.
|
||||
*/
|
||||
void GetRandBytes(Span<unsigned char> bytes) noexcept;
|
||||
void GetRandBytes(std::span<unsigned char> bytes) noexcept;
|
||||
|
||||
/**
|
||||
* Gather entropy from various sources, feed it into the internal PRNG, and
|
||||
@@ -126,7 +126,7 @@ void GetRandBytes(Span<unsigned char> bytes) noexcept;
|
||||
*
|
||||
* Thread-safe.
|
||||
*/
|
||||
void GetStrongRandBytes(Span<unsigned char> bytes) noexcept;
|
||||
void GetStrongRandBytes(std::span<unsigned char> bytes) noexcept;
|
||||
|
||||
|
||||
/* ============================= RANDOM NUMBER GENERATION CLASSES =============================
|
||||
@@ -144,7 +144,7 @@ class RandomMixin;
|
||||
|
||||
/** A concept for RandomMixin-based random number generators. */
|
||||
template<typename T>
|
||||
concept RandomNumberGenerator = requires(T& rng, Span<std::byte> s) {
|
||||
concept RandomNumberGenerator = requires(T& rng, std::span<std::byte> s) {
|
||||
// A random number generator must provide rand64().
|
||||
{ rng.rand64() } noexcept -> std::same_as<uint64_t>;
|
||||
// A random number generator must derive from RandomMixin, which adds other rand* functions.
|
||||
@@ -263,8 +263,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/** Fill a Span with random bytes. */
|
||||
void fillrand(Span<std::byte> span) noexcept
|
||||
/** Fill a span with random bytes. */
|
||||
void fillrand(std::span<std::byte> span) noexcept
|
||||
{
|
||||
while (span.size() >= 8) {
|
||||
uint64_t gen = Impl().rand64();
|
||||
@@ -400,8 +400,8 @@ public:
|
||||
return ReadLE64(buf.data());
|
||||
}
|
||||
|
||||
/** Fill a byte Span with random bytes. This overrides the RandomMixin version. */
|
||||
void fillrand(Span<std::byte> output) noexcept;
|
||||
/** Fill a byte span with random bytes. This overrides the RandomMixin version. */
|
||||
void fillrand(std::span<std::byte> output) noexcept;
|
||||
};
|
||||
|
||||
/** xoroshiro128++ PRNG. Extremely fast, not appropriate for cryptographic purposes.
|
||||
|
||||
Reference in New Issue
Block a user