Skip to content

Commit

Permalink
Added some comments for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kürzeder committed Jul 23, 2019
1 parent d94947c commit f58d55a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
## API
### Function: `jwtSign`
```cpp
string jwtSign(function(string/boolean) callback, table claims, string algorithm, string secret)
bool jwtSign(function(string/boolean) callback, table claims, string algorithm, string secret)
```
* __callback:__ Lorem ipsum
* __claims:__ Lorem ipsum
* __algorithm:__ Lorem ipsum
* __secret__ Lorem ipsum
Returns the __jwt token__ if everything went fine, __false__ otherwise.
Returns the __true__ if everything went fine, __false__ otherwise.
### Function: `jwtVerify`
```cpp
Expand Down
8 changes: 7 additions & 1 deletion module/CFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ int CFunctions::sign_jwt_token(lua_State* lua_vm)
const auto public_key_path = lua_tostring(lua_vm, 4);
const auto private_key_path = lua_tostring(lua_vm, 5);

// Read public- and private key from files
std::string public_key = public_key_path, private_key;
if (lua_type(lua_vm, 5) != LUA_TNONE)
{
Expand All @@ -45,6 +46,7 @@ int CFunctions::sign_jwt_token(lua_State* lua_vm)
}
}

// Process signing
g_Module->GetJobManager().PushTask([/* lua_vm, */ claims, algorithm, public_key, private_key]()
{
const auto& now = std::chrono::system_clock::now();
Expand Down Expand Up @@ -110,12 +112,13 @@ int CFunctions::verify_jwt_token(lua_State* lua_vm)
return 1;
}


// Read arguments
const auto token = lua_tostring(lua_vm, 1);
const auto algorithm = lua_tostring(lua_vm, 2);
const auto public_key_path = lua_tostring(lua_vm, 3);
const auto private_key_path = lua_tostring(lua_vm, 4);

// Read public- and private key from files
std::string public_key = public_key_path, private_key;
if (lua_type(lua_vm, 4) != LUA_TNONE)
{
Expand All @@ -128,6 +131,7 @@ int CFunctions::verify_jwt_token(lua_State* lua_vm)
}
}

// Process verification
try {
const auto decoded_jwt = jwt::decode(token);
auto verifier = jwt::verify();
Expand Down Expand Up @@ -166,8 +170,10 @@ int CFunctions::get_jwt_claims(lua_State* lua_vm)
return 1;
}

// Read arguments
const auto token = lua_tostring(lua_vm, 1);

// Process get claims
try
{
const auto decoded_jwt = jwt::decode(token);
Expand Down

0 comments on commit f58d55a

Please sign in to comment.