From: Vsevolod Stakhov Date: Sat, 2 Jun 2018 20:40:32 +0000 (+0100) Subject: [Minor] Add some missing methods X-Git-Tag: 1.7.6~64 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=32270a9bd1a69e3788e83d1df4d38bc684c6b488;p=rspamd.git [Minor] Add some missing methods --- diff --git a/src/lua/lua_cryptobox.c b/src/lua/lua_cryptobox.c index a052f9a3b..fa6a35155 100644 --- a/src/lua/lua_cryptobox.c +++ b/src/lua/lua_cryptobox.c @@ -42,6 +42,7 @@ LUA_FUNCTION_DEF (cryptobox_pubkey, gc); LUA_FUNCTION_DEF (cryptobox_keypair, load); LUA_FUNCTION_DEF (cryptobox_keypair, create); LUA_FUNCTION_DEF (cryptobox_keypair, gc); +LUA_FUNCTION_DEF (cryptobox_keypair, totable); LUA_FUNCTION_DEF (cryptobox_signature, create); LUA_FUNCTION_DEF (cryptobox_signature, load); LUA_FUNCTION_DEF (cryptobox_signature, save); @@ -101,6 +102,7 @@ static const struct luaL_reg cryptoboxkeypairlib_f[] = { static const struct luaL_reg cryptoboxkeypairlib_m[] = { {"__tostring", rspamd_lua_class_tostring}, + {"totable", lua_cryptobox_keypair_totable}, {"__gc", lua_cryptobox_keypair_gc}, {NULL, NULL} }; @@ -459,6 +461,36 @@ lua_cryptobox_keypair_gc (lua_State *L) return 0; } +/*** + * @method keypair:totable([hex=false]]) + * Converts keypair to table (not very safe due to memory leftovers) + */ +static gint +lua_cryptobox_keypair_totable (lua_State *L) +{ + struct rspamd_cryptobox_keypair *kp = lua_check_cryptobox_keypair (L, 1); + ucl_object_t *obj; + gboolean hex = FALSE; + gint ret = 1; + + if (kp != NULL) { + + if (lua_isboolean (L, 2)) { + hex = lua_toboolean (L, 2); + } + + obj = rspamd_keypair_to_ucl (kp, hex); + + ret = ucl_object_push_lua (L, obj, true); + ucl_object_unref (obj); + } + else { + return luaL_error (L, "invalid arguments"); + } + + return ret; +} + /*** * @function rspamd_cryptobox_signature.load(file) * Loads signature from raw file