OLD | NEW |
1 /* crypto/asn1/i2d_pr.c */ | 1 /* crypto/asn1/i2d_pr.c */ |
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * This package is an SSL implementation written | 5 * This package is an SSL implementation written |
6 * by Eric Young (eay@cryptsoft.com). | 6 * by Eric Young (eay@cryptsoft.com). |
7 * The implementation was written so as to conform with Netscapes SSL. | 7 * The implementation was written so as to conform with Netscapes SSL. |
8 * | 8 * |
9 * This library is free for commercial and non-commercial use as long as | 9 * This library is free for commercial and non-commercial use as long as |
10 * the following conditions are aheared to. The following conditions | 10 * the following conditions are aheared to. The following conditions |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 * SUCH DAMAGE. | 51 * SUCH DAMAGE. |
52 * | 52 * |
53 * The licence and distribution terms for any publically available version or | 53 * The licence and distribution terms for any publically available version or |
54 * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 * copied and put under another distribution licence | 55 * copied and put under another distribution licence |
56 * [including the GNU Public Licence.] | 56 * [including the GNU Public Licence.] |
57 */ | 57 */ |
58 | 58 |
59 #include <stdio.h> | 59 #include <stdio.h> |
60 #include "cryptlib.h" | 60 #include "cryptlib.h" |
61 #include <openssl/bn.h> | |
62 #include <openssl/evp.h> | 61 #include <openssl/evp.h> |
63 #include <openssl/objects.h> | 62 #include <openssl/x509.h> |
64 #ifndef OPENSSL_NO_RSA | 63 #include "asn1_locl.h" |
65 #include <openssl/rsa.h> | |
66 #endif | |
67 #ifndef OPENSSL_NO_DSA | |
68 #include <openssl/dsa.h> | |
69 #endif | |
70 #ifndef OPENSSL_NO_EC | |
71 #include <openssl/ec.h> | |
72 #endif | |
73 | 64 |
74 int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp) | 65 int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp) |
75 { | 66 { |
76 #ifndef OPENSSL_NO_RSA | 67 » if (a->ameth && a->ameth->old_priv_encode) |
77 » if (a->type == EVP_PKEY_RSA) | |
78 { | 68 { |
79 » » return(i2d_RSAPrivateKey(a->pkey.rsa,pp)); | 69 » » return a->ameth->old_priv_encode(a, pp); |
80 } | 70 } |
81 » else | 71 » if (a->ameth && a->ameth->priv_encode) { |
82 #endif | 72 » » PKCS8_PRIV_KEY_INFO *p8 = EVP_PKEY2PKCS8(a); |
83 #ifndef OPENSSL_NO_DSA | 73 » » int ret = i2d_PKCS8_PRIV_KEY_INFO(p8,pp); |
84 » if (a->type == EVP_PKEY_DSA) | 74 » » PKCS8_PRIV_KEY_INFO_free(p8); |
85 » » { | 75 » » return ret; |
86 » » return(i2d_DSAPrivateKey(a->pkey.dsa,pp)); | 76 » }» |
87 » » } | |
88 #endif | |
89 #ifndef OPENSSL_NO_EC | |
90 » if (a->type == EVP_PKEY_EC) | |
91 » » { | |
92 » » return(i2d_ECPrivateKey(a->pkey.ec, pp)); | |
93 » » } | |
94 #endif | |
95 | |
96 ASN1err(ASN1_F_I2D_PRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); | 77 ASN1err(ASN1_F_I2D_PRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); |
97 return(-1); | 78 return(-1); |
98 } | 79 } |
99 | 80 |
OLD | NEW |