Changeset View
Changeset View
Standalone View
Standalone View
src/util/strencodings.cpp
Show First 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | std::string EncodeBase64(const uint8_t *pch, size_t len) { | ||||
ConvertBits<8, 6, true>([&](int v) { str += pbase64[v]; }, pch, pch + len); | ConvertBits<8, 6, true>([&](int v) { str += pbase64[v]; }, pch, pch + len); | ||||
while (str.size() % 4) { | while (str.size() % 4) { | ||||
str += '='; | str += '='; | ||||
} | } | ||||
return str; | return str; | ||||
} | } | ||||
std::string EncodeBase64(const std::string &str) { | std::string EncodeBase64(const std::string &str) { | ||||
return EncodeBase64((const uint8_t *)str.c_str(), str.size()); | return EncodeBase64((const uint8_t *)str.data(), str.size()); | ||||
} | } | ||||
std::vector<uint8_t> DecodeBase64(const char *p, bool *pf_invalid) { | std::vector<uint8_t> DecodeBase64(const char *p, bool *pf_invalid) { | ||||
static const int decode64_table[256] = { | static const int decode64_table[256] = { | ||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
-1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, | -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, | ||||
58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, | 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | std::string EncodeBase32(const uint8_t *pch, size_t len) { | ||||
ConvertBits<8, 5, true>([&](int v) { str += pbase32[v]; }, pch, pch + len); | ConvertBits<8, 5, true>([&](int v) { str += pbase32[v]; }, pch, pch + len); | ||||
while (str.size() % 8) { | while (str.size() % 8) { | ||||
str += '='; | str += '='; | ||||
} | } | ||||
return str; | return str; | ||||
} | } | ||||
std::string EncodeBase32(const std::string &str) { | std::string EncodeBase32(const std::string &str) { | ||||
return EncodeBase32((const uint8_t *)str.c_str(), str.size()); | return EncodeBase32((const uint8_t *)str.data(), str.size()); | ||||
} | } | ||||
std::vector<uint8_t> DecodeBase32(const char *p, bool *pf_invalid) { | std::vector<uint8_t> DecodeBase32(const char *p, bool *pf_invalid) { | ||||
static const int decode32_table[256] = { | static const int decode32_table[256] = { | ||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, | ||||
30, 31, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, | 30, 31, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, | ||||
▲ Show 20 Lines • Show All 412 Lines • Show Last 20 Lines |