chibipub

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 4a275d08525df830c96135a5aa3de4f1778532aa
parent 4a1d3ba410f6aae3d523bca151bfd026c7454312
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 16 Jan 2021 16:03:26 -0800

add build_sigbuf helper

we might want to do this when writing activities instead

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Msrc/sigcheck.c | 41+++++++++++++++++++++++++++--------------
1 file changed, 27 insertions(+), 14 deletions(-)

diff --git a/src/sigcheck.c b/src/sigcheck.c @@ -41,12 +41,36 @@ static int push_header(struct ubjson *ubjson, struct cursor *arena, return push_data(arena, (unsigned char*)val.string, val.len); } +static int build_sigbuf(struct sig_header *sig, struct ubjson *ubjson, + struct cursor *arena, unsigned char **sigbuf, int *sigbuf_len) +{ + unsigned char *p, *pstart; + + *sigbuf = arena->p; + pstart = p = (unsigned char*)sig->headers; + for (;; p++) { + if (*p == ' ' || *p == 0) { + if (!push_header(ubjson, arena, pstart, p-pstart)) { + return 0; + } + pstart = p+1; + } + + if (*p == 0) + break; + } + + *sigbuf_len = arena->p - *sigbuf; + + return 1; +} + static int verify_signature(struct cursor cur, struct cursor *arena) { struct ubjson ubjson; struct json val; struct sig_header sig; - unsigned char *p, *pstart, *sigbuf; + unsigned char *sigbuf; int sigbuf_len; init_ubjson(&ubjson, cur.start, cur.p - cur.start); @@ -64,21 +88,10 @@ static int verify_signature(struct cursor cur, struct cursor *arena) return 0; } - sigbuf = arena->p; - pstart = p = (unsigned char*)sig.headers; - for (;; p++) { - if (*p == ' ' || *p == 0) { - if (!push_header(&ubjson, arena, pstart, p-pstart)) { - return 0; - } - pstart = p+1; - } - - if (*p == 0) - break; + if (!build_sigbuf(&sig, &ubjson, arena, &sigbuf, &sigbuf_len)) { + return 0; } - sigbuf_len = arena->p - sigbuf; printf("sigbuf: %.*s\n", sigbuf_len, sigbuf); return 1;