2016-05-18 02:51:34 +08:00
|
|
|
/*
|
|
|
|
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 18:52:47 +08:00
|
|
|
*
|
2016-05-18 02:51:34 +08: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 18:52:47 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
1999-04-24 06:13:45 +08:00
|
|
|
#include <openssl/evp.h>
|
2007-11-20 21:37:51 +08:00
|
|
|
#include <openssl/x509.h>
|
2015-03-24 02:42:42 +08:00
|
|
|
#include "internal/asn1_int.h"
|
2016-01-19 08:21:12 +08:00
|
|
|
#include "internal/evp_int.h"
|
1998-12-21 18:52:47 +08:00
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp)
|
2015-01-22 11:40:55 +08: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-10 03:52:11 +08:00
|
|
|
int ret = 0;
|
|
|
|
if (p8 != NULL) {
|
|
|
|
ret = i2d_PKCS8_PRIV_KEY_INFO(p8, pp);
|
|
|
|
PKCS8_PRIV_KEY_INFO_free(p8);
|
|
|
|
}
|
2015-01-22 11:40:55 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ASN1err(ASN1_F_I2D_PRIVATEKEY, ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
|
2016-05-10 03:52:11 +08:00
|
|
|
return -1;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|