summaryrefslogtreecommitdiff
path: root/src/sbearssl/sbearssl_ta_readfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sbearssl/sbearssl_ta_readfile.c')
-rw-r--r--src/sbearssl/sbearssl_ta_readfile.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/sbearssl/sbearssl_ta_readfile.c b/src/sbearssl/sbearssl_ta_readfile.c
index 8e7cf8e..9411347 100644
--- a/src/sbearssl/sbearssl_ta_readfile.c
+++ b/src/sbearssl/sbearssl_ta_readfile.c
@@ -1,16 +1,39 @@
/* ISC license. */
+#include <sys/types.h>
+#include <errno.h>
#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
#include <s6-networking/sbearssl.h>
-#include "sbearssl-internal.h"
int sbearssl_ta_readfile (char const *file, genalloc *taga, stralloc *tasa)
{
stralloc certsa = STRALLOC_ZERO ;
genalloc certga = GENALLOC_ZERO ;
- int r = sbearssl_ta_readfile_internal(file, taga, tasa, &certsa, &certga) ;
+ size_t tasabase = tasa->len ;
+ size_t tagabase = genalloc_len(sbearssl_ta, taga) ;
+ int tasawasnull = !tasa->s ;
+ int tagawasnull = !genalloc_s(sbearssl_ta, taga) ;
+ int r = sbearssl_cert_readbigpem(file, &certga, &certsa) ;
+ if (r) return r ;
+ r = sbearssl_ta_certs(taga, tasa, genalloc_s(sbearssl_cert, &certga), genalloc_len(sbearssl_cert, &certga), certsa.s) ;
+ if (r) goto fail ;
+
genalloc_free(sbearssl_ta, &certga) ;
stralloc_free(&certsa) ;
+ return 0 ;
+
+ fail:
+ {
+ int e = errno ;
+ genalloc_free(sbearssl_cert, &certga) ;
+ stralloc_free(&certsa) ;
+ if (tagawasnull) genalloc_free(sbearssl_ta, taga) ;
+ else genalloc_setlen(sbearssl_ta, taga, tagabase) ;
+ if (tasawasnull) stralloc_free(tasa) ;
+ else tasa->len = tasabase ;
+ errno = e ;
+ }
return r ;
+
}