Split out bech32 separator char to header

This commit is contained in:
Lőrinc committed 2024-10-19 18:49:53 +02:00
1 parent e8f72aefd2
commit c1a5d5c100
2 files changed
+5 -5

No files matched your search

+3 -3
View File
@@ -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>{});
}