Changeset View
Changeset View
Standalone View
Standalone View
src/utilstrencodings.cpp
Show First 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | if (in.size() > 0 && in[0] == '[' && in[in.size() - 1] == ']') { | ||||
hostOut = in; | hostOut = in; | ||||
} | } | ||||
} | } | ||||
std::string EncodeBase64(const uint8_t *pch, size_t len) { | std::string EncodeBase64(const uint8_t *pch, size_t len) { | ||||
static const char *pbase64 = | static const char *pbase64 = | ||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | ||||
std::string strRet = ""; | std::string strRet; | ||||
strRet.reserve((len + 2) / 3 * 4); | strRet.reserve((len + 2) / 3 * 4); | ||||
int mode = 0, left = 0; | int mode = 0, left = 0; | ||||
const uint8_t *pchEnd = pch + len; | const uint8_t *pchEnd = pch + len; | ||||
while (pch < pchEnd) { | while (pch < pchEnd) { | ||||
int enc = *(pch++); | int enc = *(pch++); | ||||
switch (mode) { | switch (mode) { | ||||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | |||||
std::string DecodeBase64(const std::string &str) { | std::string DecodeBase64(const std::string &str) { | ||||
std::vector<uint8_t> vchRet = DecodeBase64(str.c_str()); | std::vector<uint8_t> vchRet = DecodeBase64(str.c_str()); | ||||
return std::string((const char *)vchRet.data(), vchRet.size()); | return std::string((const char *)vchRet.data(), vchRet.size()); | ||||
} | } | ||||
std::string EncodeBase32(const uint8_t *pch, size_t len) { | std::string EncodeBase32(const uint8_t *pch, size_t len) { | ||||
static const char *pbase32 = "abcdefghijklmnopqrstuvwxyz234567"; | static const char *pbase32 = "abcdefghijklmnopqrstuvwxyz234567"; | ||||
std::string strRet = ""; | std::string strRet; | ||||
strRet.reserve((len + 4) / 5 * 8); | strRet.reserve((len + 4) / 5 * 8); | ||||
int mode = 0, left = 0; | int mode = 0, left = 0; | ||||
const uint8_t *pchEnd = pch + len; | const uint8_t *pchEnd = pch + len; | ||||
while (pch < pchEnd) { | while (pch < pchEnd) { | ||||
int enc = *(pch++); | int enc = *(pch++); | ||||
switch (mode) { | switch (mode) { | ||||
▲ Show 20 Lines • Show All 526 Lines • Show Last 20 Lines |