dep/jwt-cpp: Update to version 0.5
Fixes some compile warnings. Unit tests pass with this version as well.
This commit is contained in:
parent
33dbcc449a
commit
37817f6ba4
|
@ -1,30 +0,0 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include "include/jwt-cpp/base.h"
|
||||
|
||||
TEST(BaseTest, Base64Decode) {
|
||||
ASSERT_EQ("1", jwt::base::decode<jwt::alphabet::base64>("MQ=="));
|
||||
ASSERT_EQ("12", jwt::base::decode<jwt::alphabet::base64>("MTI="));
|
||||
ASSERT_EQ("123", jwt::base::decode<jwt::alphabet::base64>("MTIz"));
|
||||
ASSERT_EQ("1234", jwt::base::decode<jwt::alphabet::base64>("MTIzNA=="));
|
||||
}
|
||||
|
||||
TEST(BaseTest, Base64DecodeURL) {
|
||||
ASSERT_EQ("1", jwt::base::decode<jwt::alphabet::base64url>("MQ%3d%3d"));
|
||||
ASSERT_EQ("12", jwt::base::decode<jwt::alphabet::base64url>("MTI%3d"));
|
||||
ASSERT_EQ("123", jwt::base::decode<jwt::alphabet::base64url>("MTIz"));
|
||||
ASSERT_EQ("1234", jwt::base::decode<jwt::alphabet::base64url>("MTIzNA%3d%3d"));
|
||||
}
|
||||
|
||||
TEST(BaseTest, Base64Encode) {
|
||||
ASSERT_EQ("MQ==", jwt::base::encode<jwt::alphabet::base64>("1"));
|
||||
ASSERT_EQ("MTI=", jwt::base::encode<jwt::alphabet::base64>("12"));
|
||||
ASSERT_EQ("MTIz", jwt::base::encode<jwt::alphabet::base64>("123"));
|
||||
ASSERT_EQ("MTIzNA==", jwt::base::encode<jwt::alphabet::base64>("1234"));
|
||||
}
|
||||
|
||||
TEST(BaseTest, Base64EncodeURL) {
|
||||
ASSERT_EQ("MQ%3d%3d", jwt::base::encode<jwt::alphabet::base64url>("1"));
|
||||
ASSERT_EQ("MTI%3d", jwt::base::encode<jwt::alphabet::base64url>("12"));
|
||||
ASSERT_EQ("MTIz", jwt::base::encode<jwt::alphabet::base64url>("123"));
|
||||
ASSERT_EQ("MTIzNA%3d%3d", jwt::base::encode<jwt::alphabet::base64url>("1234"));
|
||||
}
|
|
@ -3,4 +3,4 @@ add_library(jwt-cpp::jwt-cpp ALIAS jwt-cpp)
|
|||
|
||||
target_include_directories(jwt-cpp
|
||||
INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/jwt-cpp)
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include "include/jwt-cpp/jwt.h"
|
||||
|
||||
TEST(ClaimTest, AudienceAsString) {
|
||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0.WZnM3SIiSRHsbO3O7Z2bmIzTJ4EC32HRBKfLznHhrh4";
|
||||
auto decoded = jwt::decode(token);
|
||||
|
||||
ASSERT_TRUE(decoded.has_algorithm());
|
||||
ASSERT_TRUE(decoded.has_type());
|
||||
ASSERT_FALSE(decoded.has_content_type());
|
||||
ASSERT_FALSE(decoded.has_key_id());
|
||||
ASSERT_FALSE(decoded.has_issuer());
|
||||
ASSERT_FALSE(decoded.has_subject());
|
||||
ASSERT_TRUE(decoded.has_audience());
|
||||
ASSERT_FALSE(decoded.has_expires_at());
|
||||
ASSERT_FALSE(decoded.has_not_before());
|
||||
ASSERT_FALSE(decoded.has_issued_at());
|
||||
ASSERT_FALSE(decoded.has_id());
|
||||
|
||||
ASSERT_EQ("HS256", decoded.get_algorithm());
|
||||
ASSERT_EQ("JWT", decoded.get_type());
|
||||
auto aud = decoded.get_audience();
|
||||
ASSERT_EQ(1, aud.size());
|
||||
ASSERT_EQ("test", *aud.begin());
|
||||
}
|
||||
|
||||
TEST(ClaimTest, SetAudienceAsString) {
|
||||
auto token = jwt::create()
|
||||
.set_type("JWT")
|
||||
.set_audience("test")
|
||||
.sign(jwt::algorithm::hs256("test"));
|
||||
ASSERT_EQ("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0.ny5Fa0vzAg7tNL95KWg_ecBNd3XP3tdAzq0SFA6diY4", token);
|
||||
}
|
|
@ -38,7 +38,7 @@ PROJECT_NAME = "JWT-C++"
|
|||
# could be handy for archiving the generated documentation or if some version
|
||||
# control system is used.
|
||||
|
||||
PROJECT_NUMBER =
|
||||
PROJECT_NUMBER = 0.5.0
|
||||
|
||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||
# for a project that appears at the top of each page and should give viewer a
|
||||
|
@ -889,7 +889,7 @@ EXCLUDE_SYMLINKS = NO
|
|||
# Note that the wildcards are matched against the file with absolute path, so to
|
||||
# exclude all test directories for example use the pattern */test/*
|
||||
|
||||
EXCLUDE_PATTERNS =
|
||||
EXCLUDE_PATTERNS = *nlohmann*, *picojson*
|
||||
|
||||
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
|
||||
# (namespaces, classes, functions, etc.) that should be excluded from the
|
||||
|
@ -900,13 +900,13 @@ EXCLUDE_PATTERNS =
|
|||
# Note that the wildcards are matched against the file with absolute path, so to
|
||||
# exclude all test directories use the pattern */test/*
|
||||
|
||||
EXCLUDE_SYMBOLS =
|
||||
EXCLUDE_SYMBOLS = jwt::details
|
||||
|
||||
# The EXAMPLE_PATH tag can be used to specify one or more files or directories
|
||||
# that contain example code fragments that are included (see the \include
|
||||
# command).
|
||||
|
||||
EXAMPLE_PATH =
|
||||
EXAMPLE_PATH = example
|
||||
|
||||
# If the value of the EXAMPLE_PATH tag contains directories, you can use the
|
||||
# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and
|
||||
|
@ -1666,7 +1666,7 @@ EXTRA_SEARCH_MAPPINGS =
|
|||
# If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output.
|
||||
# The default value is: YES.
|
||||
|
||||
GENERATE_LATEX = YES
|
||||
GENERATE_LATEX = NO
|
||||
|
||||
# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a
|
||||
# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include "include/jwt-cpp/jwt.h"
|
||||
|
||||
namespace {
|
||||
extern std::string google_cert;
|
||||
extern std::string google_cert_key;
|
||||
}
|
||||
|
||||
TEST(HelperTest, Cert2Pubkey) {
|
||||
auto key = jwt::helper::extract_pubkey_from_cert(google_cert);
|
||||
ASSERT_EQ(google_cert_key, key);
|
||||
}
|
||||
|
||||
namespace {
|
||||
std::string google_cert = R"(-----BEGIN CERTIFICATE-----
|
||||
MIIF8DCCBVmgAwIBAgIKYFOB9QABAACIvTANBgkqhkiG9w0BAQUFADBGMQswCQYD
|
||||
VQQGEwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzEiMCAGA1UEAxMZR29vZ2xlIElu
|
||||
dGVybmV0IEF1dGhvcml0eTAeFw0xMzA1MjIxNTQ5MDRaFw0xMzEwMzEyMzU5NTla
|
||||
MGYxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1N
|
||||
b3VudGFpbiBWaWV3MRMwEQYDVQQKEwpHb29nbGUgSW5jMRUwEwYDVQQDFAwqLmdv
|
||||
b2dsZS5jb20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARmSpIUbCqhUBq1UwnR
|
||||
Ai7/TNSk6W8JmasR+I0r/NLDYv5yApbAz8HXXN8hDdurMRP6Jy1Q0UIKmyls8HPH
|
||||
exoCo4IECjCCBAYwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMAsGA1Ud
|
||||
DwQEAwIHgDAdBgNVHQ4EFgQUU3jT0NVNRgU5ZinRHGrlyoGEnoYwHwYDVR0jBBgw
|
||||
FoAUv8Aw6/VDET5nup6R+/xq2uNrEiQwWwYDVR0fBFQwUjBQoE6gTIZKaHR0cDov
|
||||
L3d3dy5nc3RhdGljLmNvbS9Hb29nbGVJbnRlcm5ldEF1dGhvcml0eS9Hb29nbGVJ
|
||||
bnRlcm5ldEF1dGhvcml0eS5jcmwwZgYIKwYBBQUHAQEEWjBYMFYGCCsGAQUFBzAC
|
||||
hkpodHRwOi8vd3d3LmdzdGF0aWMuY29tL0dvb2dsZUludGVybmV0QXV0aG9yaXR5
|
||||
L0dvb2dsZUludGVybmV0QXV0aG9yaXR5LmNydDAMBgNVHRMBAf8EAjAAMIICwwYD
|
||||
VR0RBIICujCCAraCDCouZ29vZ2xlLmNvbYINKi5hbmRyb2lkLmNvbYIWKi5hcHBl
|
||||
bmdpbmUuZ29vZ2xlLmNvbYISKi5jbG91ZC5nb29nbGUuY29tghYqLmdvb2dsZS1h
|
||||
bmFseXRpY3MuY29tggsqLmdvb2dsZS5jYYILKi5nb29nbGUuY2yCDiouZ29vZ2xl
|
||||
LmNvLmlugg4qLmdvb2dsZS5jby5qcIIOKi5nb29nbGUuY28udWuCDyouZ29vZ2xl
|
||||
LmNvbS5hcoIPKi5nb29nbGUuY29tLmF1gg8qLmdvb2dsZS5jb20uYnKCDyouZ29v
|
||||
Z2xlLmNvbS5jb4IPKi5nb29nbGUuY29tLm14gg8qLmdvb2dsZS5jb20udHKCDyou
|
||||
Z29vZ2xlLmNvbS52boILKi5nb29nbGUuZGWCCyouZ29vZ2xlLmVzggsqLmdvb2ds
|
||||
ZS5mcoILKi5nb29nbGUuaHWCCyouZ29vZ2xlLml0ggsqLmdvb2dsZS5ubIILKi5n
|
||||
b29nbGUucGyCCyouZ29vZ2xlLnB0gg8qLmdvb2dsZWFwaXMuY26CFCouZ29vZ2xl
|
||||
Y29tbWVyY2UuY29tgg0qLmdzdGF0aWMuY29tggwqLnVyY2hpbi5jb22CECoudXJs
|
||||
Lmdvb2dsZS5jb22CFioueW91dHViZS1ub2Nvb2tpZS5jb22CDSoueW91dHViZS5j
|
||||
b22CFioueW91dHViZWVkdWNhdGlvbi5jb22CCyoueXRpbWcuY29tggthbmRyb2lk
|
||||
LmNvbYIEZy5jb4IGZ29vLmdsghRnb29nbGUtYW5hbHl0aWNzLmNvbYIKZ29vZ2xl
|
||||
LmNvbYISZ29vZ2xlY29tbWVyY2UuY29tggp1cmNoaW4uY29tggh5b3V0dS5iZYIL
|
||||
eW91dHViZS5jb22CFHlvdXR1YmVlZHVjYXRpb24uY29tMA0GCSqGSIb3DQEBBQUA
|
||||
A4GBAAMn0K3j3yhC+X+uyh6eABa2Eq7xiY5/mUB886Ir19vxluSMNKD6n/iY8vHj
|
||||
trn0BhuW8/vmJyudFkIcEDUYE4ivQMlsfIL7SOGw6OevVLmm02aiRHWj5T20Ds+S
|
||||
OpueYUG3NBcHP/5IzhUYIQJbGzlQaUaZBMaQeC8ZslMNLWI2
|
||||
-----END CERTIFICATE-----)";
|
||||
|
||||
std::string google_cert_key = R"(-----BEGIN PUBLIC KEY-----
|
||||
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEZkqSFGwqoVAatVMJ0QIu/0zUpOlv
|
||||
CZmrEfiNK/zSw2L+cgKWwM/B11zfIQ3bqzET+ictUNFCCpspbPBzx3saAg==
|
||||
-----END PUBLIC KEY-----
|
||||
)";
|
||||
}
|
|
@ -1,98 +1,208 @@
|
|||
# jwt-cpp
|
||||
# ![logo](https://raw.githubusercontent.com/Thalhammer/jwt-cpp/master/.github/logo.svg)
|
||||
|
||||
[![License Badge](https://img.shields.io/github/license/Thalhammer/jwt-cpp)](https://github.com/Thalhammer/jwt-cpp/blob/master/LICENSE)
|
||||
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/5f7055e294744901991fd0a1620b231d)](https://app.codacy.com/app/Thalhammer/jwt-cpp?utm_source=github.com&utm_medium=referral&utm_content=Thalhammer/jwt-cpp&utm_campaign=Badge_Grade_Settings)
|
||||
[![Linux Badge][Linux]][Cross-Platform]
|
||||
[![MacOS Badge][MacOS]][Cross-Platform]
|
||||
[![Windows Badge][Windows]][Cross-Platform]
|
||||
[![Coverage Status](https://coveralls.io/repos/github/Thalhammer/jwt-cpp/badge.svg?branch=master)](https://coveralls.io/github/Thalhammer/jwt-cpp?branch=master)
|
||||
[![Documentation Badge](https://img.shields.io/badge/Documentation-master-blue)](https://thalhammer.github.io/jwt-cpp/)
|
||||
[![GitHub release (latest SemVer including pre-releases)](https://img.shields.io/github/v/release/Thalhammer/jwt-cpp?include_prereleases)](https://github.com/Thalhammer/jwt-cpp/releases)
|
||||
[![Stars Badge](https://img.shields.io/github/stars/Thalhammer/jwt-cpp)](https://github.com/Thalhammer/jwt-cpp/stargazers)
|
||||
|
||||
A header only library for creating and validating json web tokens in c++.
|
||||
[Linux]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/cross-platform/ubuntu-latest/shields.json
|
||||
[MacOS]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/cross-platform/macos-latest/shields.json
|
||||
[Windows]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/cross-platform/windows-latest/shields.json
|
||||
[Cross-Platform]: https://github.com/Thalhammer/jwt-cpp/actions?query=workflow%3A%22Cross-Platform+CI%22
|
||||
|
||||
A header only library for creating and validating [JSON Web Tokens](https://tools.ietf.org/html/rfc7519) in C++11. For a great introduction, [read this](https://jwt.io/introduction/).
|
||||
|
||||
## Signature algorithms
|
||||
As of version 0.2.0 jwt-cpp supports all algorithms defined by the spec. The modular design of jwt-cpp allows one to add additional algorithms without any problems. If you need any feel free to open a pull request.
|
||||
For the sake of completeness, here is a list of all supported algorithms:
|
||||
* HS256
|
||||
* HS384
|
||||
* HS512
|
||||
* RS256
|
||||
* RS384
|
||||
* RS512
|
||||
* ES256
|
||||
* ES384
|
||||
* ES512
|
||||
* PS256
|
||||
* PS384
|
||||
* PS512
|
||||
|
||||
## Examples
|
||||
Simple example of decoding a token and printing all claims:
|
||||
```c++
|
||||
jwt-cpp supports all the algorithms defined by the specifications. The modular design allows to easily add additional algorithms without any problems. If you need any feel free to create a pull request or [open an issue](https://github.com/Thalhammer/jwt-cpp/issues/new).
|
||||
|
||||
For completeness, here is a list of all supported algorithms:
|
||||
|
||||
| HMSC | RSA | ECDSA | PSS | EdDSA |
|
||||
| ----- | ----- | ----- | ----- | ------- |
|
||||
| HS256 | RS256 | ES256 | PS256 | Ed25519 |
|
||||
| HS384 | RS384 | ES384 | PS384 | Ed448 |
|
||||
| HS512 | RS512 | ES512 | PS512 | |
|
||||
|
||||
## SSL Compatibility
|
||||
|
||||
In the name of flexibility and extensibility, jwt-cpp supports both [OpenSSL](https://github.com/openssl/openssl) and [LibreSSL](https://github.com/libressl-portable/portable). These are the version which are, or have been, tested:
|
||||
|
||||
| OpenSSL | LibreSSL |
|
||||
| -------------- | --------------- |
|
||||
| [1.0.2][1.0.2] | ![3.1.5][3.1] |
|
||||
| 1.1.0 | ![3.2.3][3.2] |
|
||||
| [1.1.1][1.1.1] | ![3.3.1][3.3] |
|
||||
|
||||
[1.0.2]: https://travis-ci.com/github/Thalhammer/jwt-cpp
|
||||
[1.1.1]: https://github.com/Thalhammer/jwt-cpp/actions?query=workflow%3A%22Coverage+CI%22
|
||||
[3.1]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/libressl/3.1.5/shields.json
|
||||
[3.2]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/libressl/3.2.3/shields.json
|
||||
[3.3]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/libressl/3.3.1/shields.json
|
||||
|
||||
## Overview
|
||||
|
||||
There is no hard dependency on a JSON library. Instead, there's a generic `jwt::basic_claim` which is templated around type traits, which described the semantic [JSON types](https://json-schema.org/understanding-json-schema/reference/type.html) for a value, object, array, string, number, integer and boolean, as well as methods to translate between them.
|
||||
|
||||
```cpp
|
||||
jwt::basic_claim<my_favorite_json_library_traits> claim(json::object({{"json", true},{"example", 0}}));
|
||||
```
|
||||
|
||||
This allows for complete freedom when picking which libraries you want to use. For more information, [see below](#providing-your-own-json-traits-your-traits).
|
||||
|
||||
In order to maintain compatibility, [picojson](https://github.com/kazuho/picojson) is still used to provide a specialized `jwt::claim` along with all helpers. Defining `JWT_DISABLE_PICOJSON` will remove this optional dependency.
|
||||
|
||||
As for the base64 requirements of JWTs, this libary provides `base.h` with all the required implentation; However base64 implementations are very common, with varying degrees of performance. When providing your own base64 implementation, you can define `JWT_DISABLE_BASE64` to remove the jwt-cpp implementation.
|
||||
|
||||
### Getting Started
|
||||
|
||||
Simple example of decoding a token and printing all [claims](https://tools.ietf.org/html/rfc7519#section-4) ([try it out](https://github.com/Thalhammer/jwt-cpp/tree/master/example/print-claims.cpp)):
|
||||
|
||||
```cpp
|
||||
#include <jwt-cpp/jwt.h>
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, const char** argv) {
|
||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||
auto decoded = jwt::decode(token);
|
||||
int main() {
|
||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||
auto decoded = jwt::decode(token);
|
||||
|
||||
for(auto& e : decoded.get_payload_claims())
|
||||
std::cout << e.first << " = " << e.second.to_json() << std::endl;
|
||||
for(auto& e : decoded.get_payload_claims())
|
||||
std::cout << e.first << " = " << e.second << std::endl;
|
||||
}
|
||||
```
|
||||
|
||||
In order to verify a token you first build a verifier and use it to verify a decoded token.
|
||||
```c++
|
||||
|
||||
```cpp
|
||||
auto verifier = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::hs256{ "secret" })
|
||||
.with_issuer("auth0");
|
||||
.allow_algorithm(jwt::algorithm::hs256{ "secret" })
|
||||
.with_issuer("auth0");
|
||||
|
||||
verifier.verify(decoded_token);
|
||||
```
|
||||
|
||||
The created verifier is stateless so you can reuse it for different tokens.
|
||||
|
||||
Creating a token (and signing) is equally easy.
|
||||
```c++
|
||||
Creating a token (and signing) is equally as easy.
|
||||
|
||||
```cpp
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.set_payload_claim("sample", std::string("test"))
|
||||
.sign(jwt::algorithm::hs256{"secret"});
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.set_payload_claim("sample", jwt::claim(std::string("test")))
|
||||
.sign(jwt::algorithm::hs256{"secret"});
|
||||
```
|
||||
|
||||
Here is a simple example of creating a token that will expire in 2 hours:
|
||||
Here is a simple example of creating a token that will expire in one hour:
|
||||
|
||||
```c++
|
||||
```cpp
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_issued_at(std::chrono::system_clock::now())
|
||||
.set_expires_at(std::chrono::system_clock::now() + std::chrono::seconds{3600})
|
||||
.sign(jwt::algorithm::hs256{"secret"});
|
||||
```
|
||||
|
||||
// Note to @Thalhammer: please replace with a better example if this is not a good way
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_issued_at(jwt::date(std::chrono::system_clock::now()))
|
||||
.set_expires_at(jwt::date(std::chrono::system_clock::now()+ std::chrono::seconds{3600}))
|
||||
.sign(jwt::algorithm::hs256{"secret"}
|
||||
> To see more examples working with RSA public and private keys, visit our [examples](https://github.com/Thalhammer/jwt-cpp/tree/master/example)!
|
||||
|
||||
### Providing your own JSON Traits
|
||||
|
||||
There are several key items that need to be provided to a `jwt::basic_claim` in order for it to be interoptable with you JSON library of choice.
|
||||
|
||||
* type specifications
|
||||
* conversion from generic "value type" to a specific type
|
||||
* serialization and parsing
|
||||
|
||||
If ever you are not sure, the traits are heavily checked against static asserts to make sure you provide everything that's required.
|
||||
|
||||
> :warning: Not all JSON libraries are a like, you may need to extent certain types such that it can be used by jwt-cpp. See this [example](https://github.com/Thalhammer/jwt-cpp/blob/ac3de9e69bc698a464dacb256a1b50512843f092/tests/jsoncons/JsonconsTest.cpp).
|
||||
|
||||
```cpp
|
||||
struct my_favorite_json_library_traits {
|
||||
// Type Specifications
|
||||
using value_type = json; // The generic "value type" implementation, most libraries have one
|
||||
using object_type = json::object_t; // The "map type" string to value
|
||||
using array_type = json::array_t; // The "list type" array of values
|
||||
using string_type = std::string; // The "list of chars", must be a narrow char
|
||||
using number_type = double; // The "percision type"
|
||||
using integer_type = int64_t; // The "integral type"
|
||||
using boolean_type = bool; // The "boolean type"
|
||||
|
||||
// Translation between the implementation notion of type, to the jwt::json::type equivilant
|
||||
static jwt::json::type get_type(const value_type &val) {
|
||||
using jwt::json::type;
|
||||
|
||||
if (val.type() == json::value_t::object)
|
||||
return type::object;
|
||||
if (val.type() == json::value_t::array)
|
||||
return type::array;
|
||||
if (val.type() == json::value_t::string)
|
||||
return type::string;
|
||||
if (val.type() == json::value_t::number_float)
|
||||
return type::number;
|
||||
if (val.type() == json::value_t::number_integer)
|
||||
return type::integer;
|
||||
if (val.type() == json::value_t::boolean)
|
||||
return type::boolean;
|
||||
|
||||
throw std::logic_error("invalid type");
|
||||
}
|
||||
|
||||
// Conversion from generic value to specific type
|
||||
static object_type as_object(const value_type &val);
|
||||
static array_type as_array(const value_type &val);
|
||||
static string_type as_string(const value_type &val);
|
||||
static number_type as_number(const value_type &val);
|
||||
static integer_type as_int(const value_type &val);
|
||||
static boolean_type as_bool(const value_type &val);
|
||||
|
||||
// serilization and parsing
|
||||
static bool parse(value_type &val, string_type str);
|
||||
static string_type serialize(const value_type &val); // with no extra whitespace, padding or indentation
|
||||
};
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
If you have an improvement or found a bug feel free to [open an issue](https://github.com/Thalhammer/jwt-cpp/issues/new) or add the change and create a pull request. If you file a bug please make sure to include as much information about your environment (compiler version, etc.) as possible to help reproduce the issue. If you add a new feature please make sure to also include test cases for it.
|
||||
|
||||
## Dependencies
|
||||
|
||||
In order to use jwt-cpp you need the following tools.
|
||||
|
||||
* libcrypto (openssl or compatible)
|
||||
* libssl-dev (for the header files)
|
||||
* a compiler supporting at least c++11
|
||||
* basic stl support
|
||||
|
||||
In order to build the test cases you also need
|
||||
* gtest installed in linker path
|
||||
|
||||
* gtest
|
||||
* pthread
|
||||
|
||||
## Troubleshooting
|
||||
#### Expired tokens
|
||||
If you are generating tokens that seem to immediately expire, you are likely not using UTC. Specifically,
|
||||
if you use `get_time` to get the current time, it likely uses localtime, while this library uses UTC, which may be why your token is immediately expiring. Please see example above on the right way to use current time.
|
||||
|
||||
#### Missing _HMAC amd _EVP_sha256 symbols on Mac
|
||||
### Expired tokens
|
||||
|
||||
If you are generating tokens that seem to immediately expire, you are likely not using UTC. Specifically,
|
||||
if you use `get_time` to get the current time, it likely uses localtime, while this library uses UTC,
|
||||
which may be why your token is immediately expiring. Please see example above on the right way to use current time.
|
||||
|
||||
### Missing \_HMAC and \_EVP_sha256 symbols on Mac
|
||||
|
||||
There seems to exists a problem with the included openssl library of MacOS. Make sure you link to one provided by brew.
|
||||
See [here](https://github.com/Thalhammer/jwt-cpp/issues/6) for more details.
|
||||
#### Building on windows fails with syntax errors
|
||||
The header "Windows.h", which is often included in windowsprojects, defines macros for MIN and MAX which screw up std::numeric_limits.
|
||||
|
||||
### Building on windows fails with syntax errors
|
||||
|
||||
The header `<Windows.h>`, which is often included in windowsprojects, defines macros for MIN and MAX which screw up std::numeric_limits.
|
||||
See [here](https://github.com/Thalhammer/jwt-cpp/issues/5) for more details. To fix this do one of the following things:
|
||||
|
||||
* define NOMINMAX, which suppresses this behaviour
|
||||
* include this library before you include windows.h
|
||||
* place ```#undef max``` and ```#undef min``` before you include this library
|
||||
* place `#undef max` and `#undef min` before you include this library
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include "include/jwt-cpp/jwt.h"
|
||||
|
||||
TEST(TokenFormatTest, MissingDot) {
|
||||
ASSERT_THROW(jwt::decode("eyJhbGciOiJub25lIiwidHlwIjoiSldTIn0.eyJpc3MiOiJhdXRoMCJ9"), std::invalid_argument);
|
||||
ASSERT_THROW(jwt::decode("eyJhbGciOiJub25lIiwidHlwIjoiSldTIn0eyJpc3MiOiJhdXRoMCJ9."), std::invalid_argument);
|
||||
}
|
||||
|
||||
TEST(TokenFormatTest, InvalidChar) {
|
||||
ASSERT_THROW(jwt::decode("eyJhbGciOiJub25lIiwidHlwIjoiSldTIn0().eyJpc3MiOiJhdXRoMCJ9."), std::runtime_error);
|
||||
}
|
||||
|
||||
TEST(TokenFormatTest, InvalidJSON) {
|
||||
ASSERT_THROW(jwt::decode("YXsiYWxnIjoibm9uZSIsInR5cCI6IkpXUyJ9YQ.eyJpc3MiOiJhdXRoMCJ9."), std::runtime_error);
|
||||
}
|
|
@ -1,420 +0,0 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include "include/jwt-cpp/jwt.h"
|
||||
|
||||
namespace {
|
||||
extern std::string rsa_priv_key;
|
||||
extern std::string rsa_pub_key;
|
||||
extern std::string rsa_pub_key_invalid;
|
||||
extern std::string rsa512_priv_key;
|
||||
extern std::string rsa512_pub_key;
|
||||
extern std::string rsa512_pub_key_invalid;
|
||||
extern std::string ecdsa_priv_key;
|
||||
extern std::string ecdsa_pub_key;
|
||||
extern std::string ecdsa_pub_key_invalid;
|
||||
}
|
||||
|
||||
TEST(TokenTest, DecodeToken) {
|
||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||
auto decoded = jwt::decode(token);
|
||||
|
||||
ASSERT_TRUE(decoded.has_algorithm());
|
||||
ASSERT_TRUE(decoded.has_type());
|
||||
ASSERT_FALSE(decoded.has_content_type());
|
||||
ASSERT_FALSE(decoded.has_key_id());
|
||||
ASSERT_TRUE(decoded.has_issuer());
|
||||
ASSERT_FALSE(decoded.has_subject());
|
||||
ASSERT_FALSE(decoded.has_audience());
|
||||
ASSERT_FALSE(decoded.has_expires_at());
|
||||
ASSERT_FALSE(decoded.has_not_before());
|
||||
ASSERT_FALSE(decoded.has_issued_at());
|
||||
ASSERT_FALSE(decoded.has_id());
|
||||
|
||||
ASSERT_EQ("HS256", decoded.get_algorithm());
|
||||
ASSERT_EQ("JWS", decoded.get_type());
|
||||
ASSERT_EQ("auth0", decoded.get_issuer());
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateToken) {
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::none{});
|
||||
ASSERT_EQ("eyJhbGciOiJub25lIiwidHlwIjoiSldTIn0.eyJpc3MiOiJhdXRoMCJ9.", token);
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateTokenHS256) {
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::hs256{"secret"});
|
||||
ASSERT_EQ("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE", token);
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateTokenRS256) {
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::rs256(rsa_pub_key, rsa_priv_key, "", ""));
|
||||
|
||||
ASSERT_EQ(
|
||||
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
||||
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
||||
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ", token);
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateTokenRS512) {
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::rs512(rsa512_pub_key, rsa512_priv_key, "", ""));
|
||||
|
||||
ASSERT_EQ(
|
||||
"eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZSSQyLKvI0"
|
||||
"TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4GB"
|
||||
"hfGgejPBCBlGrQtqFGFdHHOjNHY", token);
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateTokenPS256) {
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::ps256(rsa_pub_key, rsa_priv_key, "", ""));
|
||||
|
||||
// TODO: Find a better way to check if generated signature is valid
|
||||
// Can't do simple check for equal since pss adds random salt.
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateTokenPS384) {
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::ps384(rsa_pub_key, rsa_priv_key, "", ""));
|
||||
|
||||
// TODO: Find a better way to check if generated signature is valid
|
||||
// Can't do simple check for equal since pss adds random salt.
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateTokenPS512) {
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::ps512(rsa_pub_key, rsa_priv_key, "", ""));
|
||||
|
||||
// TODO: Find a better way to check if generated signature is valid
|
||||
// Can't do simple check for equal since pss adds random salt.
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateTokenES256) {
|
||||
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::es256("", ecdsa_priv_key, "", ""));
|
||||
|
||||
auto decoded = jwt::decode(token);
|
||||
|
||||
ASSERT_THROW(jwt::verify().allow_algorithm(jwt::algorithm::es256(ecdsa_pub_key_invalid, "", "", "")).verify(decoded), jwt::signature_verification_exception);
|
||||
ASSERT_NO_THROW(jwt::verify().allow_algorithm(jwt::algorithm::es256(ecdsa_pub_key, "", "", "")).verify(decoded));
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateTokenES256NoPrivate) {
|
||||
|
||||
ASSERT_THROW([](){
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::es256(ecdsa_pub_key, "", "", ""));
|
||||
}(), jwt::signature_generation_exception);
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenRS256) {
|
||||
std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
||||
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
||||
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::rs256(rsa_pub_key, rsa_priv_key, "", ""))
|
||||
.with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
verify.verify(decoded_token);
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenRS256PublicOnly) {
|
||||
std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
||||
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
||||
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::rs256(rsa_pub_key, "", "", ""))
|
||||
.with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
verify.verify(decoded_token);
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenRS256Fail) {
|
||||
std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
||||
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
||||
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::rs256(rsa_pub_key_invalid, "", "", ""))
|
||||
.with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenRS512) {
|
||||
std::string token = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
|
||||
"SSQyLKvI0TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4"
|
||||
"GBhfGgejPBCBlGrQtqFGFdHHOjNHY";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::rs512(rsa512_pub_key, rsa512_priv_key, "", ""))
|
||||
.with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
verify.verify(decoded_token);
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenRS512PublicOnly) {
|
||||
std::string token = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
|
||||
"SSQyLKvI0TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4"
|
||||
"GBhfGgejPBCBlGrQtqFGFdHHOjNHY";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::rs512(rsa512_pub_key, "", "", ""))
|
||||
.with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
verify.verify(decoded_token);
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenRS512Fail) {
|
||||
std::string token = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
|
||||
"SSQyLKvI0TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4"
|
||||
"GBhfGgejPBCBlGrQtqFGFdHHOjNHY";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::rs512(rsa_pub_key_invalid, "", "", ""))
|
||||
.with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenHS256) {
|
||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::hs256{ "secret" })
|
||||
.with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
verify.verify(decoded_token);
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyFail) {
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::none{});
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
{
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::none{})
|
||||
.with_issuer("auth");
|
||||
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
||||
}
|
||||
{
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::none{})
|
||||
.with_issuer("auth0")
|
||||
.with_audience({ "test" });
|
||||
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
||||
}
|
||||
{
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::none{})
|
||||
.with_issuer("auth0")
|
||||
.with_subject("test");
|
||||
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
||||
}
|
||||
{
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::none{})
|
||||
.with_issuer("auth0")
|
||||
.with_claim("myclaim", jwt::claim(std::string("test")));
|
||||
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenES256) {
|
||||
const std::string token = "eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJhdXRoMCJ9.4iVk3-Y0v4RT4_9IaQlp-8dZ_4fsTzIylgrPTDLrEvTHBTyVS3tgPbr2_IZfLETtiKRqCg0aQ5sh9eIsTTwB1g";
|
||||
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::es256(ecdsa_pub_key, "", "", ""));
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
verify.verify(decoded_token);
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenES256Fail) {
|
||||
const std::string token = "eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJhdXRoMCJ9.4iVk3-Y0v4RT4_9IaQlp-8dZ_4fsTzIylgrPTDLrEvTHBTyVS3tgPbr2_IZfLETtiKRqCg0aQ5sh9eIsTTwB1g";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::es256(ecdsa_pub_key_invalid, "", "", ""));
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenPS256) {
|
||||
std::string token = "eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.CJ4XjVWdbV6vXGZkD4GdJbtYc80SN9cmPOqRhZBRzOyDRqTFE"
|
||||
"4MsbdKyQuhAWcvuMOjn-24qOTjVMR_P_uTC1uG6WPLcucxZyLnbb56zbKnEklW2SX0mQnCGewr-93a_vDaFT6Cp45MsF_OwFPRCMaS5CJg-"
|
||||
"N5KY67UrVSr3s9nkuK9ZTQkyODHfyEUh9F_FhRCATGrb5G7_qHqBYvTvaPUXqzhhpCjN855Tocg7A24Hl0yMwM-XdasucW5xNdKjG_YCkis"
|
||||
"HX7ax--JiF5GNYCO61eLFteO4THUg-3Z0r4OlGqlppyWo5X5tjcxOZCvBh7WDWfkxA48KFZPRv0nlKA";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::ps256(rsa_pub_key, rsa_priv_key, "", ""))
|
||||
.with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
verify.verify(decoded_token);
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenPS256PublicOnly) {
|
||||
std::string token = "eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.CJ4XjVWdbV6vXGZkD4GdJbtYc80SN9cmPOqRhZBRzOyDRqTFE"
|
||||
"4MsbdKyQuhAWcvuMOjn-24qOTjVMR_P_uTC1uG6WPLcucxZyLnbb56zbKnEklW2SX0mQnCGewr-93a_vDaFT6Cp45MsF_OwFPRCMaS5CJg-"
|
||||
"N5KY67UrVSr3s9nkuK9ZTQkyODHfyEUh9F_FhRCATGrb5G7_qHqBYvTvaPUXqzhhpCjN855Tocg7A24Hl0yMwM-XdasucW5xNdKjG_YCkis"
|
||||
"HX7ax--JiF5GNYCO61eLFteO4THUg-3Z0r4OlGqlppyWo5X5tjcxOZCvBh7WDWfkxA48KFZPRv0nlKA";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::ps256(rsa_pub_key, "", "", ""))
|
||||
.with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
verify.verify(decoded_token);
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenPS256Fail) {
|
||||
std::string token = "eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.CJ4XjVWdbV6vXGZkD4GdJbtYc80SN9cmPOqRhZBRzOyDRqTFE"
|
||||
"4MsbdKyQuhAWcvuMOjn-24qOTjVMR_P_uTC1uG6WPLcucxZyLnbb56zbKnEklW2SX0mQnCGewr-93a_vDaFT6Cp45MsF_OwFPRCMaS5CJg-"
|
||||
"N5KY67UrVSr3s9nkuK9ZTQkyODHfyEUh9F_FhRCATGrb5G7_qHqBYvTvaPUXqzhhpCjN855Tocg7A24Hl0yMwM-XdasucW5xNdKjG_YCkis"
|
||||
"HX7ax--JiF5GNYCO61eLFteO4THUg-3Z0r4OlGqlppyWo5X5tjcxOZCvBh7WDWfkxA48KFZPRv0nlKA";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::ps256(rsa_pub_key_invalid, "", "", ""))
|
||||
.with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
||||
}
|
||||
|
||||
namespace {
|
||||
std::string rsa_priv_key = R"(-----BEGIN PRIVATE KEY-----
|
||||
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC4ZtdaIrd1BPIJ
|
||||
tfnF0TjIK5inQAXZ3XlCrUlJdP+XHwIRxdv1FsN12XyMYO/6ymLmo9ryoQeIrsXB
|
||||
XYqlET3zfAY+diwCb0HEsVvhisthwMU4gZQu6TYW2s9LnXZB5rVtcBK69hcSlA2k
|
||||
ZudMZWxZcj0L7KMfO2rIvaHw/qaVOE9j0T257Z8Kp2CLF9MUgX0ObhIsdumFRLaL
|
||||
DvDUmBPr2zuh/34j2XmWwn1yjN/WvGtdfhXW79Ki1S40HcWnygHgLV8sESFKUxxQ
|
||||
mKvPUTwDOIwLFL5WtE8Mz7N++kgmDcmWMCHc8kcOIu73Ta/3D4imW7VbKgHZo9+K
|
||||
3ESFE3RjAgMBAAECggEBAJTEIyjMqUT24G2FKiS1TiHvShBkTlQdoR5xvpZMlYbN
|
||||
tVWxUmrAGqCQ/TIjYnfpnzCDMLhdwT48Ab6mQJw69MfiXwc1PvwX1e9hRscGul36
|
||||
ryGPKIVQEBsQG/zc4/L2tZe8ut+qeaK7XuYrPp8bk/X1e9qK5m7j+JpKosNSLgJj
|
||||
NIbYsBkG2Mlq671irKYj2hVZeaBQmWmZxK4fw0Istz2WfN5nUKUeJhTwpR+JLUg4
|
||||
ELYYoB7EO0Cej9UBG30hbgu4RyXA+VbptJ+H042K5QJROUbtnLWuuWosZ5ATldwO
|
||||
u03dIXL0SH0ao5NcWBzxU4F2sBXZRGP2x/jiSLHcqoECgYEA4qD7mXQpu1b8XO8U
|
||||
6abpKloJCatSAHzjgdR2eRDRx5PMvloipfwqA77pnbjTUFajqWQgOXsDTCjcdQui
|
||||
wf5XAaWu+TeAVTytLQbSiTsBhrnoqVrr3RoyDQmdnwHT8aCMouOgcC5thP9vQ8Us
|
||||
rVdjvRRbnJpg3BeSNimH+u9AHgsCgYEA0EzcbOltCWPHRAY7B3Ge/AKBjBQr86Kv
|
||||
TdpTlxePBDVIlH+BM6oct2gaSZZoHbqPjbq5v7yf0fKVcXE4bSVgqfDJ/sZQu9Lp
|
||||
PTeV7wkk0OsAMKk7QukEpPno5q6tOTNnFecpUhVLLlqbfqkB2baYYwLJR3IRzboJ
|
||||
FQbLY93E8gkCgYB+zlC5VlQbbNqcLXJoImqItgQkkuW5PCgYdwcrSov2ve5r/Acz
|
||||
FNt1aRdSlx4176R3nXyibQA1Vw+ztiUFowiP9WLoM3PtPZwwe4bGHmwGNHPIfwVG
|
||||
m+exf9XgKKespYbLhc45tuC08DATnXoYK7O1EnUINSFJRS8cezSI5eHcbQKBgQDC
|
||||
PgqHXZ2aVftqCc1eAaxaIRQhRmY+CgUjumaczRFGwVFveP9I6Gdi+Kca3DE3F9Pq
|
||||
PKgejo0SwP5vDT+rOGHN14bmGJUMsX9i4MTmZUZ5s8s3lXh3ysfT+GAhTd6nKrIE
|
||||
kM3Nh6HWFhROptfc6BNusRh1kX/cspDplK5x8EpJ0QKBgQDWFg6S2je0KtbV5PYe
|
||||
RultUEe2C0jYMDQx+JYxbPmtcopvZQrFEur3WKVuLy5UAy7EBvwMnZwIG7OOohJb
|
||||
vkSpADK6VPn9lbqq7O8cTedEHttm6otmLt8ZyEl3hZMaL3hbuRj6ysjmoFKx6CrX
|
||||
rK0/Ikt5ybqUzKCMJZg2VKGTxg==
|
||||
-----END PRIVATE KEY-----)";
|
||||
std::string rsa_pub_key = R"(-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuGbXWiK3dQTyCbX5xdE4
|
||||
yCuYp0AF2d15Qq1JSXT/lx8CEcXb9RbDddl8jGDv+spi5qPa8qEHiK7FwV2KpRE9
|
||||
83wGPnYsAm9BxLFb4YrLYcDFOIGULuk2FtrPS512Qea1bXASuvYXEpQNpGbnTGVs
|
||||
WXI9C+yjHztqyL2h8P6mlThPY9E9ue2fCqdgixfTFIF9Dm4SLHbphUS2iw7w1JgT
|
||||
69s7of9+I9l5lsJ9cozf1rxrXX4V1u/SotUuNB3Fp8oB4C1fLBEhSlMcUJirz1E8
|
||||
AziMCxS+VrRPDM+zfvpIJg3JljAh3PJHDiLu902v9w+Iplu1WyoB2aPfitxEhRN0
|
||||
YwIDAQAB
|
||||
-----END PUBLIC KEY-----)";
|
||||
std::string rsa_pub_key_invalid = R"(-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxzYuc22QSst/dS7geYYK
|
||||
5l5kLxU0tayNdixkEQ17ix+CUcUbKIsnyftZxaCYT46rQtXgCaYRdJcbB3hmyrOa
|
||||
vkhTpX79xJZnQmfuamMbZBqitvscxW9zRR9tBUL6vdi/0rpoUwPMEh8+Bw7CgYR0
|
||||
FK0DhWYBNDfe9HKcyZEv3max8Cdq18htxjEsdYO0iwzhtKRXomBWTdhD5ykd/fAC
|
||||
VTr4+KEY+IeLvubHVmLUhbE5NgWXxrRpGasDqzKhCTmsa2Ysf712rl57SlH0Wz/M
|
||||
r3F7aM9YpErzeYLrl0GhQr9BVJxOvXcVd4kmY+XkiCcrkyS1cnghnllh+LCwQu1s
|
||||
YwIDAQAB
|
||||
-----END PUBLIC KEY-----)";
|
||||
std::string rsa512_priv_key = R"(-----BEGIN RSA PRIVATE KEY-----
|
||||
MIICWwIBAAKBgQDdlatRjRjogo3WojgGHFHYLugdUWAY9iR3fy4arWNA1KoS8kVw
|
||||
33cJibXr8bvwUAUparCwlvdbH6dvEOfou0/gCFQsHUfQrSDv+MuSUMAe8jzKE4qW
|
||||
+jK+xQU9a03GUnKHkkle+Q0pX/g6jXZ7r1/xAK5Do2kQ+X5xK9cipRgEKwIDAQAB
|
||||
AoGAD+onAtVye4ic7VR7V50DF9bOnwRwNXrARcDhq9LWNRrRGElESYYTQ6EbatXS
|
||||
3MCyjjX2eMhu/aF5YhXBwkppwxg+EOmXeh+MzL7Zh284OuPbkglAaGhV9bb6/5Cp
|
||||
uGb1esyPbYW+Ty2PC0GSZfIXkXs76jXAu9TOBvD0ybc2YlkCQQDywg2R/7t3Q2OE
|
||||
2+yo382CLJdrlSLVROWKwb4tb2PjhY4XAwV8d1vy0RenxTB+K5Mu57uVSTHtrMK0
|
||||
GAtFr833AkEA6avx20OHo61Yela/4k5kQDtjEf1N0LfI+BcWZtxsS3jDM3i1Hp0K
|
||||
Su5rsCPb8acJo5RO26gGVrfAsDcIXKC+bQJAZZ2XIpsitLyPpuiMOvBbzPavd4gY
|
||||
6Z8KWrfYzJoI/Q9FuBo6rKwl4BFoToD7WIUS+hpkagwWiz+6zLoX1dbOZwJACmH5
|
||||
fSSjAkLRi54PKJ8TFUeOP15h9sQzydI8zJU+upvDEKZsZc/UhT/SySDOxQ4G/523
|
||||
Y0sz/OZtSWcol/UMgQJALesy++GdvoIDLfJX5GBQpuFgFenRiRDabxrE9MNUZ2aP
|
||||
FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==
|
||||
-----END RSA PRIVATE KEY-----)";
|
||||
std::string rsa512_pub_key = R"(-----BEGIN PUBLIC KEY-----
|
||||
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdlatRjRjogo3WojgGHFHYLugd
|
||||
UWAY9iR3fy4arWNA1KoS8kVw33cJibXr8bvwUAUparCwlvdbH6dvEOfou0/gCFQs
|
||||
HUfQrSDv+MuSUMAe8jzKE4qW+jK+xQU9a03GUnKHkkle+Q0pX/g6jXZ7r1/xAK5D
|
||||
o2kQ+X5xK9cipRgEKwIDAQAB
|
||||
-----END PUBLIC KEY-----)";
|
||||
std::string rsa512_pub_key_invalid = R"(-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxzYuc22QSst/dS7geYYK
|
||||
5l5kLxU0tayNdixkEQ17ix+CUcUbKIsnyftZxaCYT46rQtXgCaYRdJcbB3hmyrOa
|
||||
vkhTpX79xJZnQmfuamMbZBqitvscxW9zRR9tBUL6vdi/0rpoUwPMEh8+Bw7CgYR0
|
||||
FK0DhWYBNDfe9HKcyZEv3max8Cdq18htxjEsdYO0iwzhtKRXomBWTdhD5ykd/fAC
|
||||
VTr4+KEY+IeLvubHVmLUhbE5NgWXxrRpGasDqzKhCTmsa2Ysf712rl57SlH0Wz/M
|
||||
r3F7aM9YpErzeYLrl0GhQr9BVJxOvXcVd4kmY+XkiCcrkyS1cnghnllh+LCwQu1s
|
||||
YwIDAQAB
|
||||
-----END PUBLIC KEY-----)";
|
||||
std::string ecdsa_priv_key = R"(-----BEGIN PRIVATE KEY-----
|
||||
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgPGJGAm4X1fvBuC1z
|
||||
SpO/4Izx6PXfNMaiKaS5RUkFqEGhRANCAARCBvmeksd3QGTrVs2eMrrfa7CYF+sX
|
||||
sjyGg+Bo5mPKGH4Gs8M7oIvoP9pb/I85tdebtKlmiCZHAZE5w4DfJSV6
|
||||
-----END PRIVATE KEY-----)";
|
||||
std::string ecdsa_pub_key = R"(-----BEGIN PUBLIC KEY-----
|
||||
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEQgb5npLHd0Bk61bNnjK632uwmBfr
|
||||
F7I8hoPgaOZjyhh+BrPDO6CL6D/aW/yPObXXm7SpZogmRwGROcOA3yUleg==
|
||||
-----END PUBLIC KEY-----)";
|
||||
std::string ecdsa_pub_key_invalid = R"(-----BEGIN PUBLIC KEY-----
|
||||
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEoBUyo8CQAFPeYPvv78ylh5MwFZjT
|
||||
CLQeb042TjiMJxG+9DLFmRSMlBQ9T/RsLLc+PmpB1+7yPAR+oR5gZn3kJQ==
|
||||
-----END PUBLIC KEY-----)";
|
||||
}
|
|
@ -1,39 +1,64 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
#ifndef JWT_CPP_BASE_H
|
||||
#define JWT_CPP_BASE_H
|
||||
|
||||
#include <array>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#ifdef __has_cpp_attribute
|
||||
#if __has_cpp_attribute(fallthrough)
|
||||
#define JWT_FALLTHROUGH [[fallthrough]]
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef JWT_FALLTHROUGH
|
||||
#define JWT_FALLTHROUGH
|
||||
#endif
|
||||
|
||||
namespace jwt {
|
||||
/**
|
||||
* \brief character maps when encoding and decoding
|
||||
*/
|
||||
namespace alphabet {
|
||||
/**
|
||||
* \brief valid list of characted when working with [Base64](https://tools.ietf.org/html/rfc3548)
|
||||
*/
|
||||
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 constexpr 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 = "=";
|
||||
static std::string fill{"="};
|
||||
return fill;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* \brief valid list of characted when working with [Base64URL](https://tools.ietf.org/html/rfc4648)
|
||||
*/
|
||||
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 constexpr 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";
|
||||
static std::string fill{"%3d"};
|
||||
return fill;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace alphabet
|
||||
|
||||
/**
|
||||
* \brief Alphabet generic methods for working with encoding/decoding the base64 family
|
||||
*/
|
||||
class base {
|
||||
public:
|
||||
template<typename T>
|
||||
|
@ -44,18 +69,27 @@ 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) {
|
||||
static std::string encode(const std::string& bin, const std::array<char, 64>& alphabet,
|
||||
const std::string& fill) {
|
||||
size_t size = bin.size();
|
||||
std::string res;
|
||||
|
||||
// clear incomplete bytes
|
||||
size_t fast_size = size - size % 3;
|
||||
for (size_t i = 0; i < fast_size;) {
|
||||
uint32_t octet_a = (unsigned char)bin[i++];
|
||||
uint32_t octet_b = (unsigned char)bin[i++];
|
||||
uint32_t octet_c = (unsigned char)bin[i++];
|
||||
uint32_t octet_a = static_cast<unsigned char>(bin[i++]);
|
||||
uint32_t octet_b = static_cast<unsigned char>(bin[i++]);
|
||||
uint32_t octet_c = static_cast<unsigned char>(bin[i++]);
|
||||
|
||||
uint32_t triple = (octet_a << 0x10) + (octet_b << 0x08) + octet_c;
|
||||
|
||||
|
@ -65,14 +99,13 @@ namespace jwt {
|
|||
res += alphabet[(triple >> 0 * 6) & 0x3F];
|
||||
}
|
||||
|
||||
if (fast_size == size)
|
||||
return res;
|
||||
if (fast_size == size) return res;
|
||||
|
||||
size_t mod = size % 3;
|
||||
|
||||
uint32_t octet_a = fast_size < size ? (unsigned char)bin[fast_size++] : 0;
|
||||
uint32_t octet_b = fast_size < size ? (unsigned char)bin[fast_size++] : 0;
|
||||
uint32_t octet_c = fast_size < size ? (unsigned char)bin[fast_size++] : 0;
|
||||
uint32_t octet_a = fast_size < size ? static_cast<unsigned char>(bin[fast_size++]) : 0;
|
||||
uint32_t octet_b = fast_size < size ? static_cast<unsigned char>(bin[fast_size++]) : 0;
|
||||
uint32_t octet_c = fast_size < size ? static_cast<unsigned char>(bin[fast_size++]) : 0;
|
||||
|
||||
uint32_t triple = (octet_a << 0x10) + (octet_b << 0x08) + octet_c;
|
||||
|
||||
|
@ -89,14 +122,14 @@ namespace jwt {
|
|||
res += alphabet[(triple >> 1 * 6) & 0x3F];
|
||||
res += fill;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static std::string decode(const std::string& base, const std::array<char, 64>& alphabet, const std::string& fill) {
|
||||
static std::string decode(const std::string& base, const std::array<char, 64>& alphabet,
|
||||
const std::string& fill) {
|
||||
size_t size = base.size();
|
||||
|
||||
size_t fill_cnt = 0;
|
||||
|
@ -104,14 +137,12 @@ namespace jwt {
|
|||
if (base.substr(size - fill.size(), fill.size()) == fill) {
|
||||
fill_cnt++;
|
||||
size -= fill.size();
|
||||
if(fill_cnt > 2)
|
||||
throw std::runtime_error("Invalid input");
|
||||
}
|
||||
else break;
|
||||
if (fill_cnt > 2) throw std::runtime_error("Invalid input");
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
||||
if ((size + fill_cnt) % 4 != 0)
|
||||
throw std::runtime_error("Invalid input");
|
||||
if ((size + fill_cnt) % 4 != 0) throw std::runtime_error("Invalid input");
|
||||
|
||||
size_t out_size = size / 4 * 3;
|
||||
std::string res;
|
||||
|
@ -119,13 +150,11 @@ namespace jwt {
|
|||
|
||||
auto get_sextet = [&](size_t offset) {
|
||||
for (size_t i = 0; i < alphabet.size(); i++) {
|
||||
if (alphabet[i] == base[offset])
|
||||
return i;
|
||||
if (alphabet[i] == base[offset]) return static_cast<uint32_t>(i);
|
||||
}
|
||||
throw std::runtime_error("Invalid input");
|
||||
};
|
||||
|
||||
|
||||
size_t fast_size = size - size % 4;
|
||||
for (size_t i = 0; i < fast_size;) {
|
||||
uint32_t sextet_a = get_sextet(i++);
|
||||
|
@ -133,36 +162,47 @@ namespace jwt {
|
|||
uint32_t sextet_c = get_sextet(i++);
|
||||
uint32_t sextet_d = get_sextet(i++);
|
||||
|
||||
uint32_t triple = (sextet_a << 3 * 6)
|
||||
+ (sextet_b << 2 * 6)
|
||||
+ (sextet_c << 1 * 6)
|
||||
+ (sextet_d << 0 * 6);
|
||||
uint32_t triple = (sextet_a << 3 * 6) + (sextet_b << 2 * 6) + (sextet_c << 1 * 6) + (sextet_d << 0 * 6);
|
||||
|
||||
res += (triple >> 2 * 8) & 0xFF;
|
||||
res += (triple >> 1 * 8) & 0xFF;
|
||||
res += (triple >> 0 * 8) & 0xFF;
|
||||
res += static_cast<char>((triple >> 2 * 8) & 0xFFU);
|
||||
res += static_cast<char>((triple >> 1 * 8) & 0xFFU);
|
||||
res += static_cast<char>((triple >> 0 * 8) & 0xFFU);
|
||||
}
|
||||
|
||||
if (fill_cnt == 0)
|
||||
return res;
|
||||
if (fill_cnt == 0) return res;
|
||||
|
||||
uint32_t triple = (get_sextet(fast_size) << 3 * 6)
|
||||
+ (get_sextet(fast_size + 1) << 2 * 6);
|
||||
uint32_t triple = (get_sextet(fast_size) << 3 * 6) + (get_sextet(fast_size + 1) << 2 * 6);
|
||||
|
||||
switch (fill_cnt) {
|
||||
case 1:
|
||||
triple |= (get_sextet(fast_size + 2) << 1 * 6);
|
||||
res += (triple >> 2 * 8) & 0xFF;
|
||||
res += (triple >> 1 * 8) & 0xFF;
|
||||
break;
|
||||
case 2:
|
||||
res += (triple >> 2 * 8) & 0xFF;
|
||||
break;
|
||||
default:
|
||||
res += static_cast<char>((triple >> 2 * 8) & 0xFFU);
|
||||
res += static_cast<char>((triple >> 1 * 8) & 0xFFU);
|
||||
break;
|
||||
case 2: res += static_cast<char>((triple >> 2 * 8) & 0xFFU); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace jwt
|
||||
|
||||
#endif
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -76,8 +76,14 @@ extern "C" {
|
|||
// experimental support for int64_t (see README.mkdn for detail)
|
||||
#ifdef PICOJSON_USE_INT64
|
||||
#define __STDC_FORMAT_MACROS
|
||||
#include <errno.h>
|
||||
#include <cerrno>
|
||||
#if __cplusplus >= 201103L
|
||||
#include <cinttypes>
|
||||
#else
|
||||
extern "C" {
|
||||
#include <inttypes.h>
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// to disable the use of localeconv(3), set PICOJSON_USE_LOCALE to 0
|
||||
|
@ -104,6 +110,7 @@ extern "C" {
|
|||
#pragma warning(disable : 4244) // conversion from int to char
|
||||
#pragma warning(disable : 4127) // conditional expression is constant
|
||||
#pragma warning(disable : 4702) // unreachable code
|
||||
#pragma warning(disable : 4706) // assignment within conditional expression
|
||||
#else
|
||||
#define SNPRINTF snprintf
|
||||
#endif
|
||||
|
@ -123,7 +130,7 @@ enum {
|
|||
#endif
|
||||
};
|
||||
|
||||
enum { INDENT_WIDTH = 2 };
|
||||
enum { INDENT_WIDTH = 2, DEFAULT_MAX_DEPTHS = 100 };
|
||||
|
||||
struct null {};
|
||||
|
||||
|
@ -377,7 +384,7 @@ GET(array, *u_.array_)
|
|||
GET(object, *u_.object_)
|
||||
#ifdef PICOJSON_USE_INT64
|
||||
GET(double,
|
||||
(type_ == int64_type && (const_cast<value *>(this)->type_ = number_type, const_cast<value *>(this)->u_.number_ = u_.int64_),
|
||||
(type_ == int64_type && (const_cast<value *>(this)->type_ = number_type, (const_cast<value *>(this)->u_.number_ = u_.int64_)),
|
||||
u_.number_))
|
||||
GET(int64_t, u_.int64_)
|
||||
#else
|
||||
|
@ -832,7 +839,7 @@ template <typename Context, typename Iter> inline bool _parse_object(Context &ct
|
|||
return false;
|
||||
}
|
||||
if (in.expect('}')) {
|
||||
return true;
|
||||
return ctx.parse_object_stop();
|
||||
}
|
||||
do {
|
||||
std::string key;
|
||||
|
@ -843,7 +850,7 @@ template <typename Context, typename Iter> inline bool _parse_object(Context &ct
|
|||
return false;
|
||||
}
|
||||
} while (in.expect(','));
|
||||
return in.expect('}');
|
||||
return in.expect('}') && ctx.parse_object_stop();
|
||||
}
|
||||
|
||||
template <typename Iter> inline std::string _parse_number(input<Iter> &in) {
|
||||
|
@ -959,9 +966,10 @@ public:
|
|||
class default_parse_context {
|
||||
protected:
|
||||
value *out_;
|
||||
size_t depths_;
|
||||
|
||||
public:
|
||||
default_parse_context(value *out) : out_(out) {
|
||||
default_parse_context(value *out, size_t depths = DEFAULT_MAX_DEPTHS) : out_(out), depths_(depths) {
|
||||
}
|
||||
bool set_null() {
|
||||
*out_ = value();
|
||||
|
@ -986,27 +994,37 @@ public:
|
|||
return _parse_string(out_->get<std::string>(), in);
|
||||
}
|
||||
bool parse_array_start() {
|
||||
if (depths_ == 0)
|
||||
return false;
|
||||
--depths_;
|
||||
*out_ = value(array_type, false);
|
||||
return true;
|
||||
}
|
||||
template <typename Iter> bool parse_array_item(input<Iter> &in, size_t) {
|
||||
array &a = out_->get<array>();
|
||||
a.push_back(value());
|
||||
default_parse_context ctx(&a.back());
|
||||
default_parse_context ctx(&a.back(), depths_);
|
||||
return _parse(ctx, in);
|
||||
}
|
||||
bool parse_array_stop(size_t) {
|
||||
++depths_;
|
||||
return true;
|
||||
}
|
||||
bool parse_object_start() {
|
||||
if (depths_ == 0)
|
||||
return false;
|
||||
*out_ = value(object_type, false);
|
||||
return true;
|
||||
}
|
||||
template <typename Iter> bool parse_object_item(input<Iter> &in, const std::string &key) {
|
||||
object &o = out_->get<object>();
|
||||
default_parse_context ctx(&o[key]);
|
||||
default_parse_context ctx(&o[key], depths_);
|
||||
return _parse(ctx, in);
|
||||
}
|
||||
bool parse_object_stop() {
|
||||
++depths_;
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
default_parse_context(const default_parse_context &);
|
||||
|
@ -1014,6 +1032,9 @@ private:
|
|||
};
|
||||
|
||||
class null_parse_context {
|
||||
protected:
|
||||
size_t depths_;
|
||||
|
||||
public:
|
||||
struct dummy_str {
|
||||
void push_back(int) {
|
||||
|
@ -1021,7 +1042,7 @@ public:
|
|||
};
|
||||
|
||||
public:
|
||||
null_parse_context() {
|
||||
null_parse_context(size_t depths = DEFAULT_MAX_DEPTHS) : depths_(depths) {
|
||||
}
|
||||
bool set_null() {
|
||||
return true;
|
||||
|
@ -1042,20 +1063,31 @@ public:
|
|||
return _parse_string(s, in);
|
||||
}
|
||||
bool parse_array_start() {
|
||||
if (depths_ == 0)
|
||||
return false;
|
||||
--depths_;
|
||||
return true;
|
||||
}
|
||||
template <typename Iter> bool parse_array_item(input<Iter> &in, size_t) {
|
||||
return _parse(*this, in);
|
||||
}
|
||||
bool parse_array_stop(size_t) {
|
||||
++depths_;
|
||||
return true;
|
||||
}
|
||||
bool parse_object_start() {
|
||||
if (depths_ == 0)
|
||||
return false;
|
||||
--depths_;
|
||||
return true;
|
||||
}
|
||||
template <typename Iter> bool parse_object_item(input<Iter> &in, const std::string &) {
|
||||
++depths_;
|
||||
return _parse(*this, in);
|
||||
}
|
||||
bool parse_object_stop() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
null_parse_context(const null_parse_context &);
|
||||
|
@ -1165,4 +1197,4 @@ inline std::ostream &operator<<(std::ostream &os, const picojson::value &x) {
|
|||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
|
@ -1,28 +0,0 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jwt-cpp", "jwt-cpp.vcxproj", "{1CA8C676-7F8E-434C-9069-8F20A562E6E9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{1CA8C676-7F8E-434C-9069-8F20A562E6E9}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{1CA8C676-7F8E-434C-9069-8F20A562E6E9}.Debug|x64.Build.0 = Debug|x64
|
||||
{1CA8C676-7F8E-434C-9069-8F20A562E6E9}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{1CA8C676-7F8E-434C-9069-8F20A562E6E9}.Debug|x86.Build.0 = Debug|Win32
|
||||
{1CA8C676-7F8E-434C-9069-8F20A562E6E9}.Release|x64.ActiveCfg = Release|x64
|
||||
{1CA8C676-7F8E-434C-9069-8F20A562E6E9}.Release|x64.Build.0 = Release|x64
|
||||
{1CA8C676-7F8E-434C-9069-8F20A562E6E9}.Release|x86.ActiveCfg = Release|Win32
|
||||
{1CA8C676-7F8E-434C-9069-8F20A562E6E9}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -1,160 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{1CA8C676-7F8E-434C-9069-8F20A562E6E9}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>jwtcpp</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>gtest.lib;gtest_main.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>gtest.lib;gtest_main.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>gtest.lib;gtest_main.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>gtest.lib;gtest_main.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="include\jwt-cpp\base.h" />
|
||||
<ClInclude Include="include\jwt-cpp\jwt.h" />
|
||||
<ClInclude Include="include\jwt-cpp\picojson.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="BaseTest.cpp" />
|
||||
<ClCompile Include="TokenTest.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -1,36 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Quelldateien">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Headerdateien">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Ressourcendateien">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="include\jwt-cpp\jwt.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\jwt-cpp\picojson.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\jwt-cpp\base.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="BaseTest.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="TokenTest.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,3 +0,0 @@
|
|||
Source: jwt-cpp
|
||||
Version: 2019-04-20
|
||||
Description: A header only library for creating and validating json web tokens in c++
|
|
@ -1,12 +0,0 @@
|
|||
diff --git a/include/jwt-cpp/jwt.h b/include/jwt-cpp/jwt.h
|
||||
index ec56810..a26fd97 100644
|
||||
--- a/include/jwt-cpp/jwt.h
|
||||
+++ b/include/jwt-cpp/jwt.h
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#define PICOJSON_USE_INT64
|
||||
-#include "picojson.h"
|
||||
+#include "picojson/picojson.h"
|
||||
#include "base.h"
|
||||
#include <set>
|
||||
#include <chrono>
|
|
@ -1,31 +0,0 @@
|
|||
diff --git a/include/jwt-cpp/base.h b/include/jwt-cpp/base.h
|
||||
index dfca7fc..4d05c0b 100644
|
||||
--- a/include/jwt-cpp/base.h
|
||||
+++ b/include/jwt-cpp/base.h
|
||||
@@ -2,6 +2,10 @@
|
||||
#include <string>
|
||||
#include <array>
|
||||
|
||||
+#ifdef _MSC_VER
|
||||
+#pragma warning(disable : 4267)
|
||||
+#endif
|
||||
+
|
||||
namespace jwt {
|
||||
namespace alphabet {
|
||||
struct base64 {
|
||||
diff --git a/include/jwt-cpp/jwt.h b/include/jwt-cpp/jwt.h
|
||||
index ec56810..313cef2 100644
|
||||
--- a/include/jwt-cpp/jwt.h
|
||||
+++ b/include/jwt-cpp/jwt.h
|
||||
@@ -12,6 +12,11 @@
|
||||
#include <openssl/ec.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
+#ifdef _MSC_VER
|
||||
+#pragma warning(disable : 4267)
|
||||
+#pragma warning(disable : 4067)
|
||||
+#endif
|
||||
+
|
||||
//If openssl version less than 1.1
|
||||
#if OPENSSL_VERSION_NUMBER < 269484032
|
||||
#define OPENSSL10
|
|
@ -1,23 +0,0 @@
|
|||
#header-only library
|
||||
include(vcpkg_common_functions)
|
||||
|
||||
set(SOURCE_PATH ${CURRENT_BUILDTREES_DIR}/src/jwt-cpp)
|
||||
|
||||
vcpkg_from_github(OUT_SOURCE_PATH SOURCE_PATH
|
||||
REPO Thalhammer/jwt-cpp
|
||||
REF f0e37a79f605312686065405dd720fc197cc3df0
|
||||
SHA512 ae83c205dbb340dedc58d0d3f0e2453c4edcf5ce43b401f49d02692dc8a2a4b7260f1ced05ddfa7c1d5d6f92446e232629ddbdf67a58a119b50c5c8163591598
|
||||
HEAD_REF master
|
||||
PATCHES fix-picojson.patch
|
||||
fix-warning.patch)
|
||||
|
||||
# Copy the constexpr header files
|
||||
file(GLOB HEADER_FILES ${SOURCE_PATH}/include/jwt-cpp/*)
|
||||
file(COPY ${HEADER_FILES}
|
||||
DESTINATION ${CURRENT_PACKAGES_DIR}/include/jwt-cpp
|
||||
REGEX "\.(gitattributes|gitignore|picojson.h)$" EXCLUDE)
|
||||
|
||||
# Put the licence file where vcpkg expects it
|
||||
file(COPY ${SOURCE_PATH}/LICENSE
|
||||
DESTINATION ${CURRENT_PACKAGES_DIR}/share/jwt-cpp)
|
||||
file(RENAME ${CURRENT_PACKAGES_DIR}/share/jwt-cpp/LICENSE ${CURRENT_PACKAGES_DIR}/share/jwt-cpp/copyright)
|
|
@ -8,7 +8,7 @@
|
|||
#if HAVE_LIBJWT
|
||||
#include <jwt.h>
|
||||
#else
|
||||
#include "jwt_cpp.h"
|
||||
#include <jwt-cpp/jwt.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_LIBCRYPTO
|
||||
|
|
Loading…
Reference in New Issue