From c544ce64b3dca22dfe7ccbff38ce35a1920318cc Mon Sep 17 00:00:00 2001 From: David Burkett Date: Sat, 29 Jan 2022 11:37:59 -0500 Subject: [PATCH] MWEB: Allow extended length bech32 --- src/bech32.cpp | 4 ++-- src/bech32.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bech32.cpp b/src/bech32.cpp index 288b14e023..f58f39e2a2 100644 --- a/src/bech32.cpp +++ b/src/bech32.cpp @@ -165,7 +165,7 @@ std::string Encode(Encoding encoding, const std::string& hrp, const data& values } /** Decode a Bech32 or Bech32m string. */ -DecodeResult Decode(const std::string& str) { +DecodeResult Decode(const std::string& str, const bool ext_length) { bool lower = false, upper = false; for (size_t i = 0; i < str.size(); ++i) { unsigned char c = str[i]; @@ -175,7 +175,7 @@ DecodeResult Decode(const std::string& str) { } if (lower && upper) return {}; size_t pos = str.rfind('1'); - if (str.size() > 90 || pos == str.npos || pos == 0 || pos + 7 > str.size()) { + if ((str.size() > 90 && !ext_length) || pos == str.npos || pos == 0 || pos + 7 > str.size()) { return {}; } data values(str.size() - 1 - pos); diff --git a/src/bech32.h b/src/bech32.h index e9450ccc2b..669e54538c 100644 --- a/src/bech32.h +++ b/src/bech32.h @@ -42,7 +42,7 @@ struct DecodeResult }; /** Decode a Bech32 or Bech32m string. */ -DecodeResult Decode(const std::string& str); +DecodeResult Decode(const std::string& str, const bool ext_length = false); } // namespace bech32