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

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

int sbearssl_skey_from (sbearssl_skey *l, br_skey const *k, stralloc *sa)
{
  switch (k->type)
  {
    case BR_KEYTYPE_RSA :
      if (!sbearssl_rsa_skey_from(&l->data.rsa, &k->data.rsa, sa)) return 0 ;
      break ;
    case BR_KEYTYPE_EC :
      if (!sbearssl_ec_skey_from(&l->data.ec, &k->data.ec, sa)) return 0 ;
      break ;
    default :
      return (errno = EINVAL, 0) ;
  }
  l->type = k->type ;
  return 1 ;
}