17 namespace Azure {
namespace Core {
39 static std::string
Base64Encode(
const std::vector<uint8_t>& data);
47 static std::vector<uint8_t>
Base64Decode(
const std::string& text);
56 class Base64Url final {
59 static std::string Base64UrlEncode(
const std::vector<uint8_t>& data)
63 auto trail = base64.find(
'=');
64 if (trail != std::string::npos)
66 base64 = base64.substr(0, trail);
68 std::replace(base64.begin(), base64.end(),
'+',
'-');
69 std::replace(base64.begin(), base64.end(),
'/',
'_');
73 static std::vector<uint8_t> Base64UrlDecode(
const std::string& text)
75 std::string base64url(text);
77 std::replace(base64url.begin(), base64url.end(),
'-',
'+');
78 std::replace(base64url.begin(), base64url.end(),
'_',
'/');
79 switch (base64url.size() % 4)
84 base64url.append(
"==");
87 base64url.append(
"=");
90 throw std::invalid_argument(
"Unexpected Base64URL encoding in the HTTP response.");