2016-05-17 18:51:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 10:52:47 +00:00
|
|
|
*
|
2016-05-17 18:51:34 +00:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1998-12-21 10:52:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 14:56:48 +00:00
|
|
|
#include "internal/cryptlib.h"
|
1999-04-23 22:13:45 +00:00
|
|
|
#include <openssl/evp.h>
|
2007-11-20 13:37:51 +00:00
|
|
|
#include <openssl/x509.h>
|
2019-09-27 21:57:58 +00:00
|
|
|
#include "crypto/asn1.h"
|
|
|
|
#include "crypto/evp.h"
|
1998-12-21 10:52:47 +00:00
|
|
|
|
1999-04-19 21:31:43 +00:00
|
|
|
int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
if (a->ameth && a->ameth->old_priv_encode) {
|
|
|
|
return a->ameth->old_priv_encode(a, pp);
|
|
|
|
}
|
|
|
|
if (a->ameth && a->ameth->priv_encode) {
|
|
|
|
PKCS8_PRIV_KEY_INFO *p8 = EVP_PKEY2PKCS8(a);
|
2016-05-09 19:52:11 +00:00
|
|
|
int ret = 0;
|
|
|
|
if (p8 != NULL) {
|
|
|
|
ret = i2d_PKCS8_PRIV_KEY_INFO(p8, pp);
|
|
|
|
PKCS8_PRIV_KEY_INFO_free(p8);
|
|
|
|
}
|
2015-01-22 03:40:55 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ASN1err(ASN1_F_I2D_PRIVATEKEY, ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
|
2016-05-09 19:52:11 +00:00
|
|
|
return -1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|