Skip to content

Commit c1a5d5c

Browse files
committed
Split out bech32 separator char to header
1 parent e8f72ae commit c1a5d5c

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/bech32.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ std::string Encode(Encoding encoding, const std::string& hrp, const data& values
364364
std::string ret;
365365
ret.reserve(hrp.size() + 1 + values.size() + CHECKSUM_SIZE);
366366
ret += hrp;
367-
ret += '1';
367+
ret += SEPARATOR;
368368
for (const uint8_t& i : values) ret += CHARSET[i];
369369
for (const uint8_t& i : CreateChecksum(encoding, hrp, values)) ret += CHARSET[i];
370370
return ret;
@@ -374,7 +374,7 @@ std::string Encode(Encoding encoding, const std::string& hrp, const data& values
374374
DecodeResult Decode(const std::string& str, CharLimit limit) {
375375
std::vector<int> errors;
376376
if (!CheckCharacters(str, errors)) return {};
377-
size_t pos = str.rfind('1');
377+
size_t pos = str.rfind(SEPARATOR);
378378
if (str.size() > limit) return {};
379379
if (pos == str.npos || pos == 0 || pos + CHECKSUM_SIZE >= str.size()) {
380380
return {};
@@ -413,7 +413,7 @@ std::pair<std::string, std::vector<int>> LocateErrors(const std::string& str, Ch
413413
return std::make_pair("Invalid character or mixed case", std::move(error_locations));
414414
}
415415

416-
size_t pos = str.rfind('1');
416+
size_t pos = str.rfind(SEPARATOR);
417417
if (pos == str.npos) {
418418
return std::make_pair("Missing separator", std::vector<int>{});
419419
}

src/bech32.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
namespace bech32
2222
{
2323

24-
/** The Bech32 and Bech32m checksum size */
25-
constexpr size_t CHECKSUM_SIZE = 6;
24+
static constexpr size_t CHECKSUM_SIZE = 6;
25+
static constexpr char SEPARATOR = '1';
2626

2727
enum class Encoding {
2828
INVALID, //!< Failed decoding

0 commit comments

Comments
 (0)