From f58d55a2db32a10aa9c5bb3c7c32c8717b786847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=BCrzeder?= Date: Tue, 23 Jul 2019 11:18:52 +0200 Subject: [PATCH] Added some comments for readability --- README.md | 4 ++-- module/CFunctions.cpp | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f30e82a..a654baa 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/module/CFunctions.cpp b/module/CFunctions.cpp index 7030ef3..6cf456f 100644 --- a/module/CFunctions.cpp +++ b/module/CFunctions.cpp @@ -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) { @@ -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(); @@ -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) { @@ -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(); @@ -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);