i2d_pr.c revision 272461
1250757Sjkim/* crypto/asn1/i2d_pr.c */ 2250757Sjkim/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3250757Sjkim * All rights reserved. 4250757Sjkim * 5250757Sjkim * This package is an SSL implementation written 6250757Sjkim * by Eric Young (eay@cryptsoft.com). 7250757Sjkim * The implementation was written so as to conform with Netscapes SSL. 8250757Sjkim * 9250757Sjkim * This library is free for commercial and non-commercial use as long as 10250757Sjkim * the following conditions are aheared to. The following conditions 11250757Sjkim * apply to all code found in this distribution, be it the RC4, RSA, 12250757Sjkim * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13250757Sjkim * included with this distribution is covered by the same copyright terms 14250757Sjkim * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15250757Sjkim * 16250757Sjkim * Copyright remains Eric Young's, and as such any Copyright notices in 17250757Sjkim * the code are not to be removed. 18250757Sjkim * If this package is used in a product, Eric Young should be given attribution 19250757Sjkim * as the author of the parts of the library used. 20250757Sjkim * This can be in the form of a textual message at program startup or 21250757Sjkim * in documentation (online or textual) provided with the package. 22250757Sjkim * 23250757Sjkim * Redistribution and use in source and binary forms, with or without 24250757Sjkim * modification, are permitted provided that the following conditions 25250757Sjkim * are met: 26250757Sjkim * 1. Redistributions of source code must retain the copyright 27250757Sjkim * notice, this list of conditions and the following disclaimer. 28250757Sjkim * 2. Redistributions in binary form must reproduce the above copyright 29250757Sjkim * notice, this list of conditions and the following disclaimer in the 30250757Sjkim * documentation and/or other materials provided with the distribution. 31250757Sjkim * 3. All advertising materials mentioning features or use of this software 32250757Sjkim * must display the following acknowledgement: 33250757Sjkim * "This product includes cryptographic software written by 34250757Sjkim * Eric Young (eay@cryptsoft.com)" 35250757Sjkim * The word 'cryptographic' can be left out if the rouines from the library 36250757Sjkim * being used are not cryptographic related :-). 37250757Sjkim * 4. If you include any Windows specific code (or a derivative thereof) from 38250757Sjkim * the apps directory (application code) you must include an acknowledgement: 39250757Sjkim * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40250757Sjkim * 41250757Sjkim * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42250757Sjkim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43250757Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44250757Sjkim * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45250757Sjkim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46250838Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47250838Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48250757Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49250757Sjkim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50250757Sjkim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51250757Sjkim * SUCH DAMAGE. 52250757Sjkim * 53250757Sjkim * The licence and distribution terms for any publically available version or 54250757Sjkim * derivative of this code cannot be changed. i.e. this code cannot simply be 55250757Sjkim * copied and put under another distribution licence 56250757Sjkim * [including the GNU Public Licence.] 57250757Sjkim */ 58250757Sjkim 59250757Sjkim#include <stdio.h> 60250757Sjkim#include "cryptlib.h" 61250757Sjkim#include <openssl/evp.h> 62250757Sjkim#include <openssl/x509.h> 63250757Sjkim#include "asn1_locl.h" 64250757Sjkim 65250757Sjkimint i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp) 66250757Sjkim { 67250757Sjkim if (a->ameth && a->ameth->old_priv_encode) 68250757Sjkim { 69250757Sjkim return a->ameth->old_priv_encode(a, pp); 70250757Sjkim } 71250757Sjkim if (a->ameth && a->ameth->priv_encode) { 72250757Sjkim PKCS8_PRIV_KEY_INFO *p8 = EVP_PKEY2PKCS8(a); 73250757Sjkim int ret = i2d_PKCS8_PRIV_KEY_INFO(p8,pp); 74250757Sjkim PKCS8_PRIV_KEY_INFO_free(p8); 75250757Sjkim return ret; 76250757Sjkim } 77250757Sjkim ASN1err(ASN1_F_I2D_PRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); 78250757Sjkim return(-1); 79250757Sjkim } 80250757Sjkim 81250757Sjkim