commit 93e3d6b: [Minor] Add extensions to the keypairs

Vsevolod Stakhov vsevolod at rspamd.com
Tue Jan 3 22:56:03 UTC 2023


Author: Vsevolod Stakhov
Date: 2023-01-03 21:06:05 +0000
URL: https://github.com/rspamd/rspamd/commit/93e3d6b7a96eed644e9bfd260e45a23f775e334d (HEAD -> master)

[Minor] Add extensions to the keypairs

---
 src/libcryptobox/keypair.c         | 16 ++++++++++++++++
 src/libcryptobox/keypair_private.h |  1 +
 2 files changed, 17 insertions(+)

diff --git a/src/libcryptobox/keypair.c b/src/libcryptobox/keypair.c
index ce9a9200d..da26fcff7 100644
--- a/src/libcryptobox/keypair.c
+++ b/src/libcryptobox/keypair.c
@@ -212,6 +212,11 @@ rspamd_cryptobox_keypair_dtor (struct rspamd_cryptobox_keypair *kp)
 	sk = rspamd_cryptobox_keypair_sk (kp, &len);
 	g_assert (sk != NULL && len > 0);
 	rspamd_explicit_memzero (sk, len);
+
+	if (kp->extensions) {
+		ucl_object_unref (kp->extensions);
+	}
+
 	/* Not g_free as kp is aligned using posix_memalign */
 	free (kp);
 }
@@ -763,6 +768,12 @@ rspamd_keypair_from_ucl (const ucl_object_t *obj)
 
 	rspamd_cryptobox_hash (kp->id, target, len, NULL, 0);
 
+	elt = ucl_object_lookup (obj, "extensions");
+	if (elt && ucl_object_type (elt) == UCL_OBJECT) {
+		/* Use copy to avoid issues with the refcounts */
+		kp->extensions = ucl_object_copy (elt);
+	}
+
 	return kp;
 }
 
@@ -829,6 +840,11 @@ rspamd_keypair_to_ucl (struct rspamd_cryptobox_keypair *kp,
 							"kex" : "sign"),
 					"type", 0, false);
 
+	if (kp->extensions) {
+		ucl_object_insert_key (elt, ucl_object_copy (kp->extensions),
+			"extensions", 0, false);
+	}
+
 	return ucl_out;
 }
 
diff --git a/src/libcryptobox/keypair_private.h b/src/libcryptobox/keypair_private.h
index 8d259faaa..705d1a4fc 100644
--- a/src/libcryptobox/keypair_private.h
+++ b/src/libcryptobox/keypair_private.h
@@ -39,6 +39,7 @@ struct rspamd_cryptobox_keypair {
 	guchar id[rspamd_cryptobox_HASHBYTES];
 	enum rspamd_cryptobox_keypair_type type;
 	enum rspamd_cryptobox_mode alg;
+	ucl_object_t *extensions;
 	ref_entry_t ref;
 };
 


More information about the Commits mailing list