aboutsummaryrefslogtreecommitdiff
path: root/src/bech32.cpp
diff options
context:
space:
mode:
authormurrayn <github@nesbitt.ca>2018-04-04 03:24:25 -0700
committermurrayn <github@nesbitt.ca>2018-04-12 17:52:33 -0700
commit60f61f99529f54f85c847d61122c70c0358ebecc (patch)
treef48afc9cb38f55bb1f99331b3c7ecf0bd97733b8 /src/bech32.cpp
parentad960f5771dc251c8e1198dd8a82e18df4562171 (diff)
Tighten up bech32::Decode(); add tests.
Diffstat (limited to 'src/bech32.cpp')
-rw-r--r--src/bech32.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/bech32.cpp b/src/bech32.cpp
index 274782e467..c55f22b9b7 100644
--- a/src/bech32.cpp
+++ b/src/bech32.cpp
@@ -160,9 +160,9 @@ std::pair<std::string, data> Decode(const std::string& str) {
bool lower = false, upper = false;
for (size_t i = 0; i < str.size(); ++i) {
unsigned char c = str[i];
- if (c < 33 || c > 126) return {};
if (c >= 'a' && c <= 'z') lower = true;
- if (c >= 'A' && c <= 'Z') upper = true;
+ else if (c >= 'A' && c <= 'Z') upper = true;
+ else if (c < 33 || c > 126) return {};
}
if (lower && upper) return {};
size_t pos = str.rfind('1');
@@ -172,7 +172,8 @@ std::pair<std::string, data> Decode(const std::string& str) {
data values(str.size() - 1 - pos);
for (size_t i = 0; i < str.size() - 1 - pos; ++i) {
unsigned char c = str[i + pos + 1];
- int8_t rev = (c < 33 || c > 126) ? -1 : CHARSET_REV[c];
+ int8_t rev = CHARSET_REV[c];
+
if (rev == -1) {
return {};
}