RT1815: More const'ness improvements
[openssl.git] / crypto / asn1 / d2i_pu.c
index f66d72fd7b4303b446c242346916e07c7949dbfb..c8f39ceb037beb1fef1cc42ed839a53fc7847871 100644 (file)
 #ifndef OPENSSL_NO_DSA
 #include <openssl/dsa.h>
 #endif
-#ifndef OPENSSL_NO_ECDSA
-#include <openssl/ecdsa.h>
+#ifndef OPENSSL_NO_EC
+#include <openssl/ec.h>
 #endif
 
-EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp,
+EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp,
             long length)
        {
        EVP_PKEY *ret;
@@ -87,9 +87,13 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp,
                }
        else    ret= *a;
 
-       ret->save_type=type;
-       ret->type=EVP_PKEY_type(type);
-       switch (ret->type)
+       if (!EVP_PKEY_set_type(ret, type))
+               {
+               ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB);
+               goto err;
+               }
+
+       switch (EVP_PKEY_id(ret))
                {
 #ifndef OPENSSL_NO_RSA
        case EVP_PKEY_RSA:
@@ -103,18 +107,18 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp,
 #endif
 #ifndef OPENSSL_NO_DSA
        case EVP_PKEY_DSA:
-               if ((ret->pkey.dsa=d2i_DSAPublicKey(&(ret->pkey.dsa),
-                       (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */
+               if (!d2i_DSAPublicKey(&(ret->pkey.dsa),
+                       (const unsigned char **)pp,length)) /* TMP UGLY CAST */
                        {
                        ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB);
                        goto err;
                        }
                break;
 #endif
-#ifndef OPENSSL_NO_ECDSA
-       case EVP_PKEY_ECDSA:
-               if ((ret->pkey.ecdsa = ECDSAPublicKey_set_octet_string(&(ret->pkey.ecdsa), 
-                       (const unsigned char **)pp, length)) == NULL)
+#ifndef OPENSSL_NO_EC
+       case EVP_PKEY_EC:
+               if (!o2i_ECPublicKey(&(ret->pkey.ec),
+                                    (const unsigned char **)pp, length))
                        {
                        ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB);
                        goto err;