mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-09 06:09:48 +02:00
Make DecodeBase{32,64} always return vector, not string
Base32/base64 are mechanisms for encoding binary data. That they'd decode to a string is just bizarre. The fact that they'd do that based on the type of input arguments even more so.
This commit is contained in:
@@ -23,9 +23,9 @@ BOOST_AUTO_TEST_CASE(base32_testvectors)
|
||||
strEnc = EncodeBase32(vstrIn[i], false);
|
||||
BOOST_CHECK_EQUAL(strEnc, vstrOutNoPadding[i]);
|
||||
bool invalid;
|
||||
std::string strDec = DecodeBase32(vstrOut[i], &invalid);
|
||||
auto dec = DecodeBase32(vstrOut[i], &invalid);
|
||||
BOOST_CHECK(!invalid);
|
||||
BOOST_CHECK_EQUAL(strDec, vstrIn[i]);
|
||||
BOOST_CHECK_MESSAGE(MakeByteSpan(dec) == MakeByteSpan(vstrIn[i]), vstrOut[i]);
|
||||
}
|
||||
|
||||
// Decoding strings with embedded NUL characters should fail
|
||||
|
||||
@@ -20,9 +20,9 @@ BOOST_AUTO_TEST_CASE(base64_testvectors)
|
||||
std::string strEnc = EncodeBase64(vstrIn[i]);
|
||||
BOOST_CHECK_EQUAL(strEnc, vstrOut[i]);
|
||||
bool invalid;
|
||||
std::string strDec = DecodeBase64(strEnc, &invalid);
|
||||
auto dec = DecodeBase64(strEnc, &invalid);
|
||||
BOOST_CHECK(!invalid);
|
||||
BOOST_CHECK_EQUAL(strDec, vstrIn[i]);
|
||||
BOOST_CHECK_MESSAGE(MakeByteSpan(dec) == MakeByteSpan(vstrIn[i]), vstrOut[i]);
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -37,16 +37,16 @@ FUZZ_TARGET_INIT(base_encode_decode, initialize_base_encode_decode)
|
||||
}
|
||||
|
||||
bool pf_invalid;
|
||||
std::string decoded_string = DecodeBase32(random_encoded_string, &pf_invalid);
|
||||
decoded = DecodeBase32(random_encoded_string, &pf_invalid);
|
||||
if (!pf_invalid) {
|
||||
const std::string encoded_string = EncodeBase32(decoded_string);
|
||||
const std::string encoded_string = EncodeBase32(decoded);
|
||||
assert(encoded_string == TrimString(encoded_string));
|
||||
assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string)));
|
||||
}
|
||||
|
||||
decoded_string = DecodeBase64(random_encoded_string, &pf_invalid);
|
||||
decoded = DecodeBase64(random_encoded_string, &pf_invalid);
|
||||
if (!pf_invalid) {
|
||||
const std::string encoded_string = EncodeBase64(decoded_string);
|
||||
const std::string encoded_string = EncodeBase64(decoded);
|
||||
assert(encoded_string == TrimString(encoded_string));
|
||||
assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string)));
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@ FUZZ_TARGET_INIT(psbt, initialize_psbt)
|
||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||
PartiallySignedTransaction psbt_mut;
|
||||
std::string error;
|
||||
if (!DecodeRawPSBT(psbt_mut, fuzzed_data_provider.ConsumeRandomLengthString(), error)) {
|
||||
auto str = fuzzed_data_provider.ConsumeRandomLengthString();
|
||||
if (!DecodeRawPSBT(psbt_mut, MakeByteSpan(str), error)) {
|
||||
return;
|
||||
}
|
||||
const PartiallySignedTransaction psbt = psbt_mut;
|
||||
@@ -79,7 +80,8 @@ FUZZ_TARGET_INIT(psbt, initialize_psbt)
|
||||
}
|
||||
|
||||
PartiallySignedTransaction psbt_merge;
|
||||
if (!DecodeRawPSBT(psbt_merge, fuzzed_data_provider.ConsumeRandomLengthString(), error)) {
|
||||
str = fuzzed_data_provider.ConsumeRandomLengthString();
|
||||
if (!DecodeRawPSBT(psbt_merge, MakeByteSpan(str), error)) {
|
||||
psbt_merge = psbt;
|
||||
}
|
||||
psbt_mut = psbt;
|
||||
|
||||
Reference in New Issue
Block a user