diff --git a/src/netaddress.cpp b/src/netaddress.cpp index cb874e5e31..8adfe38dc9 100644 --- a/src/netaddress.cpp +++ b/src/netaddress.cpp @@ -4,10 +4,11 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include + #include +#include #include #include -#include #include #include @@ -341,9 +342,9 @@ enum Network CNetAddr::GetNetwork() const std::string CNetAddr::ToStringIP() const { if (IsTor()) - return EncodeBase32(m_addr.data(), m_addr.size()) + ".onion"; + return EncodeBase32(m_addr) + ".onion"; if (IsInternal()) - return EncodeBase32(m_addr.data(), m_addr.size()) + ".internal"; + return EncodeBase32(m_addr) + ".internal"; CService serv(*this, 0); struct sockaddr_storage sockaddr; socklen_t socklen = sizeof(sockaddr); 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 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 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 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 input); std::string EncodeBase32(const std::string& str); void SplitHostPort(std::string in, int& portOut, std::string& hostOut);