Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Checks: '-*,
readability-*,
-readability-magic-numbers,
-readability-braces-around-statements,
-readability-uppercase-literal-suffix'
-readability-uppercase-literal-suffix,
-misc-include-cleaner'

CheckOptions:
- key: readability-identifier-naming.TypedefCase
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/install/cmake/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ runs:
steps:
- name: Cache CMake
id: cache-cmake
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: cmake-${{ inputs.version }}
key: ${{ runner.name }}-${{ runner.os }}-${{ runner.arch }}-${{ job.container.id }}-cmake-${{ inputs.version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
cmake --build .

min-req:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install/cmake
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
linter_name: clang-format

cmake-format:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
Expand All @@ -48,9 +48,8 @@ jobs:
linter_name: cmake-format

clang-tidy:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- run: sudo apt-get install clang-tidy
- uses: lukka/get-cmake@latest
- uses: actions/checkout@v4
- name: configure
Expand Down Expand Up @@ -118,7 +117,7 @@ jobs:
linter_name: render-tests

line-ending:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: git add --renormalize .
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ A simple example is decoding a token and printing all of its [claims](https://to
#include <iostream>

int main() {
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCIsInNhbXBsZSI6InRlc3QifQ.lQm3N2bVlqt2-1L-FsOjtR6uE-L4E9zJutMWKIe1v1M";
std::string const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCIsInNhbXBsZSI6InRlc3QifQ.lQm3N2bVlqt2-1L-FsOjtR6uE-L4E9zJutMWKIe1v1M";
auto decoded = jwt::decode(token);

for(auto& e : decoded.get_payload_json())
std::cout << e.first << " = " << e.second << std::endl;
std::cout << e.first << " = " << e.second << '\n';
}
```

Expand Down
6 changes: 3 additions & 3 deletions example/es256k.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ K9EDZi0mZ7VUeeNKq476CU5X940yusahgneePQrDMF2nWFEtBCOiXQ==
.set_payload_claim("sample", jwt::claim(std::string{"test"}))
.sign(jwt::algorithm::es256k(es256k_pub_key, es256k_priv_key, "", ""));

std::cout << "token:\n" << token << std::endl;
std::cout << "token:\n" << token << '\n';

auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::es256k(es256k_pub_key, es256k_priv_key, "", ""))
Expand All @@ -35,7 +35,7 @@ K9EDZi0mZ7VUeeNKq476CU5X940yusahgneePQrDMF2nWFEtBCOiXQ==
verify.verify(decoded);

for (auto& e : decoded.get_header_json())
std::cout << e.first << " = " << e.second << std::endl;
std::cout << e.first << " = " << e.second << '\n';
for (auto& e : decoded.get_payload_json())
std::cout << e.first << " = " << e.second << std::endl;
std::cout << e.first << " = " << e.second << '\n';
}
4 changes: 2 additions & 2 deletions example/jwks-verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ ARS9Ln8Wh5RsFuw/Y7Grg8FsoAVzV/Pns4cwjZG75ezXfk4UVpr4oO4B5jzazzCR
auto x5c = jwk.get_x5c_key_value();

if (!x5c.empty() && !issuer.empty()) {
std::cout << "Verifying with 'x5c' key" << std::endl;
std::cout << "Verifying with 'x5c' key" << '\n';
auto verifier =
jwt::verify()
.allow_algorithm(jwt::algorithm::rs256(jwt::helper::convert_base64_der_to_pem(x5c), "", "", ""))
Expand All @@ -123,7 +123,7 @@ ARS9Ln8Wh5RsFuw/Y7Grg8FsoAVzV/Pns4cwjZG75ezXfk4UVpr4oO4B5jzazzCR
}
// else if the optional 'x5c' was not present
{
std::cout << "Verifying with RSA components" << std::endl;
std::cout << "Verifying with RSA components" << '\n';
const auto modulus = jwk.get_jwk_claim("n").as_string();
const auto exponent = jwk.get_jwk_claim("e").as_string();
auto verifier = jwt::verify()
Expand Down
14 changes: 7 additions & 7 deletions example/partial-claim-verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <iostream>

int main() {
std::string rsa_priv_key = R"(-----BEGIN PRIVATE KEY-----
std::string const rsa_priv_key = R"(-----BEGIN PRIVATE KEY-----
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC4ZtdaIrd1BPIJ
tfnF0TjIK5inQAXZ3XlCrUlJdP+XHwIRxdv1FsN12XyMYO/6ymLmo9ryoQeIrsXB
XYqlET3zfAY+diwCb0HEsVvhisthwMU4gZQu6TYW2s9LnXZB5rVtcBK69hcSlA2k
Expand Down Expand Up @@ -44,9 +44,9 @@ rK0/Ikt5ybqUzKCMJZg2VKGTxg==
.set_payload_claim("resource-access", role_claim)
.sign(jwt::algorithm::rs256("", rsa_priv_key, "", ""));

std::cout << "token: " << token << std::endl;
std::cout << "token: " << token << '\n';

std::string rsa_pub_key = R"(-----BEGIN PUBLIC KEY-----
std::string const rsa_pub_key = R"(-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuGbXWiK3dQTyCbX5xdE4
yCuYp0AF2d15Qq1JSXT/lx8CEcXb9RbDddl8jGDv+spi5qPa8qEHiK7FwV2KpRE9
83wGPnYsAm9BxLFb4YrLYcDFOIGULuk2FtrPS512Qea1bXASuvYXEpQNpGbnTGVs
Expand All @@ -59,9 +59,9 @@ YwIDAQAB
auto decoded = jwt::decode(token);

for (const auto& e : decoded.get_payload_json())
std::cout << e.first << " = " << e.second << std::endl;
std::cout << e.first << " = " << e.second << '\n';

std::cout << std::endl;
std::cout << '\n';

auto role_verifier = [](const jwt::verify_context& ctx, std::error_code& ec) {
using error = jwt::error::token_verification_error;
Expand All @@ -88,8 +88,8 @@ YwIDAQAB

try {
verifier.verify(decoded);
std::cout << "Success!" << std::endl;
} catch (const std::exception& ex) { std::cout << "Error: " << ex.what() << std::endl; }
std::cout << "Success!" << '\n';
} catch (const std::exception& ex) { std::cout << "Error: " << ex.what() << '\n'; }

return 0;
}
7 changes: 4 additions & 3 deletions example/print-claims.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
#include <jwt-cpp/jwt.h>

int main() {
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCIsInNhbXBsZSI6InRlc3QifQ.lQm3N2bVlqt2-"
"1L-FsOjtR6uE-L4E9zJutMWKIe1v1M";
const std::string token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCIsInNhbXBsZSI6InRlc3QifQ.lQm3N2bVlqt2-"
"1L-FsOjtR6uE-L4E9zJutMWKIe1v1M";
auto decoded = jwt::decode(token);

for (auto& e : decoded.get_payload_json())
std::cout << e.first << " = " << e.second << std::endl;
std::cout << e.first << " = " << e.second << '\n';
}
2 changes: 1 addition & 1 deletion example/private-claims.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main() {
const auto decoded = jwt::decode(token);

const auto api_array = decoded.get_payload_claim("object").to_json().get("api").get("array");
std::cout << "api array = " << api_array << std::endl;
std::cout << "api array = " << api_array << '\n';

/* [verify exact claim] */
jwt::verify()
Expand Down
4 changes: 2 additions & 2 deletions example/rsa-create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <jwt-cpp/jwt.h>

int main() {
std::string rsa_priv_key = R"(-----BEGIN PRIVATE KEY-----
std::string const rsa_priv_key = R"(-----BEGIN PRIVATE KEY-----
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC4ZtdaIrd1BPIJ
tfnF0TjIK5inQAXZ3XlCrUlJdP+XHwIRxdv1FsN12XyMYO/6ymLmo9ryoQeIrsXB
XYqlET3zfAY+diwCb0HEsVvhisthwMU4gZQu6TYW2s9LnXZB5rVtcBK69hcSlA2k
Expand Down Expand Up @@ -41,5 +41,5 @@ rK0/Ikt5ybqUzKCMJZg2VKGTxg==
.set_payload_claim("sample", jwt::claim(std::string{"test"}))
.sign(jwt::algorithm::rs256("", rsa_priv_key, "", ""));

std::cout << "token:\n" << token << std::endl;
std::cout << "token:\n" << token << '\n';
}
22 changes: 11 additions & 11 deletions example/rsa-verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <jwt-cpp/jwt.h>

int main() {
std::string rsa_pub_key = R"(-----BEGIN PUBLIC KEY-----
const std::string rsa_pub_key = R"(-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuGbXWiK3dQTyCbX5xdE4
yCuYp0AF2d15Qq1JSXT/lx8CEcXb9RbDddl8jGDv+spi5qPa8qEHiK7FwV2KpRE9
83wGPnYsAm9BxLFb4YrLYcDFOIGULuk2FtrPS512Qea1bXASuvYXEpQNpGbnTGVs
Expand All @@ -13,14 +13,14 @@ AziMCxS+VrRPDM+zfvpIJg3JljAh3PJHDiLu902v9w+Iplu1WyoB2aPfitxEhRN0
YwIDAQAB
-----END PUBLIC KEY-----)";

std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9."
"VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-"
"GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-"
"IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-"
"uc2z5c05CCXqVSpfCjWbh9gQ";
const std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9."
"VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-"
"GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-"
"IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-"
"uc2z5c05CCXqVSpfCjWbh9gQ";

/* [allow rsa algorithm] */
auto verify = jwt::verify()
Expand All @@ -35,7 +35,7 @@ YwIDAQAB
verify.verify(decoded);

for (auto& e : decoded.get_header_json())
std::cout << e.first << " = " << e.second << std::endl;
std::cout << e.first << " = " << e.second << '\n';
for (auto& e : decoded.get_payload_json())
std::cout << e.first << " = " << e.second << std::endl;
std::cout << e.first << " = " << e.second << '\n';
}
4 changes: 2 additions & 2 deletions example/traits/boost-json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ int main() {
const auto decoded = jwt::decode<traits>(token);

for (auto& e : decoded.get_header_json())
std::cout << e.key() << " = " << e.value() << std::endl;
std::cout << e.key() << " = " << e.value() << '\n';

const auto array =
traits::as_array(decoded.get_payload_claim("object").to_json().as_object()["api"].as_object()["array"]);
std::cout << "payload /object/api/array = " << array << std::endl;
std::cout << "payload /object/api/array = " << array << '\n';

jwt::verify<traits>()
.allow_algorithm(jwt::algorithm::none{})
Expand Down
2 changes: 1 addition & 1 deletion example/traits/danielaparker-jsoncons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main() {
const auto decoded = jwt::decode<traits>(token);

const auto array = traits::as_array(decoded.get_payload_claim("object").to_json()["api"]["array"]);
std::cout << "payload /object/api/array = " << jsoncons::pretty_print(traits::json(array)) << std::endl;
std::cout << "payload /object/api/array = " << jsoncons::pretty_print(traits::json(array)) << '\n';

jwt::verify<traits>()
.allow_algorithm(jwt::algorithm::none{})
Expand Down
2 changes: 1 addition & 1 deletion example/traits/kazuho-picojson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main() {
const auto decoded = jwt::decode<traits>(token);

const auto api_array = decoded.get_payload_claim("object").to_json().get("api").get("array");
std::cout << "api array = " << api_array << std::endl;
std::cout << "api array = " << api_array << '\n';

jwt::verify<traits>()
.allow_algorithm(jwt::algorithm::none{})
Expand Down
2 changes: 1 addition & 1 deletion example/traits/nlohmann-json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main() {
const auto decoded = jwt::decode<traits>(token);

const auto array = traits::as_array(decoded.get_payload_claim("object").to_json()["api"]["array"]);
std::cout << "payload /object/api/array = " << array << std::endl;
std::cout << "payload /object/api/array = " << array << '\n';

jwt::verify<traits>()
.allow_algorithm(jwt::algorithm::none{})
Expand Down
2 changes: 1 addition & 1 deletion example/traits/open-source-parsers-jsoncpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main() {
const auto decoded = jwt::decode<traits>(token);

const auto array = traits::as_array(decoded.get_payload_claim("object").to_json()["api"]["array"]);
std::cout << "payload /object/api/array = " << array << std::endl;
std::cout << "payload /object/api/array = " << array << '\n';

jwt::verify<traits>()
.allow_algorithm(jwt::algorithm::none{})
Expand Down
2 changes: 1 addition & 1 deletion include/jwt-cpp/jwt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1819,7 +1819,7 @@ namespace jwt {
ERR_clear_error();
if (EVP_DigestSignUpdate(ctx.get(), reinterpret_cast<const unsigned char*>(data.data()), data.size()) !=
1) {
std::cout << ERR_error_string(ERR_get_error(), NULL) << std::endl;
std::cout << ERR_error_string(ERR_get_error(), NULL) << '\n';
ec = error::signature_generation_error::signupdate_failed;
return {};
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ClaimTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <gtest/gtest.h>

TEST(ClaimTest, AudienceAsString) {
std::string token =
std::string const token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0.WZnM3SIiSRHsbO3O7Z2bmIzTJ4EC32HRBKfLznHhrh4";
auto decoded = jwt::decode(token);

Expand Down Expand Up @@ -32,7 +32,7 @@ TEST(ClaimTest, SetAudienceAsString) {
}

TEST(ClaimTest, AudienceAsSet) {
std::string token = "eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJhdWQiOlsidGVzdCIsInRlc3QyIl19.";
std::string const token = "eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJhdWQiOlsidGVzdCIsInRlc3QyIl19.";
auto decoded = jwt::decode(token);

ASSERT_TRUE(decoded.has_algorithm());
Expand Down
2 changes: 1 addition & 1 deletion tests/OpenSSLErrorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ TEST(OpenSSLErrorTest, LoadPrivateKeyFromStringErrorCode) {

#if !defined(LIBWOLFSSL_VERSION_HEX) || LIBWOLFSSL_VERSION_HEX > 0x05007000
TEST(OpenSSLErrorTest, HMACSign) {
std::string token =
std::string const token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";

auto verify = jwt::verify().allow_algorithm(jwt::algorithm::hs256{"secret"}).with_issuer("auth0");
Expand Down
2 changes: 1 addition & 1 deletion tests/TokenFormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TEST(TokenFormatTest, InvalidJSON) {
#include "jwt-cpp/traits/nlohmann-json/traits.h"

TEST(TokenFormatTest, GitHubIssue341) {
std::string token =
std::string const token =
"eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJjYXV0aDAiLCJleHAiOjE3MTMzODgxNjgsInN1YiI6InRlc3RfdXNlciJ9."
"dlAk0mSWk1Clzfi1PMq7Omxun3EyEqh-AAu-fTkpabA67ZKenawAQhZO8glY93flukpJCqHLVtukaes6ZSOjGw";
auto decoded = jwt::decoded_jwt<jwt::traits::nlohmann_json>(token);
Expand Down
Loading