diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index abc8168c5..d6988ee3a 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -1300,7 +1300,7 @@ UniValue combinepsbt(const JSONRPCRequest& request) CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); ssTx << merged_psbt; - return EncodeBase64((unsigned char*)ssTx.data(), ssTx.size()); + return EncodeBase64(MakeUCharSpan(ssTx)); } UniValue finalizepsbt(const JSONRPCRequest& request) @@ -1435,7 +1435,7 @@ UniValue createpsbt(const JSONRPCRequest& request) CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); ssTx << psbtx; - return EncodeBase64((unsigned char*)ssTx.data(), ssTx.size()); + return EncodeBase64(MakeUCharSpan(ssTx)); } UniValue converttopsbt(const JSONRPCRequest& request) @@ -1502,7 +1502,7 @@ UniValue converttopsbt(const JSONRPCRequest& request) CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); ssTx << psbtx; - return EncodeBase64((unsigned char*)ssTx.data(), ssTx.size()); + return EncodeBase64(MakeUCharSpan(ssTx)); } UniValue utxoupdatepsbt(const JSONRPCRequest& request) @@ -1590,7 +1590,7 @@ UniValue utxoupdatepsbt(const JSONRPCRequest& request) CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); ssTx << psbtx; - return EncodeBase64((unsigned char*)ssTx.data(), ssTx.size()); + return EncodeBase64(MakeUCharSpan(ssTx)); } UniValue joinpsbts(const JSONRPCRequest& request) @@ -1683,7 +1683,7 @@ UniValue joinpsbts(const JSONRPCRequest& request) CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); ssTx << shuffled_psbt; - return EncodeBase64((unsigned char*)ssTx.data(), ssTx.size()); + return EncodeBase64(MakeUCharSpan(ssTx)); } UniValue analyzepsbt(const JSONRPCRequest& request) diff --git a/src/util/message.cpp b/src/util/message.cpp index 1e7128d22..e1d5cff48 100644 --- a/src/util/message.cpp +++ b/src/util/message.cpp @@ -64,7 +64,7 @@ bool MessageSign( return false; } - signature = EncodeBase64(signature_bytes.data(), signature_bytes.size()); + signature = EncodeBase64(signature_bytes); return true; } diff --git a/src/util/strencodings.cpp b/src/util/strencodings.cpp index ec29efc58..079a4529a 100644 --- a/src/util/strencodings.cpp +++ b/src/util/strencodings.cpp @@ -126,20 +126,20 @@ void SplitHostPort(std::string in, int &portOut, std::string &hostOut) { hostOut = in; } -std::string EncodeBase64(const unsigned char* pch, size_t len) +std::string EncodeBase64(Span input) { static const char *pbase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; std::string str; - str.reserve(((len + 2) / 3) * 4); - ConvertBits<8, 6, true>([&](int v) { str += pbase64[v]; }, pch, pch + len); + str.reserve(((input.size() + 2) / 3) * 4); + ConvertBits<8, 6, true>([&](int v) { str += pbase64[v]; }, input.begin(), input.end()); while (str.size() % 4) str += '='; return str; } std::string EncodeBase64(const std::string& str) { - return EncodeBase64((const unsigned char*)str.data(), str.size()); + return EncodeBase64(MakeUCharSpan(str)); } std::vector DecodeBase64(const char* p, bool* pf_invalid) diff --git a/src/util/strencodings.h b/src/util/strencodings.h index 1d0695a78..151921414 100644 --- a/src/util/strencodings.h +++ b/src/util/strencodings.h @@ -48,7 +48,7 @@ bool IsHex(const std::string& str); bool IsHexNumber(const std::string& str); std::vector DecodeBase64(const char* p, bool* pf_invalid = nullptr); std::string DecodeBase64(const std::string& str, bool* pf_invalid = nullptr); -std::string EncodeBase64(const unsigned char* pch, size_t len); +std::string EncodeBase64(Span input); 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);