summaryrefslogtreecommitdiff
path: root/src/sbearssl/sbearssl_pkey_from.c
blob: c7bc707e57115517048aab48c400e8aa9708f7b1 (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 <errno.h>
#include <bearssl.h>
#include <s6-networking/sbearssl.h>

int sbearssl_pkey_from (sbearssl_pkey *l, br_x509_pkey const *k, stralloc *sa)
{
  switch (k->key_type)
  {
    case BR_KEYTYPE_RSA :
      if (!sbearssl_rsa_pkey_from(&l->data.rsa, &k->key.rsa, sa)) return 0 ;
      break ;
    case BR_KEYTYPE_EC :
      if (!sbearssl_ec_pkey_from(&l->data.ec, &k->key.ec, sa)) return 0 ;
      break ;
    default :
      return (errno = EINVAL, 0) ;
  }
  l->type = k->key_type ;
  return 1 ;
}