Skip to content

Commit

Permalink
[skip ci] fixing clang warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
prince-chrismc committed May 30, 2020
1 parent 76aac93 commit 9f4a217
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
36 changes: 18 additions & 18 deletions include/jwt-cpp/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand All @@ -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;
}
};
Expand Down Expand Up @@ -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<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;

Expand All @@ -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<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;

Expand Down Expand Up @@ -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<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)
Expand All @@ -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<char>((triple >> 2 * 8) & 0xFFu);
res += static_cast<char>((triple >> 1 * 8) & 0xFFu);
break;
case 2:
res += (triple >> 2 * 8) & 0xFF;
res += static_cast<char>((triple >> 2 * 8) & 0xFFu);
break;
default:
break;
Expand Down
43 changes: 21 additions & 22 deletions include/jwt-cpp/jwt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -768,7 +768,7 @@ namespace jwt {
number,
string,
array,
object,
object
};
}

Expand Down Expand Up @@ -1370,25 +1370,24 @@ namespace jwt {
/**
* Constructor
* Parses a given token
* Decodes using the jwt::base64url which supports an std::string
* \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
*/
decoded_jwt(const string_type& token)
: decoded_jwt(token, [](const string_type& token){
return base::decode<alphabet::base64url>(base::pad<alphabet::base64url>(token));
})
{}
/**
* Constructor
* Parses a given token
* Decodes using the jwt::base64url which supports an std::string
* \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
*/
decoded_jwt(const string_type& token)
: decoded_jwt(token, [](const string_type& token){
return base::decode<alphabet::base64url>(base::pad<alphabet::base64url>(token));
})
{}

template<typename Decode>
decoded_jwt(const string_type& token, Decode decode)
: token(token)
Expand Down Expand Up @@ -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)); }
Expand Down
3 changes: 2 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ add_executable(jwt-cpp-test ${TEST_SOURCES})
target_compile_options(jwt-cpp-test PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4>
$<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra -Wpedantic>
$<$<CXX_COMPILER_ID:Clang>:-Weverything>)
$<$<CXX_COMPILER_ID:Clang>:-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)

0 comments on commit 9f4a217

Please sign in to comment.