diff --git a/include/jwt-cpp/base.h b/include/jwt-cpp/base.h index 0d1c4a5..5312639 100644 --- a/include/jwt-cpp/base.h +++ b/include/jwt-cpp/base.h @@ -22,9 +22,9 @@ namespace jwt { '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() { + static constexpr auto fill = "="; return fill; } }; @@ -36,9 +36,9 @@ namespace jwt { '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() { + static constexpr auto fill = "%3d"; return fill; } }; @@ -71,9 +71,9 @@ namespace jwt { // 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(bin[i++]); + uint32_t octet_b = static_cast(bin[i++]); + uint32_t octet_c = static_cast(bin[i++]); uint32_t triple = (octet_a << 0x10) + (octet_b << 0x08) + octet_c; @@ -88,9 +88,9 @@ namespace jwt { 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(bin[fast_size++]) : 0; + uint32_t octet_b = fast_size < size ? static_cast(bin[fast_size++]) : 0; + uint32_t octet_c = fast_size < size ? static_cast(bin[fast_size++]) : 0; uint32_t triple = (octet_a << 0x10) + (octet_b << 0x08) + octet_c; @@ -155,9 +155,9 @@ namespace jwt { + (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((triple >> 2 * 8) & 0xFFu); + res += static_cast((triple >> 1 * 8) & 0xFFu); + res += static_cast((triple >> 0 * 8) & 0xFFu); } if (fill_cnt == 0) @@ -169,11 +169,11 @@ namespace jwt { switch (fill_cnt) { case 1: triple |= (get_sextet(fast_size + 2) << 1 * 6); - res += (triple >> 2 * 8) & 0xFF; - res += (triple >> 1 * 8) & 0xFF; + res += static_cast((triple >> 2 * 8) & 0xFFu); + res += static_cast((triple >> 1 * 8) & 0xFFu); break; case 2: - res += (triple >> 2 * 8) & 0xFF; + res += static_cast((triple >> 2 * 8) & 0xFFu); break; default: break; diff --git a/include/jwt-cpp/jwt.h b/include/jwt-cpp/jwt.h index 54e8b81..69dfa7b 100644 --- a/include/jwt-cpp/jwt.h +++ b/include/jwt-cpp/jwt.h @@ -248,7 +248,7 @@ namespace jwt { * \param public_key RSA public key in PEM format * \param private_key RSA private key or empty string if not available. If empty, signing will always fail. * \param public_key_password Password to decrypt public key pem. - * \param privat_key_password Password to decrypt private key pem. + * \param private_key_password Password to decrypt private key pem. * \param md Pointer to hash function * \param name Name of the algorithm */ @@ -337,7 +337,7 @@ namespace jwt { * \param public_key ECDSA public key in PEM format * \param private_key ECDSA private key or empty string if not available. If empty, signing will always fail. * \param public_key_password Password to decrypt public key pem. - * \param privat_key_password Password to decrypt private key pem. + * \param private_key_password Password to decrypt private key pem. * \param md Pointer to hash function * \param name Name of the algorithm */ @@ -492,7 +492,7 @@ namespace jwt { * \param public_key RSA public key in PEM format * \param private_key RSA private key or empty string if not available. If empty, signing will always fail. * \param public_key_password Password to decrypt public key pem. - * \param privat_key_password Password to decrypt private key pem. + * \param private_key_password Password to decrypt private key pem. * \param md Pointer to hash function * \param name Name of the algorithm */ @@ -631,7 +631,7 @@ namespace jwt { * \param public_key RSA public key in PEM format * \param private_key RSA private key or empty string if not available. If empty, signing will always fail. * \param public_key_password Password to decrypt public key pem. - * \param privat_key_password Password to decrypt private key pem. + * \param private_key_password Password to decrypt private key pem. */ explicit rs256(const std::string& public_key, const std::string& private_key = "", const std::string& public_key_password = "", const std::string& private_key_password = "") : rsa(public_key, private_key, public_key_password, private_key_password, EVP_sha256, "RS256") @@ -646,7 +646,7 @@ namespace jwt { * \param public_key RSA public key in PEM format * \param private_key RSA private key or empty string if not available. If empty, signing will always fail. * \param public_key_password Password to decrypt public key pem. - * \param privat_key_password Password to decrypt private key pem. + * \param private_key_password Password to decrypt private key pem. */ explicit rs384(const std::string& public_key, const std::string& private_key = "", const std::string& public_key_password = "", const std::string& private_key_password = "") : rsa(public_key, private_key, public_key_password, private_key_password, EVP_sha384, "RS384") @@ -661,7 +661,7 @@ namespace jwt { * \param public_key RSA public key in PEM format * \param private_key RSA private key or empty string if not available. If empty, signing will always fail. * \param public_key_password Password to decrypt public key pem. - * \param privat_key_password Password to decrypt private key pem. + * \param private_key_password Password to decrypt private key pem. */ explicit rs512(const std::string& public_key, const std::string& private_key = "", const std::string& public_key_password = "", const std::string& private_key_password = "") : rsa(public_key, private_key, public_key_password, private_key_password, EVP_sha512, "RS512") @@ -676,7 +676,7 @@ namespace jwt { * \param public_key ECDSA public key in PEM format * \param private_key ECDSA private key or empty string if not available. If empty, signing will always fail. * \param public_key_password Password to decrypt public key pem. - * \param privat_key_password Password to decrypt private key pem. + * \param private_key_password Password to decrypt private key pem. */ explicit es256(const std::string& public_key, const std::string& private_key = "", const std::string& public_key_password = "", const std::string& private_key_password = "") : ecdsa(public_key, private_key, public_key_password, private_key_password, EVP_sha256, "ES256", 64) @@ -691,7 +691,7 @@ namespace jwt { * \param public_key ECDSA public key in PEM format * \param private_key ECDSA private key or empty string if not available. If empty, signing will always fail. * \param public_key_password Password to decrypt public key pem. - * \param privat_key_password Password to decrypt private key pem. + * \param private_key_password Password to decrypt private key pem. */ explicit es384(const std::string& public_key, const std::string& private_key = "", const std::string& public_key_password = "", const std::string& private_key_password = "") : ecdsa(public_key, private_key, public_key_password, private_key_password, EVP_sha384, "ES384", 96) @@ -706,7 +706,7 @@ namespace jwt { * \param public_key ECDSA public key in PEM format * \param private_key ECDSA private key or empty string if not available. If empty, signing will always fail. * \param public_key_password Password to decrypt public key pem. - * \param privat_key_password Password to decrypt private key pem. + * \param private_key_password Password to decrypt private key pem. */ explicit es512(const std::string& public_key, const std::string& private_key = "", const std::string& public_key_password = "", const std::string& private_key_password = "") : ecdsa(public_key, private_key, public_key_password, private_key_password, EVP_sha512, "ES512", 132) @@ -722,7 +722,7 @@ namespace jwt { * \param public_key RSA public key in PEM format * \param private_key RSA private key or empty string if not available. If empty, signing will always fail. * \param public_key_password Password to decrypt public key pem. - * \param privat_key_password Password to decrypt private key pem. + * \param private_key_password Password to decrypt private key pem. */ explicit ps256(const std::string& public_key, const std::string& private_key = "", const std::string& public_key_password = "", const std::string& private_key_password = "") : pss(public_key, private_key, public_key_password, private_key_password, EVP_sha256, "PS256") @@ -737,7 +737,7 @@ namespace jwt { * \param public_key RSA public key in PEM format * \param private_key RSA private key or empty string if not available. If empty, signing will always fail. * \param public_key_password Password to decrypt public key pem. - * \param privat_key_password Password to decrypt private key pem. + * \param private_key_password Password to decrypt private key pem. */ explicit ps384(const std::string& public_key, const std::string& private_key = "", const std::string& public_key_password = "", const std::string& private_key_password = "") : pss(public_key, private_key, public_key_password, private_key_password, EVP_sha384, "PS384") @@ -752,7 +752,7 @@ namespace jwt { * \param public_key RSA public key in PEM format * \param private_key RSA private key or empty string if not available. If empty, signing will always fail. * \param public_key_password Password to decrypt public key pem. - * \param privat_key_password Password to decrypt private key pem. + * \param private_key_password Password to decrypt private key pem. */ explicit ps512(const std::string& public_key, const std::string& private_key = "", const std::string& public_key_password = "", const std::string& private_key_password = "") : pss(public_key, private_key, public_key_password, private_key_password, EVP_sha512, "PS512") @@ -768,7 +768,7 @@ namespace jwt { number, string, array, - object, + object }; } @@ -1367,14 +1367,6 @@ namespace jwt { /// Unmodified signature part in base64 string_type signature_base64; public: - /** - * Constructor - * Parses a given token - * \param token The token to parse - * \param decode The token to parse - * \throws std::invalid_argument Token is not in correct format - * \throws std::runtime_error Base64 decoding failed or invalid json - */ /** * Constructor * Parses a given token @@ -1388,7 +1380,14 @@ namespace jwt { return base::decode(base::pad(token)); }) {} - + /** + * Constructor + * Parses a given token + * \param token The token to parse + * \param decode The token to parse + * \throws std::invalid_argument Token is not in correct format + * \throws std::runtime_error Base64 decoding failed or invalid json + */ template decoded_jwt(const string_type& token, Decode decode) : token(token) @@ -1542,7 +1541,7 @@ namespace jwt { builder& set_subject(string_type str) { return set_payload_claim("sub", value_type(str)); } /** * Set audience claim - * \param l Audience set + * \param a Audience set * \return *this to allow for method chaining */ builder& set_audience(array_type a) { return set_payload_claim("aud", value_type(a)); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f5f33f9..d7660e6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,7 +16,8 @@ add_executable(jwt-cpp-test ${TEST_SOURCES}) target_compile_options(jwt-cpp-test PRIVATE $<$:/W4> $<$:-Wall -Wextra -Wpedantic> - $<$:-Weverything>) + $<$:-Weverything -Wno-c++98-compat -Wno-global-constructors + -Wno-weak-vtables>) target_link_libraries(jwt-cpp-test PRIVATE jwt-cpp::jwt-cpp GTest::GTest GTest::Main pthread) gtest_add_tests(TARGET jwt-cpp-test)