|
|
|
@ -6,9 +6,10 @@ |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#include "Utilities.h" |
|
|
|
|
#include <fmt/format.h> |
|
|
|
|
#include <cstdint> |
|
|
|
|
#include <sstream> |
|
|
|
|
#include <vector> |
|
|
|
|
#include <fmt/format.h> |
|
|
|
|
|
|
|
|
|
std::pair<std::string,std::string> FormatCTCPLine(std::string line) |
|
|
|
|
{ |
|
|
|
@ -142,3 +143,53 @@ bool strEquals(const std::string& l, const std::string& r) |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::string toBase64(const std::string& input) |
|
|
|
|
{ |
|
|
|
|
static const char b64map[] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P', |
|
|
|
|
'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f', |
|
|
|
|
'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', |
|
|
|
|
'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/' }; |
|
|
|
|
|
|
|
|
|
std::string ret; |
|
|
|
|
|
|
|
|
|
for (auto i = 0; i < input.size(); i += 3) { |
|
|
|
|
std::int_fast32_t seq{}; // Need only 24 bits of this
|
|
|
|
|
std::int_fast32_t a{}, b{}, c{}, d{}; |
|
|
|
|
bool cBlank{}, dBlank{}; |
|
|
|
|
|
|
|
|
|
seq |= input[i]; |
|
|
|
|
seq <<= 8; |
|
|
|
|
|
|
|
|
|
if (i + 1 < input.size()) |
|
|
|
|
seq |= input[i + 1]; |
|
|
|
|
else |
|
|
|
|
cBlank = true; |
|
|
|
|
seq <<= 8; |
|
|
|
|
|
|
|
|
|
if (i + 2 < input.size()) |
|
|
|
|
seq |= input[i + 2]; |
|
|
|
|
else |
|
|
|
|
dBlank = true; |
|
|
|
|
|
|
|
|
|
a = (seq & 0xFC0000) >> 18; |
|
|
|
|
b = (seq & 0x3F000) >> 12; |
|
|
|
|
c = (seq & 0xFC0) >> 6; |
|
|
|
|
d = seq & 0x3F; |
|
|
|
|
|
|
|
|
|
ret.push_back(b64map[a]); |
|
|
|
|
ret.push_back(b64map[b]); |
|
|
|
|
|
|
|
|
|
if (cBlank) |
|
|
|
|
ret.push_back('='); |
|
|
|
|
else |
|
|
|
|
ret.push_back(b64map[c]); |
|
|
|
|
|
|
|
|
|
if (dBlank) |
|
|
|
|
ret.push_back('='); |
|
|
|
|
else |
|
|
|
|
ret.push_back(b64map[d]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|