Skip to content

Commit e2aa1a5

Browse files
committed
util: make EncodeBase64 consume Spans
1 parent 2bc2071 commit e2aa1a5

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ UniValue combinepsbt(const JSONRPCRequest& request)
13001300

13011301
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
13021302
ssTx << merged_psbt;
1303-
return EncodeBase64((unsigned char*)ssTx.data(), ssTx.size());
1303+
return EncodeBase64(MakeUCharSpan(ssTx));
13041304
}
13051305

13061306
UniValue finalizepsbt(const JSONRPCRequest& request)
@@ -1435,7 +1435,7 @@ UniValue createpsbt(const JSONRPCRequest& request)
14351435
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
14361436
ssTx << psbtx;
14371437

1438-
return EncodeBase64((unsigned char*)ssTx.data(), ssTx.size());
1438+
return EncodeBase64(MakeUCharSpan(ssTx));
14391439
}
14401440

14411441
UniValue converttopsbt(const JSONRPCRequest& request)
@@ -1502,7 +1502,7 @@ UniValue converttopsbt(const JSONRPCRequest& request)
15021502
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
15031503
ssTx << psbtx;
15041504

1505-
return EncodeBase64((unsigned char*)ssTx.data(), ssTx.size());
1505+
return EncodeBase64(MakeUCharSpan(ssTx));
15061506
}
15071507

15081508
UniValue utxoupdatepsbt(const JSONRPCRequest& request)
@@ -1590,7 +1590,7 @@ UniValue utxoupdatepsbt(const JSONRPCRequest& request)
15901590

15911591
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
15921592
ssTx << psbtx;
1593-
return EncodeBase64((unsigned char*)ssTx.data(), ssTx.size());
1593+
return EncodeBase64(MakeUCharSpan(ssTx));
15941594
}
15951595

15961596
UniValue joinpsbts(const JSONRPCRequest& request)
@@ -1683,7 +1683,7 @@ UniValue joinpsbts(const JSONRPCRequest& request)
16831683

16841684
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
16851685
ssTx << shuffled_psbt;
1686-
return EncodeBase64((unsigned char*)ssTx.data(), ssTx.size());
1686+
return EncodeBase64(MakeUCharSpan(ssTx));
16871687
}
16881688

16891689
UniValue analyzepsbt(const JSONRPCRequest& request)

src/util/message.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ bool MessageSign(
6464
return false;
6565
}
6666

67-
signature = EncodeBase64(signature_bytes.data(), signature_bytes.size());
67+
signature = EncodeBase64(signature_bytes);
6868

6969
return true;
7070
}

src/util/strencodings.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,20 @@ void SplitHostPort(std::string in, int &portOut, std::string &hostOut) {
126126
hostOut = in;
127127
}
128128

129-
std::string EncodeBase64(const unsigned char* pch, size_t len)
129+
std::string EncodeBase64(Span<const unsigned char> input)
130130
{
131131
static const char *pbase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
132132

133133
std::string str;
134-
str.reserve(((len + 2) / 3) * 4);
135-
ConvertBits<8, 6, true>([&](int v) { str += pbase64[v]; }, pch, pch + len);
134+
str.reserve(((input.size() + 2) / 3) * 4);
135+
ConvertBits<8, 6, true>([&](int v) { str += pbase64[v]; }, input.begin(), input.end());
136136
while (str.size() % 4) str += '=';
137137
return str;
138138
}
139139

140140
std::string EncodeBase64(const std::string& str)
141141
{
142-
return EncodeBase64((const unsigned char*)str.data(), str.size());
142+
return EncodeBase64(MakeUCharSpan(str));
143143
}
144144

145145
std::vector<unsigned char> DecodeBase64(const char* p, bool* pf_invalid)

src/util/strencodings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ bool IsHex(const std::string& str);
4848
bool IsHexNumber(const std::string& str);
4949
std::vector<unsigned char> DecodeBase64(const char* p, bool* pf_invalid = nullptr);
5050
std::string DecodeBase64(const std::string& str, bool* pf_invalid = nullptr);
51-
std::string EncodeBase64(const unsigned char* pch, size_t len);
51+
std::string EncodeBase64(Span<const unsigned char> input);
5252
std::string EncodeBase64(const std::string& str);
5353
std::vector<unsigned char> DecodeBase32(const char* p, bool* pf_invalid = nullptr);
5454
std::string DecodeBase32(const std::string& str, bool* pf_invalid = nullptr);

0 commit comments

Comments
 (0)