aboutsummaryrefslogtreecommitdiff
path: root/src/base58.cpp
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2020-08-10 02:52:37 +0200
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2020-08-12 16:25:50 +0200
commitf0fce0675d56b2226a993253731690ca864066c8 (patch)
tree25b8fb258913edec576cad0740f014f8fa643bef /src/base58.cpp
parentbd00d3b1f2036893419d1e8c514a8af2c4e4b1fb (diff)
util: make EncodeBase58 consume Spans
Diffstat (limited to 'src/base58.cpp')
-rw-r--r--src/base58.cpp19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/base58.cpp b/src/base58.cpp
index 9b2946e7a9..715e4e7891 100644
--- a/src/base58.cpp
+++ b/src/base58.cpp
@@ -84,21 +84,21 @@ bool DecodeBase58(const char* psz, std::vector<unsigned char>& vch, int max_ret_
return true;
}
-std::string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend)
+std::string EncodeBase58(Span<const unsigned char> input)
{
// Skip & count leading zeroes.
int zeroes = 0;
int length = 0;
- while (pbegin != pend && *pbegin == 0) {
- pbegin++;
+ while (input.size() > 0 && input[0] == 0) {
+ input = input.subspan(1);
zeroes++;
}
// Allocate enough space in big-endian base58 representation.
- int size = (pend - pbegin) * 138 / 100 + 1; // log(256) / log(58), rounded up.
+ int size = input.size() * 138 / 100 + 1; // log(256) / log(58), rounded up.
std::vector<unsigned char> b58(size);
// Process the bytes.
- while (pbegin != pend) {
- int carry = *pbegin;
+ while (input.size() > 0) {
+ int carry = input[0];
int i = 0;
// Apply "b58 = b58 * 256 + ch".
for (std::vector<unsigned char>::reverse_iterator it = b58.rbegin(); (carry != 0 || i < length) && (it != b58.rend()); it++, i++) {
@@ -109,7 +109,7 @@ std::string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend)
assert(carry == 0);
length = i;
- pbegin++;
+ input = input.subspan(1);
}
// Skip leading zeroes in base58 result.
std::vector<unsigned char>::iterator it = b58.begin() + (size - length);
@@ -124,11 +124,6 @@ std::string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend)
return str;
}
-std::string EncodeBase58(const std::vector<unsigned char>& vch)
-{
- return EncodeBase58(vch.data(), vch.data() + vch.size());
-}
-
bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet, int max_ret_len)
{
if (!ValidAsCString(str)) {