aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2020-08-07 19:55:51 +0200
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2020-08-25 18:52:51 +0200
commit2bc207190e6f1818b04c9336f6e0d625b2a2a0ba (patch)
tree5fa9684143f5f2e0fef4ef8b53444dcb3c262e9e /src/util
parent8d6224fefe015c2022d00a79a4549464bd79cf2f (diff)
util: make EncodeBase32 consume Spans
Diffstat (limited to 'src/util')
-rw-r--r--src/util/strencodings.cpp8
-rw-r--r--src/util/strencodings.h2
2 files changed, 5 insertions, 5 deletions
diff --git a/src/util/strencodings.cpp b/src/util/strencodings.cpp
index 6d93029737..ec29efc586 100644
--- a/src/util/strencodings.cpp
+++ b/src/util/strencodings.cpp
@@ -201,20 +201,20 @@ std::string DecodeBase64(const std::string& str, bool* pf_invalid)
return std::string((const char*)vchRet.data(), vchRet.size());
}
-std::string EncodeBase32(const unsigned char* pch, size_t len)
+std::string EncodeBase32(Span<const unsigned char> input)
{
static const char *pbase32 = "abcdefghijklmnopqrstuvwxyz234567";
std::string str;
- str.reserve(((len + 4) / 5) * 8);
- ConvertBits<8, 5, true>([&](int v) { str += pbase32[v]; }, pch, pch + len);
+ str.reserve(((input.size() + 4) / 5) * 8);
+ ConvertBits<8, 5, true>([&](int v) { str += pbase32[v]; }, input.begin(), input.end());
while (str.size() % 8) str += '=';
return str;
}
std::string EncodeBase32(const std::string& str)
{
- return EncodeBase32((const unsigned char*)str.data(), str.size());
+ return EncodeBase32(MakeUCharSpan(str));
}
std::vector<unsigned char> DecodeBase32(const char* p, bool* pf_invalid)
diff --git a/src/util/strencodings.h b/src/util/strencodings.h
index 4c7a2694a9..1d0695a780 100644
--- a/src/util/strencodings.h
+++ b/src/util/strencodings.h
@@ -52,7 +52,7 @@ std::string EncodeBase64(const unsigned char* pch, size_t len);
std::string EncodeBase64(const std::string& str);
std::vector<unsigned char> DecodeBase32(const char* p, bool* pf_invalid = nullptr);
std::string DecodeBase32(const std::string& str, bool* pf_invalid = nullptr);
-std::string EncodeBase32(const unsigned char* pch, size_t len);
+std::string EncodeBase32(Span<const unsigned char> input);
std::string EncodeBase32(const std::string& str);
void SplitHostPort(std::string in, int& portOut, std::string& hostOut);