• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9 
10 #include <openssl/asn1.h>
11 #include <openssl/dsa.h>
12 #include <openssl/ec_key.h>
13 #include <openssl/err.h>
14 #include <openssl/evp.h>
15 #include <openssl/rsa.h>
16 
17 
i2d_PrivateKey(const EVP_PKEY * a,uint8_t ** pp)18 int i2d_PrivateKey(const EVP_PKEY *a, uint8_t **pp) {
19   switch (EVP_PKEY_id(a)) {
20     case EVP_PKEY_RSA:
21       return i2d_RSAPrivateKey(EVP_PKEY_get0_RSA(a), pp);
22     case EVP_PKEY_EC:
23       return i2d_ECPrivateKey(EVP_PKEY_get0_EC_KEY(a), pp);
24     case EVP_PKEY_DSA:
25       return i2d_DSAPrivateKey(EVP_PKEY_get0_DSA(a), pp);
26     default:
27       // Although this file is in crypto/x509 for layering reasons, it emits
28       // an error code from ASN1 for OpenSSL compatibility.
29       OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
30       return -1;
31   }
32 }
33