1
0

Extend API and add get_secret_key for secure operations (#84)

Co-authored-by: luk3yx <luk3yx@users.noreply.github.com>
This commit is contained in:
Bektur 2022-10-29 16:31:21 +06:00 committed by GitHub
parent e9157515b9
commit 3ecb0895aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 1 deletions

View File

@ -220,6 +220,10 @@ class GameActivity : SDLActivity() {
fun upgrade(item: String) {
}
fun getSecretKey(key: String): String {
return "Stub"
}
@Suppress("unused")
fun getRoundScreen(): Int {
return radius

View File

@ -392,7 +392,7 @@ jstring getJniString(const std::string &message)
void upgrade(const std::string &item)
{
jmethodID upgradeGame = jnienv->GetMethodID(activityClass,
"upgrade","(Ljava/lang/String;)V");
"upgrade", "(Ljava/lang/String;)V");
FATAL_ERROR_IF(upgradeGame == nullptr,
"porting::upgradeGame unable to find java upgrade method");
@ -418,4 +418,18 @@ int getRoundScreen()
}
return radius;
}
std::string getSecretKey(const std::string &key)
{
jmethodID getKey = jnienv->GetMethodID(activityClass,
"getSecretKey", "(Ljava/lang/String;)Ljava/lang/String;");
FATAL_ERROR_IF(getKey == nullptr,
"porting::getSecretKey unable to find java getSecretKey method");
jstring jkey = jnienv->NewStringUTF(key.c_str());
auto result = (jstring) jnienv->CallObjectMethod(activityObj, getKey, jkey);
return javaStringToUTF8(result);
}
}

View File

@ -113,4 +113,9 @@ void upgrade(const std::string &item);
* get radius of rounded corners
*/
int getRoundScreen();
/**
* get encrypted key for further actions
*/
std::string getSecretKey(const std::string &key);
}

View File

@ -501,6 +501,21 @@ int ModApiUtil::l_upgrade(lua_State *L)
return 1;
}
int ModApiUtil::l_get_secret_key(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
#if defined(__ANDROID__) || defined(__IOS__)
const std::string secret_name = luaL_checkstring(L, 1);
const std::string res = porting::getSecretKey(secret_name);
lua_pushlstring(L, res.c_str(), res.size());
#else
// Not implemented on desktop platforms
lua_pushstring(L, "");
#endif
return 1;
}
void ModApiUtil::Initialize(lua_State *L, int top)
{
API_FCT(log);
@ -597,4 +612,5 @@ void ModApiUtil::InitializeAsync(lua_State *L, int top)
void ModApiUtil::InitializeMainMenu(lua_State *L, int top) {
Initialize(L, top);
API_FCT(upgrade);
API_FCT(get_secret_key);
}

View File

@ -104,6 +104,9 @@ private:
// upgrade(string)
static int l_upgrade(lua_State *L);
// get_secret_key(string)
static int l_get_secret_key(lua_State *L);
public:
static void Initialize(lua_State *L, int top);
static void InitializeAsync(lua_State *L, int top);