mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
fuzz: replace hardcoded numbers for bech32 limits
Use bech32::CharLimit::BECH32 and bech32::CHECKSUM_SIZE instead of hardcoded values. This is a follow-up fix for #34007 (where this file was missed)
This commit is contained in:
parent
949b673472
commit
59c0ece0a7
3 changed files with 6 additions and 5 deletions
|
@ -19,9 +19,6 @@ namespace
|
||||||
|
|
||||||
typedef std::vector<uint8_t> data;
|
typedef std::vector<uint8_t> data;
|
||||||
|
|
||||||
/** The Bech32 and Bech32m checksum size */
|
|
||||||
constexpr size_t CHECKSUM_SIZE = 6;
|
|
||||||
|
|
||||||
/** The Bech32 and Bech32m character set for encoding. */
|
/** The Bech32 and Bech32m character set for encoding. */
|
||||||
const char* CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
|
const char* CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,9 @@
|
||||||
namespace bech32
|
namespace bech32
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** The Bech32 and Bech32m checksum size */
|
||||||
|
constexpr size_t CHECKSUM_SIZE = 6;
|
||||||
|
|
||||||
enum class Encoding {
|
enum class Encoding {
|
||||||
INVALID, //!< Failed decoding
|
INVALID, //!< Failed decoding
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,9 @@ FUZZ_TARGET(bech32)
|
||||||
std::vector<unsigned char> input;
|
std::vector<unsigned char> input;
|
||||||
ConvertBits<8, 5, true>([&](unsigned char c) { input.push_back(c); }, buffer.begin(), buffer.end());
|
ConvertBits<8, 5, true>([&](unsigned char c) { input.push_back(c); }, buffer.begin(), buffer.end());
|
||||||
|
|
||||||
if (input.size() + 3 + 6 <= 90) {
|
// Input data part + 3 characters for the HRP and separator (bc1) + the checksum characters
|
||||||
// If it's possible to encode input in Bech32(m) without exceeding the 90-character limit:
|
if (input.size() + 3 + bech32::CHECKSUM_SIZE <= bech32::CharLimit::BECH32) {
|
||||||
|
// If it's possible to encode input in Bech32(m) without exceeding the bech32-character limit:
|
||||||
for (auto encoding : {bech32::Encoding::BECH32, bech32::Encoding::BECH32M}) {
|
for (auto encoding : {bech32::Encoding::BECH32, bech32::Encoding::BECH32M}) {
|
||||||
const std::string encoded = bech32::Encode(encoding, "bc", input);
|
const std::string encoded = bech32::Encode(encoding, "bc", input);
|
||||||
assert(!encoded.empty());
|
assert(!encoded.empty());
|
||||||
|
|
Loading…
Add table
Reference in a new issue