diff --git a/README.md b/README.md index f153a58..4e5598e 100644 --- a/README.md +++ b/README.md @@ -25,15 +25,25 @@ * libssl-dev (for the header files) ## API +## Globals +### Algorithm +* `JWT_ALGORITHM_HS256` +* `JWT_ALGORITHM_HS384` +* `JWT_ALGORITHM_HS512` +* `JWT_ALGORITHM_RS256` +* `JWT_ALGORITHM_RS384` +* `JWT_ALGORITHM_RS512` + +## Functions ### Function: `jwtSign` ```cpp -bool jwtSign(function(string/boolean) callback, table claims, string algorithm, string secret/public_key_path, string private_key_path) +bool jwtSign(function(string/boolean) callback, table claims, JWT_ALGORITHM algorithm, string secret/private_key_path, bool is_file_path = false) ``` * __callback:__ Lorem ipsum * __claims:__ Lorem ipsum * __algorithm:__ Lorem ipsum -* __secret/public_key_path__ Lorem ipsum -* __private_key_path__ Lorem ipsum +* __secret/private_key_path__ Lorem ipsum +* __is_file_path__ Lorem ipsum Returns __true__ if everything went fine, __false__ otherwise. diff --git a/module/CFunctions.cpp b/module/CFunctions.cpp index 9025526..efd5f6d 100644 --- a/module/CFunctions.cpp +++ b/module/CFunctions.cpp @@ -60,8 +60,16 @@ int CFunctions::sign_jwt_token(lua_State* lua_vm) { case JWT_ALGORITHM_HS256: return jwt.sign(jwt::algorithm::hs256{ private_key }); + case JWT_ALGORITHM_HS384: + return jwt.sign(jwt::algorithm::hs384{ private_key }); + case JWT_ALGORITHM_HS512: + return jwt.sign(jwt::algorithm::hs512{ private_key }); case JWT_ALGORITHM_RS256: return jwt.sign(jwt::algorithm::rs256{ "", private_key }); + case JWT_ALGORITHM_RS384: + return jwt.sign(jwt::algorithm::rs384{ "", private_key }); + case JWT_ALGORITHM_RS512: + return jwt.sign(jwt::algorithm::rs512{ "", private_key }); default: break; } @@ -158,8 +166,16 @@ int CFunctions::verify_jwt_token(lua_State* lua_vm) // set verifier algorithm if (std::strcmp(algorithm, "HS256") == 0) verifier.allow_algorithm(jwt::algorithm::hs256{ public_key }); - else if (std::strcmp(algorithm, "RS256") == 0) + if (std::strcmp(algorithm, "HS384") == 0) + verifier.allow_algorithm(jwt::algorithm::hs384{ public_key }); + if (std::strcmp(algorithm, "HS512") == 0) + verifier.allow_algorithm(jwt::algorithm::hs512{ public_key }); + if (std::strcmp(algorithm, "RS256") == 0) verifier.allow_algorithm(jwt::algorithm::rs256{ public_key }); + if (std::strcmp(algorithm, "RS384") == 0) + verifier.allow_algorithm(jwt::algorithm::rs384{ public_key }); + if (std::strcmp(algorithm, "RS512") == 0) + verifier.allow_algorithm(jwt::algorithm::rs512{ public_key }); verifier.verify(decoded_jwt);