mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-21 12:22:50 -05:00
Split out bech32 separator char to header
This commit is contained in:
parent
e8f72aefd2
commit
c1a5d5c100
2 changed files with 5 additions and 5 deletions
|
@ -364,7 +364,7 @@ std::string Encode(Encoding encoding, const std::string& hrp, const data& values
|
|||
std::string ret;
|
||||
ret.reserve(hrp.size() + 1 + values.size() + CHECKSUM_SIZE);
|
||||
ret += hrp;
|
||||
ret += '1';
|
||||
ret += SEPARATOR;
|
||||
for (const uint8_t& i : values) ret += CHARSET[i];
|
||||
for (const uint8_t& i : CreateChecksum(encoding, hrp, values)) ret += CHARSET[i];
|
||||
return ret;
|
||||
|
@ -374,7 +374,7 @@ std::string Encode(Encoding encoding, const std::string& hrp, const data& values
|
|||
DecodeResult Decode(const std::string& str, CharLimit limit) {
|
||||
std::vector<int> errors;
|
||||
if (!CheckCharacters(str, errors)) return {};
|
||||
size_t pos = str.rfind('1');
|
||||
size_t pos = str.rfind(SEPARATOR);
|
||||
if (str.size() > limit) return {};
|
||||
if (pos == str.npos || pos == 0 || pos + CHECKSUM_SIZE >= str.size()) {
|
||||
return {};
|
||||
|
@ -413,7 +413,7 @@ std::pair<std::string, std::vector<int>> LocateErrors(const std::string& str, Ch
|
|||
return std::make_pair("Invalid character or mixed case", std::move(error_locations));
|
||||
}
|
||||
|
||||
size_t pos = str.rfind('1');
|
||||
size_t pos = str.rfind(SEPARATOR);
|
||||
if (pos == str.npos) {
|
||||
return std::make_pair("Missing separator", std::vector<int>{});
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
namespace bech32
|
||||
{
|
||||
|
||||
/** The Bech32 and Bech32m checksum size */
|
||||
constexpr size_t CHECKSUM_SIZE = 6;
|
||||
static constexpr size_t CHECKSUM_SIZE = 6;
|
||||
static constexpr char SEPARATOR = '1';
|
||||
|
||||
enum class Encoding {
|
||||
INVALID, //!< Failed decoding
|
||||
|
|
Loading…
Add table
Reference in a new issue