diff --git a/module/CFunctions.cpp b/module/CFunctions.cpp index 5700e87..ce950c7 100644 --- a/module/CFunctions.cpp +++ b/module/CFunctions.cpp @@ -29,7 +29,7 @@ int CFunctions::sign_jwt_token(lua_State* lua_vm) // Read other arguments const auto claims = Utils::parse_named_table(lua_vm, 2); - const auto algorithm = jwt_algorithm(reinterpret_cast(lua_touserdata(lua_vm, 3))); + const auto algorithm = jwt_algorithm(reinterpret_cast(lua_touserdata(lua_vm, 3))); const auto private_key_path = lua_tostring(lua_vm, 4); std::string private_key = private_key_path; @@ -70,12 +70,12 @@ int CFunctions::sign_jwt_token(lua_State* lua_vm) return jwt.sign(jwt::algorithm::rs384{ std::string(), private_key }); case jwt_algorithm_rs512: return jwt.sign(jwt::algorithm::rs512{ std::string(), private_key }); + case jwt_algorithm_none: default: - break; + pModuleManager->ErrorPrintf("Error @ jwtSign, invalid algorithm has been passed.\n"); + return {}; } - pModuleManager->ErrorPrintf("Error @ jwtSign, invalid algorithm has been passed.\n"); - return {}; } catch(exception& e) { std::stringstream ss; diff --git a/module/Utils.h b/module/Utils.h index dbe7d02..629b060 100644 --- a/module/Utils.h +++ b/module/Utils.h @@ -14,14 +14,15 @@ static const int index_key = -2; #define DEBUG_LOG( msg ) #endif -enum jwt_algorithm : unsigned +enum jwt_algorithm : uint32_t { - jwt_algorithm_hs256 = 0b1000000 << 0, - jwt_algorithm_hs384 = 0b1000000 << 1, - jwt_algorithm_hs512 = 0b1000000 << 2, - jwt_algorithm_rs256 = 0b1000000 << 3, - jwt_algorithm_rs384 = 0b1000000 << 4, - jwt_algorithm_rs512 = 0b1000000 << 5 + jwt_algorithm_none = 0x123456789ABCDEFui32, + jwt_algorithm_hs256 = jwt_algorithm_none << 1, + jwt_algorithm_hs384 = jwt_algorithm_none << 2, + jwt_algorithm_hs512 = jwt_algorithm_none << 3, + jwt_algorithm_rs256 = jwt_algorithm_none << 4, + jwt_algorithm_rs384 = jwt_algorithm_none << 5, + jwt_algorithm_rs512 = jwt_algorithm_none << 6 }; class Utils