Fix Coverity issues 1596850, 1596851 and 1596852
[openssl.git] / crypto / asn1 / i2d_evp.c
index 8b36388263c35fe786f2a04f5690a1628e12d663..106ea152733c504e95b0075f4781215ab91ae302 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
  *
  * Licensed under the Apache License 2.0 (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
@@ -34,7 +34,6 @@ static int i2d_provided(const EVP_PKEY *a, int selection,
                         const struct type_and_structure_st *output_info,
                         unsigned char **pp)
 {
-    OSSL_ENCODER_CTX *ctx = NULL;
     int ret;
 
     for (ret = -1;
@@ -49,6 +48,7 @@ static int i2d_provided(const EVP_PKEY *a, int selection,
          */
         size_t len = INT_MAX;
         int pp_was_NULL = (pp == NULL || *pp == NULL);
+        OSSL_ENCODER_CTX *ctx;
 
         ctx = OSSL_ENCODER_CTX_new_for_pkey(a, selection,
                                             output_info->output_type,
@@ -63,7 +63,6 @@ static int i2d_provided(const EVP_PKEY *a, int selection,
                 ret = INT_MAX - (int)len;
         }
         OSSL_ENCODER_CTX_free(ctx);
-        ctx = NULL;
     }
 
     if (ret == -1)
@@ -131,7 +130,7 @@ int i2d_PublicKey(const EVP_PKEY *a, unsigned char **pp)
 
         return i2d_provided(a, EVP_PKEY_PUBLIC_KEY, output_info, pp);
     }
-    switch (EVP_PKEY_get_id(a)) {
+    switch (EVP_PKEY_get_base_id(a)) {
     case EVP_PKEY_RSA:
         return i2d_RSAPublicKey(EVP_PKEY_get0_RSA(a), pp);
 #ifndef OPENSSL_NO_DSA