diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-02-05 23:53:57 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-02-05 23:53:57 +0000 |
commit | 7994b046610509c8fc3ad8350c77ee0b864f6349 (patch) | |
tree | b77e86bacb50c1ea775a40d34ceefff8c7fa3b48 /src/libcryptobox | |
parent | c13d594abf0c2c1f75b7b55573a047b757e2c2ec (diff) | |
download | rspamd-7994b046610509c8fc3ad8350c77ee0b864f6349.tar.gz rspamd-7994b046610509c8fc3ad8350c77ee0b864f6349.zip |
Add more utilities to operate with keypairs
Diffstat (limited to 'src/libcryptobox')
-rw-r--r-- | src/libcryptobox/keypair.c | 44 | ||||
-rw-r--r-- | src/libcryptobox/keypair.h | 24 |
2 files changed, 68 insertions, 0 deletions
diff --git a/src/libcryptobox/keypair.c b/src/libcryptobox/keypair.c index 61a5f687d..0cd6f9eb3 100644 --- a/src/libcryptobox/keypair.c +++ b/src/libcryptobox/keypair.c @@ -451,6 +451,21 @@ rspamd_pubkey_get_id (struct rspamd_cryptobox_pubkey *pk) return pk->id; } +const guchar * +rspamd_pubkey_get_pk (struct rspamd_cryptobox_pubkey *pk, + guint *len) +{ + guchar *ret = NULL; + guint rlen; + + ret = rspamd_cryptobox_pubkey_pk (pk, &rlen); + + if (len) { + *len = rlen; + } + + return ret; +} static void rspamd_keypair_print_component (guchar *data, gsize datalen, @@ -513,3 +528,32 @@ rspamd_keypair_print (struct rspamd_cryptobox_keypair *kp, guint how) return res; } + +const guchar * +rspamd_keypair_component (struct rspamd_cryptobox_keypair *kp, + guint ncomp, guint *len) +{ + guint rlen = 0; + const guchar *ret = NULL; + + g_assert (kp != NULL); + + switch (ncomp) { + case RSPAMD_KEYPAIR_COMPONENT_ID: + rlen = sizeof (kp->id); + ret = kp->id; + break; + case RSPAMD_KEYPAIR_COMPONENT_PK: + ret = rspamd_cryptobox_keypair_pk (kp, &rlen); + break; + case RSPAMD_KEYPAIR_COMPONENT_SK: + ret = rspamd_cryptobox_keypair_sk (kp, &rlen); + break; + } + + if (len) { + *len = rlen; + } + + return ret; +} diff --git a/src/libcryptobox/keypair.h b/src/libcryptobox/keypair.h index bd82b64ae..613c1296d 100644 --- a/src/libcryptobox/keypair.h +++ b/src/libcryptobox/keypair.h @@ -148,6 +148,14 @@ const guchar * rspamd_keypair_get_id (struct rspamd_cryptobox_keypair *kp); */ const guchar * rspamd_pubkey_get_id (struct rspamd_cryptobox_pubkey *pk); +/** + * Get raw public key from pubkey opaque structure + * @param pk + * @param len + * @return + */ +const guchar * rspamd_pubkey_get_pk (struct rspamd_cryptobox_pubkey *pk, + guint *len); /** Print pubkey */ #define RSPAMD_KEYPAIR_PUBKEY 0x1 @@ -171,4 +179,20 @@ const guchar * rspamd_pubkey_get_id (struct rspamd_cryptobox_pubkey *pk); GString *rspamd_keypair_print (struct rspamd_cryptobox_keypair *kp, guint how); +/** Get keypair pubkey ID */ +#define RSPAMD_KEYPAIR_COMPONENT_ID 0 +/** Get keypair public key */ +#define RSPAMD_KEYPAIR_COMPONENT_PK 1 +/** Get keypair private key */ +#define RSPAMD_KEYPAIR_COMPONENT_SK 2 +/** + * Get specific component of a keypair + * @param kp keypair + * @param ncomp component number + * @param len length of input + * @return raw content of the component + */ +const guchar * rspamd_keypair_component (struct rspamd_cryptobox_keypair *kp, + guint ncomp, guint *len); + #endif /* SRC_LIBCRYPTOBOX_KEYPAIR_H_ */ |