From 018025f0f36a4847df265c9948dbaf7073ed3245 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 25 Nov 2016 18:16:05 +0000 Subject: Alpha version of the SSL work. Doesn't build yet, but I'm scared of losing it, so using git as storage. Will fix the stupid bugs now, the tricky bugs later. --- src/sbearssl/sbearssl_pem_decode_from_string.c | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/sbearssl/sbearssl_pem_decode_from_string.c (limited to 'src/sbearssl/sbearssl_pem_decode_from_string.c') diff --git a/src/sbearssl/sbearssl_pem_decode_from_string.c b/src/sbearssl/sbearssl_pem_decode_from_string.c new file mode 100644 index 0000000..efcb431 --- /dev/null +++ b/src/sbearssl/sbearssl_pem_decode_from_string.c @@ -0,0 +1,36 @@ +/* ISC license. */ + +#include +#include +#include +#include +#include +#include +#include +#include "sbearssl-internal.h" + +int sbearssl_pem_decode_from_string (char const *s, size_t len, genalloc *list, stralloc *sa) +{ + br_pem_decoder_context ctx ; + sbearssl_pemobject po ; + sbearssl_strallocerr blah = { .sa = sa, .err = 0 } ; + size_t listbase = genalloc_len(sbearssl_pemobject, list) ; + size_t sabase = sa->len ; + int listwasnull = !genalloc_s(sbearssl_pemobject, list) ; + int sawasnull = !sa->s ; + int inobj = 0 ; + int r ; + + br_pem_decoder_init(&ctx) ; + r = sbearssl_pem_push(&ctx, s, len, &po, list, &blah, &inobj) ; + if (r) goto fail ; + if (!inobj) return 0 ; + + errno = EPROTO ; + fail: + if (listwasnull) genalloc_free(sbearssl_pemobject, list) ; + else genalloc_setlen(sbearssl_pemobject, list, listbase) ; + if (sawasnull) stralloc_free(sa) ; + else sa->len = sabase ; + return r ; +} -- cgit v1.3.1