Remove references to o_time.h
[openssl.git] / crypto / asn1 / i2d_pr.c
index 361beb9fddf942916aa0b31855cc4a0214a08b92..e398b6266612ead688d0325ae443a32e0178492d 100644 (file)
@@ -1,5 +1,5 @@
 /* crypto/asn1/i2d_pr.c */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
  * This package is an SSL implementation written
 
 #include <stdio.h>
 #include "cryptlib.h"
-#include "bn.h"
-#include "evp.h"
-#include "objects.h"
+#include <openssl/evp.h>
+#include <openssl/x509.h>
+#include "asn1_locl.h"
 
-int i2d_PrivateKey(a,pp)
-EVP_PKEY *a;
-unsigned char **pp;
+int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp)
        {
-#ifndef NO_RSA
-       if (a->type == EVP_PKEY_RSA)
+       if (a->ameth && a->ameth->old_priv_encode)
                {
-               return(i2d_RSAPrivateKey(a->pkey.rsa,pp));
+               return a->ameth->old_priv_encode(a, pp);
                }
-       else
-#endif
-#ifndef NO_DSA
-       if (a->type == EVP_PKEY_DSA)
-               {
-               return(i2d_DSAPrivateKey(a->pkey.dsa,pp));
-               }
-#endif
-
+       if (a->ameth && a->ameth->priv_encode) {
+               PKCS8_PRIV_KEY_INFO *p8 = EVP_PKEY2PKCS8(a);
+               int ret = i2d_PKCS8_PRIV_KEY_INFO(p8,pp);
+               PKCS8_PRIV_KEY_INFO_free(p8);
+               return ret;
+       }       
        ASN1err(ASN1_F_I2D_PRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
        return(-1);
        }