Skip to content

Commit 162ffef

Browse files
committed
Add pf_invalid arg to std::string DecodeBase{32,64}
Add support for the optional "pf_invalid" out parameter (which allows the caller to detect decoding failures) to the std::string versions of DecodeBase32 and DecodeBase64. The char* versions already have this feature. Also, rename all uses of pfInvalid to pf_invalid to match style guidelines.
1 parent 1bc149d commit 162ffef

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/util/strencodings.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ std::string EncodeBase64(const std::string& str)
141141
return EncodeBase64((const unsigned char*)str.c_str(), str.size());
142142
}
143143

144-
std::vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid)
144+
std::vector<unsigned char> DecodeBase64(const char* p, bool* pf_invalid)
145145
{
146146
static const int decode64_table[256] =
147147
{
@@ -183,14 +183,14 @@ std::vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid)
183183
++p;
184184
}
185185
valid = valid && (p - e) % 4 == 0 && p - q < 4;
186-
if (pfInvalid) *pfInvalid = !valid;
186+
if (pf_invalid) *pf_invalid = !valid;
187187

188188
return ret;
189189
}
190190

191-
std::string DecodeBase64(const std::string& str)
191+
std::string DecodeBase64(const std::string& str, bool* pf_invalid)
192192
{
193-
std::vector<unsigned char> vchRet = DecodeBase64(str.c_str());
193+
std::vector<unsigned char> vchRet = DecodeBase64(str.c_str(), pf_invalid);
194194
return std::string((const char*)vchRet.data(), vchRet.size());
195195
}
196196

@@ -210,7 +210,7 @@ std::string EncodeBase32(const std::string& str)
210210
return EncodeBase32((const unsigned char*)str.c_str(), str.size());
211211
}
212212

213-
std::vector<unsigned char> DecodeBase32(const char* p, bool* pfInvalid)
213+
std::vector<unsigned char> DecodeBase32(const char* p, bool* pf_invalid)
214214
{
215215
static const int decode32_table[256] =
216216
{
@@ -252,14 +252,14 @@ std::vector<unsigned char> DecodeBase32(const char* p, bool* pfInvalid)
252252
++p;
253253
}
254254
valid = valid && (p - e) % 8 == 0 && p - q < 8;
255-
if (pfInvalid) *pfInvalid = !valid;
255+
if (pf_invalid) *pf_invalid = !valid;
256256

257257
return ret;
258258
}
259259

260-
std::string DecodeBase32(const std::string& str)
260+
std::string DecodeBase32(const std::string& str, bool* pf_invalid)
261261
{
262-
std::vector<unsigned char> vchRet = DecodeBase32(str.c_str());
262+
std::vector<unsigned char> vchRet = DecodeBase32(str.c_str(), pf_invalid);
263263
return std::string((const char*)vchRet.data(), vchRet.size());
264264
}
265265

src/util/strencodings.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ bool IsHex(const std::string& str);
4444
* Return true if the string is a hex number, optionally prefixed with "0x"
4545
*/
4646
bool IsHexNumber(const std::string& str);
47-
std::vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid = nullptr);
48-
std::string DecodeBase64(const std::string& str);
47+
std::vector<unsigned char> DecodeBase64(const char* p, bool* pf_invalid = nullptr);
48+
std::string DecodeBase64(const std::string& str, bool* pf_invalid = nullptr);
4949
std::string EncodeBase64(const unsigned char* pch, size_t len);
5050
std::string EncodeBase64(const std::string& str);
51-
std::vector<unsigned char> DecodeBase32(const char* p, bool* pfInvalid = nullptr);
52-
std::string DecodeBase32(const std::string& str);
51+
std::vector<unsigned char> DecodeBase32(const char* p, bool* pf_invalid = nullptr);
52+
std::string DecodeBase32(const std::string& str, bool* pf_invalid = nullptr);
5353
std::string EncodeBase32(const unsigned char* pch, size_t len);
5454
std::string EncodeBase32(const std::string& str);
5555

0 commit comments

Comments
 (0)