commit 3f5ca5e: [Minor] Allow to flatten keypair output

Vsevolod Stakhov vsevolod at rspamd.com
Wed Jan 4 19:56:07 UTC 2023


Author: Vsevolod Stakhov
Date: 2023-01-04 13:56:29 +0000
URL: https://github.com/rspamd/rspamd/commit/3f5ca5e8b061e34b713b1a2022e46c37529751db (HEAD -> master)

[Minor] Allow to flatten keypair output

---
 src/fuzzy_storage.c        |  3 ++-
 src/libcryptobox/keypair.c | 13 ++++++++++---
 src/libcryptobox/keypair.h |  1 +
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c
index bea32134f..71f63adbd 100644
--- a/src/fuzzy_storage.c
+++ b/src/fuzzy_storage.c
@@ -1882,7 +1882,8 @@ 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, RSPAMD_KEYPAIR_DUMP_NO_SECRET),
+			ucl_object_insert_key (elt,
+				rspamd_keypair_to_ucl (fuzzy_key->key, RSPAMD_KEYPAIR_DUMP_NO_SECRET|RSPAMD_KEYPAIR_DUMP_FLATTENED),
 				"keypair", 0, false);
 			ucl_object_insert_key (keys_obj, elt, keyname, 0, true);
 		}
diff --git a/src/libcryptobox/keypair.c b/src/libcryptobox/keypair.c
index b97cd699e..2ef996527 100644
--- a/src/libcryptobox/keypair.c
+++ b/src/libcryptobox/keypair.c
@@ -805,9 +805,16 @@ rspamd_keypair_to_ucl (struct rspamd_cryptobox_keypair *kp,
 		encoding = "base32";
 	}
 
-	ucl_out = ucl_object_typed_new (UCL_OBJECT);
-	elt = ucl_object_typed_new (UCL_OBJECT);
-	ucl_object_insert_key (ucl_out, elt, "keypair", 0, false);
+	if (flags & RSPAMD_KEYPAIR_DUMP_FLATTENED) {
+		ucl_out = ucl_object_typed_new (UCL_OBJECT);
+		elt = ucl_out;
+	}
+	else {
+		ucl_out = ucl_object_typed_new (UCL_OBJECT);
+		elt = ucl_object_typed_new (UCL_OBJECT);
+		ucl_object_insert_key (ucl_out, elt, "keypair", 0, false);
+	}
+
 
 	/* pubkey part */
 	keypair_out = rspamd_keypair_print (kp,
diff --git a/src/libcryptobox/keypair.h b/src/libcryptobox/keypair.h
index ed247e8ca..18a87d7f5 100644
--- a/src/libcryptobox/keypair.h
+++ b/src/libcryptobox/keypair.h
@@ -249,6 +249,7 @@ enum rspamd_keypair_dump_flags {
 	RSPAMD_KEYPAIR_DUMP_DEFAULT = 0,
 	RSPAMD_KEYPAIR_DUMP_HEX = 1u << 0u,
 	RSPAMD_KEYPAIR_DUMP_NO_SECRET = 1u << 1u,
+	RSPAMD_KEYPAIR_DUMP_FLATTENED = 1u << 2u,
 };
 
 /**


More information about the Commits mailing list