Revert the size_t modifications from HEAD that had led to more
[openssl.git] / crypto / asn1 / x_pkey.c
index ced975b40ee5017a8d90c510378ea00ef190c6c8..8453618426fbf433cba9a40731eae6233bddedee 100644 (file)
@@ -1,5 +1,5 @@
 /* crypto/asn1/x_pkey.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 "evp.h"
-#include "objects.h"
-#include "asn1_mac.h"
-
-/* ASN1err(ASN1_F_D2I_X509_PKEY,ASN1_R_UNSUPPORTED_CIPHER); */
-/* ASN1err(ASN1_F_X509_PKEY_NEW,ASN1_R_IV_TOO_LARGE); */
+#include <openssl/evp.h>
+#include <openssl/objects.h>
+#include <openssl/asn1_mac.h>
+#include <openssl/x509.h>
 
 /* need to implement */
-int i2d_X509_PKEY(a,pp)
-X509_PKEY *a;
-unsigned char **pp;
+int i2d_X509_PKEY(X509_PKEY *a, unsigned char **pp)
        {
        return(0);
        }
 
-X509_PKEY *d2i_X509_PKEY(a,pp,length)
-X509_PKEY **a;
-unsigned char **pp;
-long length;
+X509_PKEY *d2i_X509_PKEY(X509_PKEY **a, const unsigned char **pp, long length)
        {
        int i;
        M_ASN1_D2I_vars(a,X509_PKEY *,X509_PKEY_new);
 
        M_ASN1_D2I_Init();
        M_ASN1_D2I_start_sequence();
-       M_ASN1_D2I_get(ret->enc_algor,d2i_X509_ALGOR);
-       M_ASN1_D2I_get(ret->enc_pkey,d2i_ASN1_OCTET_STRING);
+       M_ASN1_D2I_get_x(X509_ALGOR,ret->enc_algor,d2i_X509_ALGOR);
+       M_ASN1_D2I_get_x(ASN1_OCTET_STRING,ret->enc_pkey,d2i_ASN1_OCTET_STRING);
 
        ret->cipher.cipher=EVP_get_cipherbyname(
                OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm)));
        if (ret->cipher.cipher == NULL)
                {
                c.error=ASN1_R_UNSUPPORTED_CIPHER;
+               c.line=__LINE__;
                goto err;
                }
        if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) 
@@ -99,6 +93,7 @@ long length;
                if (i > EVP_MAX_IV_LENGTH)
                        {
                        c.error=ASN1_R_IV_TOO_LARGE;
+                       c.line=__LINE__;
                        goto err;
                        }
                memcpy(ret->cipher.iv,
@@ -109,14 +104,15 @@ long length;
        M_ASN1_D2I_Finish(a,X509_PKEY_free,ASN1_F_D2I_X509_PKEY);
        }
 
-X509_PKEY *X509_PKEY_new()
+X509_PKEY *X509_PKEY_new(void)
        {
        X509_PKEY *ret=NULL;
+       ASN1_CTX c;
 
        M_ASN1_New_Malloc(ret,X509_PKEY);
        ret->version=0;
        M_ASN1_New(ret->enc_algor,X509_ALGOR_new);
-       M_ASN1_New(ret->enc_pkey,ASN1_OCTET_STRING_new);
+       M_ASN1_New(ret->enc_pkey,M_ASN1_OCTET_STRING_new);
        ret->dec_pkey=NULL;
        ret->key_length=0;
        ret->key_data=NULL;
@@ -128,14 +124,16 @@ X509_PKEY *X509_PKEY_new()
        M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW);
        }
 
-void X509_PKEY_free(x)
-X509_PKEY *x;
+void X509_PKEY_free(X509_PKEY *x)
        {
        int i;
 
        if (x == NULL) return;
 
        i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_X509_PKEY);
+#ifdef REF_PRINT
+       REF_PRINT("X509_PKEY",x);
+#endif
        if (i > 0) return;
 #ifdef REF_CHECK
        if (i < 0)
@@ -146,8 +144,8 @@ X509_PKEY *x;
 #endif
 
        if (x->enc_algor != NULL) X509_ALGOR_free(x->enc_algor);
-       if (x->enc_pkey != NULL) ASN1_OCTET_STRING_free(x->enc_pkey);
+       if (x->enc_pkey != NULL) M_ASN1_OCTET_STRING_free(x->enc_pkey);
        if (x->dec_pkey != NULL)EVP_PKEY_free(x->dec_pkey);
-       if ((x->key_data != NULL) && (x->key_free)) Free((char *)x->key_data);
-       Free((char *)(char *)x);
+       if ((x->key_data != NULL) && (x->key_free)) OPENSSL_free(x->key_data);
+       OPENSSL_free(x);
        }