mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-05 18:52:29 +02:00
scripted-diff: Use std::span over Span
-BEGIN VERIFY SCRIPT-
ren() { sed -i "s!\<$1\>!$2!g" $( git grep -l "$1" -- "./src" ":(exclude)src/span.h" ":(exclude)src/leveldb/db/log_test.cc" ) ; }
ren Span std::span
ren AsBytes std::as_bytes
ren AsWritableBytes std::as_writable_bytes
sed -i 's!SpanPopBack(Span!SpanPopBack(std::span!g' ./src/span.h
-END VERIFY SCRIPT-
This commit is contained in:
@@ -106,7 +106,7 @@ FUZZ_TARGET(bip324_cipher_roundtrip, .init=Initialize)
|
||||
}
|
||||
|
||||
// Decrypt length
|
||||
uint32_t dec_length = receiver.DecryptLength(Span{ciphertext}.first(initiator.LENGTH_LEN));
|
||||
uint32_t dec_length = receiver.DecryptLength(std::span{ciphertext}.first(initiator.LENGTH_LEN));
|
||||
if (!damage) {
|
||||
assert(dec_length == length);
|
||||
} else {
|
||||
@@ -119,7 +119,7 @@ FUZZ_TARGET(bip324_cipher_roundtrip, .init=Initialize)
|
||||
// Decrypt
|
||||
std::vector<std::byte> decrypt(dec_length);
|
||||
bool dec_ignore{false};
|
||||
bool ok = receiver.Decrypt(Span{ciphertext}.subspan(initiator.LENGTH_LEN), aad, dec_ignore, decrypt);
|
||||
bool ok = receiver.Decrypt(std::span{ciphertext}.subspan(initiator.LENGTH_LEN), aad, dec_ignore, decrypt);
|
||||
// Decryption *must* fail if the packet was damaged, and succeed if it wasn't.
|
||||
assert(!ok == damage);
|
||||
if (!ok) break;
|
||||
|
||||
@@ -108,9 +108,9 @@ void ChaCha20SplitFuzz(FuzzedDataProvider& provider)
|
||||
// This tests that Keystream() has the same behavior as Crypt() applied
|
||||
// to 0x00 input bytes.
|
||||
if (UseCrypt || provider.ConsumeBool()) {
|
||||
crypt2.Crypt(Span{data2}.subspan(bytes2, now), Span{data2}.subspan(bytes2, now));
|
||||
crypt2.Crypt(std::span{data2}.subspan(bytes2, now), std::span{data2}.subspan(bytes2, now));
|
||||
} else {
|
||||
crypt2.Keystream(Span{data2}.subspan(bytes2, now));
|
||||
crypt2.Keystream(std::span{data2}.subspan(bytes2, now));
|
||||
}
|
||||
bytes2 += now;
|
||||
if (is_last) break;
|
||||
|
||||
@@ -18,9 +18,9 @@ constexpr static inline void crypt_till_rekey(FSChaCha20Poly1305& aead, int reke
|
||||
for (int i = 0; i < rekey_interval; ++i) {
|
||||
std::byte dummy_tag[FSChaCha20Poly1305::EXPANSION] = {{}};
|
||||
if (encrypt) {
|
||||
aead.Encrypt(Span{dummy_tag}.first(0), Span{dummy_tag}.first(0), dummy_tag);
|
||||
aead.Encrypt(std::span{dummy_tag}.first(0), std::span{dummy_tag}.first(0), dummy_tag);
|
||||
} else {
|
||||
aead.Decrypt(dummy_tag, Span{dummy_tag}.first(0), Span{dummy_tag}.first(0));
|
||||
aead.Decrypt(dummy_tag, std::span{dummy_tag}.first(0), std::span{dummy_tag}.first(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ FUZZ_TARGET(crypto_aeadchacha20poly1305)
|
||||
|
||||
if (use_splits && length > 0) {
|
||||
size_t split_index = provider.ConsumeIntegralInRange<size_t>(1, length);
|
||||
aead.Encrypt(Span{plain}.first(split_index), Span{plain}.subspan(split_index), aad, nonce, cipher);
|
||||
aead.Encrypt(std::span{plain}.first(split_index), std::span{plain}.subspan(split_index), aad, nonce, cipher);
|
||||
} else {
|
||||
aead.Encrypt(plain, aad, nonce, cipher);
|
||||
}
|
||||
@@ -102,7 +102,7 @@ FUZZ_TARGET(crypto_aeadchacha20poly1305)
|
||||
|
||||
if (use_splits && length > 0) {
|
||||
size_t split_index = provider.ConsumeIntegralInRange<size_t>(1, length);
|
||||
ok = aead.Decrypt(cipher, aad, nonce, Span{decrypted_contents}.first(split_index), Span{decrypted_contents}.subspan(split_index));
|
||||
ok = aead.Decrypt(cipher, aad, nonce, std::span{decrypted_contents}.first(split_index), std::span{decrypted_contents}.subspan(split_index));
|
||||
} else {
|
||||
ok = aead.Decrypt(cipher, aad, nonce, decrypted_contents);
|
||||
}
|
||||
@@ -152,7 +152,7 @@ FUZZ_TARGET(crypto_fschacha20poly1305)
|
||||
crypt_till_rekey(enc_aead, rekey_interval, true);
|
||||
if (use_splits && length > 0) {
|
||||
size_t split_index = provider.ConsumeIntegralInRange<size_t>(1, length);
|
||||
enc_aead.Encrypt(Span{plain}.first(split_index), Span{plain}.subspan(split_index), aad, cipher);
|
||||
enc_aead.Encrypt(std::span{plain}.first(split_index), std::span{plain}.subspan(split_index), aad, cipher);
|
||||
} else {
|
||||
enc_aead.Encrypt(plain, aad, cipher);
|
||||
}
|
||||
@@ -187,7 +187,7 @@ FUZZ_TARGET(crypto_fschacha20poly1305)
|
||||
crypt_till_rekey(dec_aead, rekey_interval, false);
|
||||
if (use_splits && length > 0) {
|
||||
size_t split_index = provider.ConsumeIntegralInRange<size_t>(1, length);
|
||||
ok = dec_aead.Decrypt(cipher, aad, Span{decrypted_contents}.first(split_index), Span{decrypted_contents}.subspan(split_index));
|
||||
ok = dec_aead.Decrypt(cipher, aad, std::span{decrypted_contents}.first(split_index), std::span{decrypted_contents}.subspan(split_index));
|
||||
} else {
|
||||
ok = dec_aead.Decrypt(cipher, aad, decrypted_contents);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
namespace {
|
||||
|
||||
/** Takes the pre-computed and topologically-valid chunks and generates a fee diagram which starts at FeeFrac of (0, 0) */
|
||||
std::vector<FeeFrac> BuildDiagramFromChunks(const Span<const FeeFrac> chunks)
|
||||
std::vector<FeeFrac> BuildDiagramFromChunks(const std::span<const FeeFrac> chunks)
|
||||
{
|
||||
std::vector<FeeFrac> diagram;
|
||||
diagram.reserve(chunks.size() + 1);
|
||||
@@ -34,7 +34,7 @@ std::vector<FeeFrac> BuildDiagramFromChunks(const Span<const FeeFrac> chunks)
|
||||
*
|
||||
* Fees in diagram cannot exceed 2^32, as the returned evaluation could overflow
|
||||
* the FeeFrac::fee field in the result. */
|
||||
FeeFrac EvaluateDiagram(int32_t size, Span<const FeeFrac> diagram)
|
||||
FeeFrac EvaluateDiagram(int32_t size, std::span<const FeeFrac> diagram)
|
||||
{
|
||||
assert(diagram.size() > 0);
|
||||
unsigned not_above = 0;
|
||||
@@ -63,12 +63,12 @@ FeeFrac EvaluateDiagram(int32_t size, Span<const FeeFrac> diagram)
|
||||
return {point_a.fee * dir_coef.size + dir_coef.fee * (size - point_a.size), dir_coef.size};
|
||||
}
|
||||
|
||||
std::weak_ordering CompareFeeFracWithDiagram(const FeeFrac& ff, Span<const FeeFrac> diagram)
|
||||
std::weak_ordering CompareFeeFracWithDiagram(const FeeFrac& ff, std::span<const FeeFrac> diagram)
|
||||
{
|
||||
return FeeRateCompare(FeeFrac{ff.fee, 1}, EvaluateDiagram(ff.size, diagram));
|
||||
}
|
||||
|
||||
std::partial_ordering CompareDiagrams(Span<const FeeFrac> dia1, Span<const FeeFrac> dia2)
|
||||
std::partial_ordering CompareDiagrams(std::span<const FeeFrac> dia1, std::span<const FeeFrac> dia2)
|
||||
{
|
||||
bool all_ge = true;
|
||||
bool all_le = true;
|
||||
|
||||
@@ -23,7 +23,7 @@ FUZZ_TARGET(hex)
|
||||
const std::string random_hex_string(buffer.begin(), buffer.end());
|
||||
const std::vector<unsigned char> data = ParseHex(random_hex_string);
|
||||
const std::vector<std::byte> bytes{ParseHex<std::byte>(random_hex_string)};
|
||||
assert(std::ranges::equal(AsBytes(Span{data}), bytes));
|
||||
assert(std::ranges::equal(std::as_bytes(std::span{data}), bytes));
|
||||
const std::string hex_data = HexStr(data);
|
||||
if (IsHex(random_hex_string)) {
|
||||
assert(ToLower(random_hex_string) == hex_data);
|
||||
|
||||
@@ -129,7 +129,7 @@ struct ParserContext {
|
||||
auto it = TEST_DATA.dummy_key_idx_map.find(key);
|
||||
if (it == TEST_DATA.dummy_key_idx_map.end()) return {};
|
||||
uint8_t idx = it->second;
|
||||
return HexStr(Span{&idx, 1});
|
||||
return HexStr(std::span{&idx, 1});
|
||||
}
|
||||
|
||||
std::vector<unsigned char> ToPKBytes(const Key& key) const {
|
||||
@@ -290,7 +290,7 @@ const struct CheckerContext: BaseSignatureChecker {
|
||||
if (it == TEST_DATA.dummy_sigs.end()) return false;
|
||||
return it->second.first == sig;
|
||||
}
|
||||
bool CheckSchnorrSignature(Span<const unsigned char> sig, Span<const unsigned char> pubkey, SigVersion,
|
||||
bool CheckSchnorrSignature(std::span<const unsigned char> sig, std::span<const unsigned char> pubkey, SigVersion,
|
||||
ScriptExecutionData&, ScriptError*) const override {
|
||||
XOnlyPubKey pk{pubkey};
|
||||
auto it = TEST_DATA.schnorr_sigs.find(pk);
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
|
||||
/** Construct an arith_uint6144 from any multiple of 4 bytes in LE notation,
|
||||
* up to 768 bytes. */
|
||||
arith_uint6144(Span<const uint8_t> bytes) : base_uint{}
|
||||
arith_uint6144(std::span<const uint8_t> bytes) : base_uint{}
|
||||
{
|
||||
assert(bytes.size() % 4 == 0);
|
||||
assert(bytes.size() <= 768);
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
|
||||
/** Serialize an arithm_uint6144 to any multiply of 4 bytes in LE notation,
|
||||
* on the condition that the represented number fits. */
|
||||
void Serialize(Span<uint8_t> bytes) {
|
||||
void Serialize(std::span<uint8_t> bytes) {
|
||||
assert(bytes.size() % 4 == 0);
|
||||
assert(bytes.size() <= 768);
|
||||
for (unsigned i = 0; i * 4 < bytes.size(); ++i) {
|
||||
|
||||
@@ -72,7 +72,7 @@ FUZZ_TARGET(p2p_transport_serialization, .init = initialize_p2p_transport_serial
|
||||
}
|
||||
|
||||
mutable_msg_bytes.insert(mutable_msg_bytes.end(), payload_bytes.begin(), payload_bytes.end());
|
||||
Span<const uint8_t> msg_bytes{mutable_msg_bytes};
|
||||
std::span<const uint8_t> msg_bytes{mutable_msg_bytes};
|
||||
while (msg_bytes.size() > 0) {
|
||||
if (!recv_transport.ReceivedBytes(msg_bytes)) {
|
||||
break;
|
||||
@@ -87,7 +87,7 @@ FUZZ_TARGET(p2p_transport_serialization, .init = initialize_p2p_transport_serial
|
||||
assert(msg.m_time == m_time);
|
||||
|
||||
std::vector<unsigned char> header;
|
||||
auto msg2 = NetMsg::Make(msg.m_type, Span{msg.m_recv});
|
||||
auto msg2 = NetMsg::Make(msg.m_type, std::span{msg.m_recv});
|
||||
bool queued = send_transport.SetMessageToSend(msg2);
|
||||
assert(queued);
|
||||
std::optional<bool> known_more;
|
||||
@@ -191,7 +191,7 @@ void SimulationTest(Transport& initiator, Transport& responder, R& rng, FuzzedDa
|
||||
if (more_nonext) assert(more_next);
|
||||
// Compare with previously reported output.
|
||||
assert(to_send[side].size() <= bytes.size());
|
||||
assert(std::ranges::equal(to_send[side], Span{bytes}.first(to_send[side].size())));
|
||||
assert(std::ranges::equal(to_send[side], std::span{bytes}.first(to_send[side].size())));
|
||||
to_send[side].resize(bytes.size());
|
||||
std::copy(bytes.begin(), bytes.end(), to_send[side].begin());
|
||||
// Remember 'more' results.
|
||||
@@ -252,7 +252,7 @@ void SimulationTest(Transport& initiator, Transport& responder, R& rng, FuzzedDa
|
||||
// Decide span to receive
|
||||
size_t to_recv_len = in_flight[side].size();
|
||||
if (!everything) to_recv_len = provider.ConsumeIntegralInRange<size_t>(0, to_recv_len);
|
||||
Span<const uint8_t> to_recv = Span{in_flight[side]}.first(to_recv_len);
|
||||
std::span<const uint8_t> to_recv = std::span{in_flight[side]}.first(to_recv_len);
|
||||
// Process those bytes
|
||||
while (!to_recv.empty()) {
|
||||
size_t old_len = to_recv.size();
|
||||
|
||||
@@ -25,11 +25,11 @@ class PoolResourceFuzzer
|
||||
size_t m_total_allocated{};
|
||||
|
||||
struct Entry {
|
||||
Span<std::byte> span;
|
||||
std::span<std::byte> span;
|
||||
size_t alignment;
|
||||
uint64_t seed;
|
||||
|
||||
Entry(Span<std::byte> s, size_t a, uint64_t se) : span(s), alignment(a), seed(se) {}
|
||||
Entry(std::span<std::byte> s, size_t a, uint64_t se) : span(s), alignment(a), seed(se) {}
|
||||
};
|
||||
|
||||
std::vector<Entry> m_entries;
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
assert((alignment & (alignment - 1)) == 0); // Alignment must be power of 2.
|
||||
assert((size & (alignment - 1)) == 0); // Size must be a multiple of alignment.
|
||||
|
||||
auto span = Span(static_cast<std::byte*>(m_test_resource.Allocate(size, alignment)), size);
|
||||
auto span = std::span(static_cast<std::byte*>(m_test_resource.Allocate(size, alignment)), size);
|
||||
m_total_allocated += size;
|
||||
|
||||
auto ptr_val = reinterpret_cast<std::uintptr_t>(span.data());
|
||||
|
||||
@@ -15,9 +15,9 @@ FUZZ_TARGET(script_parsing)
|
||||
const size_t query_size = fuzzed_data_provider.ConsumeIntegral<size_t>();
|
||||
const std::string query = fuzzed_data_provider.ConsumeBytesAsString(std::min<size_t>(query_size, 1024 * 1024));
|
||||
const std::string span_str = fuzzed_data_provider.ConsumeRemainingBytesAsString();
|
||||
const Span<const char> const_span{span_str};
|
||||
const std::span<const char> const_span{span_str};
|
||||
|
||||
Span<const char> mut_span = const_span;
|
||||
std::span<const char> mut_span = const_span;
|
||||
(void)script::Const(query, mut_span);
|
||||
|
||||
mut_span = const_span;
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
return m_fuzzed_data_provider.ConsumeBool();
|
||||
}
|
||||
|
||||
bool CheckSchnorrSignature(Span<const unsigned char> sig, Span<const unsigned char> pubkey, SigVersion sigversion, ScriptExecutionData& execdata, ScriptError* serror = nullptr) const override
|
||||
bool CheckSchnorrSignature(std::span<const unsigned char> sig, std::span<const unsigned char> pubkey, SigVersion sigversion, ScriptExecutionData& execdata, ScriptError* serror = nullptr) const override
|
||||
{
|
||||
return m_fuzzed_data_provider.ConsumeBool();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ FUZZ_TARGET(span)
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
|
||||
std::string str = fuzzed_data_provider.ConsumeBytesAsString(32);
|
||||
const Span<const char> span{str};
|
||||
const std::span<const char> span{str};
|
||||
(void)span.data();
|
||||
(void)span.begin();
|
||||
(void)span.end();
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
std::vector<uint8_t> ConstructPubKeyBytes(FuzzedDataProvider& fuzzed_data_provider, Span<const uint8_t> byte_data, const bool compressed) noexcept
|
||||
std::vector<uint8_t> ConstructPubKeyBytes(FuzzedDataProvider& fuzzed_data_provider, std::span<const uint8_t> byte_data, const bool compressed) noexcept
|
||||
{
|
||||
uint8_t pk_type;
|
||||
if (compressed) {
|
||||
|
||||
@@ -87,7 +87,7 @@ void utxo_snapshot_fuzz(FuzzBufferType buffer)
|
||||
// Metadata
|
||||
if (fuzzed_data_provider.ConsumeBool()) {
|
||||
std::vector<uint8_t> metadata{ConsumeRandomLengthByteVector(fuzzed_data_provider)};
|
||||
outfile << Span{metadata};
|
||||
outfile << std::span{metadata};
|
||||
} else {
|
||||
auto msg_start = chainman.GetParams().MessageStart();
|
||||
int base_blockheight{fuzzed_data_provider.ConsumeIntegralInRange<int>(1, 2 * COINBASE_MATURITY)};
|
||||
@@ -99,7 +99,7 @@ void utxo_snapshot_fuzz(FuzzBufferType buffer)
|
||||
// Coins
|
||||
if (fuzzed_data_provider.ConsumeBool()) {
|
||||
std::vector<uint8_t> file_data{ConsumeRandomLengthByteVector(fuzzed_data_provider)};
|
||||
outfile << Span{file_data};
|
||||
outfile << std::span{file_data};
|
||||
} else {
|
||||
int height{0};
|
||||
for (const auto& block : *g_chain) {
|
||||
|
||||
@@ -24,7 +24,7 @@ static constexpr size_t MAX_OPERATIONS{1024};
|
||||
* T must be constructible from a uint64_t seed, comparable to other T, copyable, and movable.
|
||||
*/
|
||||
template<typename T, bool CheckNoneLeft>
|
||||
void TestType(Span<const uint8_t> buffer, uint64_t rng_tweak)
|
||||
void TestType(std::span<const uint8_t> buffer, uint64_t rng_tweak)
|
||||
{
|
||||
FuzzedDataProvider provider(buffer.data(), buffer.size());
|
||||
// Local RNG, only used for the seeds to initialize T objects with.
|
||||
|
||||
Reference in New Issue
Block a user