aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/jwt-cpp/base.h
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-05-05 17:50:58 +0300
committershadchin <shadchin@yandex-team.ru>2022-05-05 17:50:58 +0300
commitdea1e96c926a63a534cf579e7450479f29dc1b45 (patch)
treecbdc7638febcf17dc537331356ec2621570ffe4f /contrib/libs/jwt-cpp/base.h
parent570266d20cea70e21f7b00c6140a08902b1fb455 (diff)
downloadydb-dea1e96c926a63a534cf579e7450479f29dc1b45.tar.gz
Update contrib/libs/jwt-cpp to 0.4.0
ref:c22a6249506be3d6363f3ca316df6b0800de7e81
Diffstat (limited to 'contrib/libs/jwt-cpp/base.h')
-rw-r--r--contrib/libs/jwt-cpp/base.h68
1 files changed, 55 insertions, 13 deletions
diff --git a/contrib/libs/jwt-cpp/base.h b/contrib/libs/jwt-cpp/base.h
index dfca7fc08f9..375e0eb08f3 100644
--- a/contrib/libs/jwt-cpp/base.h
+++ b/contrib/libs/jwt-cpp/base.h
@@ -2,16 +2,26 @@
#include <string>
#include <array>
+#ifdef __has_cpp_attribute
+#if __has_cpp_attribute(fallthrough)
+#define JWT_FALLTHROUGH [[fallthrough]]
+#endif
+#endif
+
+#ifndef JWT_FALLTHROUGH
+#define JWT_FALLTHROUGH
+#endif
+
namespace jwt {
namespace alphabet {
struct base64 {
static const std::array<char, 64>& data() {
- static std::array<char, 64> data = {
- {'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', '+', '/'}};
- return data;
+ static std::array<char, 64> data = {
+ {'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', '+', '/'}};
+ return data;
};
static const std::string& fill() {
static std::string fill = "=";
@@ -20,12 +30,12 @@ namespace jwt {
};
struct base64url {
static const std::array<char, 64>& data() {
- static std::array<char, 64> data = {
- {'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', '-', '_'}};
- return data;
+ static std::array<char, 64> data = {
+ {'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', '-', '_'}};
+ return data;
};
static const std::string& fill() {
static std::string fill = "%3d";
@@ -44,6 +54,14 @@ namespace jwt {
static std::string decode(const std::string& base) {
return decode(base, T::data(), T::fill());
}
+ template<typename T>
+ static std::string pad(const std::string& base) {
+ return pad(base, T::fill());
+ }
+ template<typename T>
+ static std::string trim(const std::string& base) {
+ return trim(base, T::fill());
+ }
private:
static std::string encode(const std::string& bin, const std::array<char, 64>& alphabet, const std::string& fill) {
@@ -120,7 +138,7 @@ namespace jwt {
auto get_sextet = [&](size_t offset) {
for (size_t i = 0; i < alphabet.size(); i++) {
if (alphabet[i] == base[offset])
- return i;
+ return static_cast<uint32_t>(i);
}
throw std::runtime_error("Invalid input");
};
@@ -164,5 +182,29 @@ namespace jwt {
return res;
}
+
+ static std::string pad(const std::string& base, const std::string& fill) {
+ std::string padding;
+ switch (base.size() % 4) {
+ case 1:
+ padding += fill;
+ JWT_FALLTHROUGH;
+ case 2:
+ padding += fill;
+ JWT_FALLTHROUGH;
+ case 3:
+ padding += fill;
+ JWT_FALLTHROUGH;
+ default:
+ break;
+ }
+
+ return base + padding;
+ }
+
+ static std::string trim(const std::string& base, const std::string& fill) {
+ auto pos = base.find(fill);
+ return base.substr(0, pos);
+ }
};
}