summaryrefslogtreecommitdiff
path: root/src/sbearssl/sbearssl_ta_from.c
blob: 001b95817e3405a9b22c298c6d9f332bbce46ef9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* ISC license. */

#include <sys/types.h>
#include <bearssl.h>
#include <skalibs/stralloc.h>
#include <s6-networking/sbearssl.h>

int sbearssl_ta_from (sbearssl_ta *l, br_x509_trust_anchor const *k, stralloc *sa)
{
  size_t sabase = sa->len ;
  int sawasnull = !sa->s ;
  sbearssl_ta ta = { .dn = sa->len, .dnlen = k->dn_len, .flags = k->flags } ;
  if (!stralloc_catb(sa, (char const *)k->dn, k->dn_len)) return 0 ;
  if (!sbearssl_pkey_from(&ta.pkey, &k->pkey, sa)) goto fail ;
  *l = ta ;
  return 1 ;

 fail:
  if (sawasnull) stralloc_free(sa) ;
  else sa->len = sabase ;
  return 0 ;
}