@@ -1882,7 +1882,7 @@ rspamd_fuzzy_stat_to_ucl (struct rspamd_fuzzy_storage_ctx *ctx, gboolean ip_stat | |||
ucl_object_insert_key (elt, ip_elt, "ips", 0, false); | |||
} | |||
ucl_object_insert_key (elt, rspamd_keypair_to_ucl (fuzzy_key->key, FALSE), | |||
ucl_object_insert_key (elt, rspamd_keypair_to_ucl (fuzzy_key->key, RSPAMD_KEYPAIR_DUMP_NO_SECRET), | |||
"keypair", 0, false); | |||
ucl_object_insert_key (keys_obj, elt, keyname, 0, true); | |||
} |
@@ -787,7 +787,7 @@ rspamd_keypair_from_ucl (const ucl_object_t *obj) | |||
ucl_object_t * | |||
rspamd_keypair_to_ucl (struct rspamd_cryptobox_keypair *kp, | |||
gboolean is_hex) | |||
enum rspamd_keypair_dump_flags flags) | |||
{ | |||
ucl_object_t *ucl_out, *elt; | |||
gint how = 0; | |||
@@ -796,7 +796,7 @@ rspamd_keypair_to_ucl (struct rspamd_cryptobox_keypair *kp, | |||
g_assert (kp != NULL); | |||
if (is_hex) { | |||
if (flags & RSPAMD_KEYPAIR_DUMP_HEX) { | |||
how |= RSPAMD_KEYPAIR_HEX; | |||
encoding = "hex"; | |||
} | |||
@@ -817,13 +817,15 @@ rspamd_keypair_to_ucl (struct rspamd_cryptobox_keypair *kp, | |||
"pubkey", 0, false); | |||
g_string_free (keypair_out, TRUE); | |||
/* privkey part */ | |||
keypair_out = rspamd_keypair_print (kp, | |||
RSPAMD_KEYPAIR_PRIVKEY|how); | |||
ucl_object_insert_key (elt, | |||
ucl_object_fromlstring (keypair_out->str, keypair_out->len), | |||
if (!(flags & RSPAMD_KEYPAIR_DUMP_NO_SECRET)) { | |||
/* privkey part */ | |||
keypair_out = rspamd_keypair_print(kp, | |||
RSPAMD_KEYPAIR_PRIVKEY | how); | |||
ucl_object_insert_key(elt, | |||
ucl_object_fromlstring(keypair_out->str, keypair_out->len), | |||
"privkey", 0, false); | |||
g_string_free (keypair_out, TRUE); | |||
g_string_free(keypair_out, TRUE); | |||
} | |||
keypair_out = rspamd_keypair_print (kp, | |||
RSPAMD_KEYPAIR_ID|how); |
@@ -244,13 +244,20 @@ const guchar *rspamd_keypair_component (struct rspamd_cryptobox_keypair *kp, | |||
*/ | |||
struct rspamd_cryptobox_keypair *rspamd_keypair_from_ucl (const ucl_object_t *obj); | |||
enum rspamd_keypair_dump_flags { | |||
RSPAMD_KEYPAIR_DUMP_DEFAULT = 0, | |||
RSPAMD_KEYPAIR_DUMP_HEX = 1u << 0u, | |||
RSPAMD_KEYPAIR_DUMP_NO_SECRET = 1u << 1u, | |||
}; | |||
/** | |||
* Converts keypair to ucl object | |||
* @param kp | |||
* @return | |||
*/ | |||
ucl_object_t *rspamd_keypair_to_ucl (struct rspamd_cryptobox_keypair *kp, | |||
gboolean is_hex); | |||
enum rspamd_keypair_dump_flags flags); | |||
/** |
@@ -567,7 +567,7 @@ lua_cryptobox_keypair_totable (lua_State *L) | |||
hex = lua_toboolean (L, 2); | |||
} | |||
obj = rspamd_keypair_to_ucl (kp, hex); | |||
obj = rspamd_keypair_to_ucl (kp, hex ? RSPAMD_KEYPAIR_DUMP_HEX : RSPAMD_KEYPAIR_DUMP_DEFAULT); | |||
ret = ucl_object_push_lua (L, obj, true); | |||
ucl_object_unref (obj); |