Skip to content

Commit

Permalink
Small improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kürzeder committed Jul 26, 2019
1 parent 4333606 commit 46b3054
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
8 changes: 4 additions & 4 deletions module/CFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned>(lua_touserdata(lua_vm, 3)));
const auto algorithm = jwt_algorithm(reinterpret_cast<uint32_t>(lua_touserdata(lua_vm, 3)));
const auto private_key_path = lua_tostring(lua_vm, 4);
std::string private_key = private_key_path;

Expand Down Expand Up @@ -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;
Expand Down
15 changes: 8 additions & 7 deletions module/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 46b3054

Please sign in to comment.