From f657cfa70301037f057945177a2adad6b8653d1c Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Fri, 21 Oct 2016 10:19:17 +0200 Subject: [PATCH] better sig2blob and back wrappers --- include/pcp/keysig.h | 5 ++++- libpcp/keysig.c | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/pcp/keysig.h b/include/pcp/keysig.h index f25b535..27be313 100644 --- a/include/pcp/keysig.h +++ b/include/pcp/keysig.h @@ -36,7 +36,10 @@ #define PCP_RAW_KEYSIGSIZE sizeof(pcp_keysig_t) - sizeof(UT_hash_handle) /* put a keysig into a buffer, convert to big endian while at it */ -Buffer *pcp_keysig2blob(pcp_keysig_t *s); +void pcp_keysig2blob(Buffer *b, pcp_keysig_t *s); + +/* same, but allocs buffer */ +Buffer *pcp_keysigblob(pcp_keysig_t *s); /* fetch a keysig from a buffer, usually loaded from vault */ pcp_keysig_t *pcp_blob2keysig(Buffer *blob); diff --git a/libpcp/keysig.c b/libpcp/keysig.c index 2d9d553..4d9f77e 100644 --- a/libpcp/keysig.c +++ b/libpcp/keysig.c @@ -22,16 +22,19 @@ #include "keysig.h" -Buffer *pcp_keysig2blob(pcp_keysig_t *s) { - Buffer *b = buffer_new(256, "keysig2blob"); +void pcp_keysig2blob(Buffer *b, pcp_keysig_t *s) { buffer_add8(b, s->type); buffer_add32be(b, s->size); buffer_add(b, s->id, 17); buffer_add(b, s->checksum, LSHA); buffer_add(b, s->blob, s->size); - return b; } +Buffer *pcp_keysigblob(pcp_keysig_t *s) { + Buffer *b = buffer_new(256, "keysig2blob"); + pcp_keysig2blob(b, s); + return b; +} pcp_keysig_t *pcp_blob2keysig(Buffer *blob) { pcp_keysig_t *sk = ucmalloc(sizeof(pcp_keysig_t));