use enum type for do_EC_KEY_print
authorDr. Stephen Henson <steve@openssl.org>
Wed, 3 Feb 2016 14:53:15 +0000 (14:53 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Fri, 5 Feb 2016 00:33:33 +0000 (00:33 +0000)
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
crypto/ec/ec_ameth.c

index a0ddb187a255c7e1049f22a1ebbc3240f68f01de..322116b3c1a8cbb7adcf9432c8535f78d99de652 100644 (file)
@@ -379,7 +379,13 @@ static void int_ec_free(EVP_PKEY *pkey)
     EC_KEY_free(pkey->pkey.ec);
 }
 
     EC_KEY_free(pkey->pkey.ec);
 }
 
-static int do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype)
+typedef enum {
+    EC_KEY_PRINT_PRIVATE,
+    EC_KEY_PRINT_PUBLIC,
+    EC_KEY_PRINT_PARAM
+} ec_print_t;
+
+static int do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, ec_print_t ktype)
 {
     unsigned char *buffer = NULL;
     const char *ecstr;
 {
     unsigned char *buffer = NULL;
     const char *ecstr;
@@ -395,7 +401,7 @@ static int do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype)
         goto err;
     }
 
         goto err;
     }
 
-    if (ktype > 0) {
+    if (ktype != EC_KEY_PRINT_PARAM) {
         public_key = EC_KEY_get0_public_key(x);
         if (public_key != NULL) {
             pub_len = EC_POINT_point2oct(group, public_key,
         public_key = EC_KEY_get0_public_key(x);
         if (public_key != NULL) {
             pub_len = EC_POINT_point2oct(group, public_key,
@@ -409,7 +415,7 @@ static int do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype)
         }
     }
 
         }
     }
 
-    if (ktype == 2 && EC_KEY_get0_private_key(x) != NULL) {
+    if (ktype == EC_KEY_PRINT_PRIVATE && EC_KEY_get0_private_key(x) != NULL) {
         priv_len = EC_KEY_priv2oct(x, NULL, 0);
         if (priv_len == 0) {
             reason = ERR_R_EC_LIB;
         priv_len = EC_KEY_priv2oct(x, NULL, 0);
         if (priv_len == 0) {
             reason = ERR_R_EC_LIB;
@@ -426,9 +432,9 @@ static int do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype)
             goto err;
         }
     }
             goto err;
         }
     }
-    if (ktype == 2)
+    if (ktype == EC_KEY_PRINT_PRIVATE)
         ecstr = "Private-Key";
         ecstr = "Private-Key";
-    else if (ktype == 1)
+    else if (ktype == EC_KEY_PRINT_PUBLIC)
         ecstr = "Public-Key";
     else
         ecstr = "ECDSA-Parameters";
         ecstr = "Public-Key";
     else
         ecstr = "ECDSA-Parameters";
@@ -492,19 +498,19 @@ static int eckey_param_encode(const EVP_PKEY *pkey, unsigned char **pder)
 static int eckey_param_print(BIO *bp, const EVP_PKEY *pkey, int indent,
                              ASN1_PCTX *ctx)
 {
 static int eckey_param_print(BIO *bp, const EVP_PKEY *pkey, int indent,
                              ASN1_PCTX *ctx)
 {
-    return do_EC_KEY_print(bp, pkey->pkey.ec, indent, 0);
+    return do_EC_KEY_print(bp, pkey->pkey.ec, indent, EC_KEY_PRINT_PARAM);
 }
 
 static int eckey_pub_print(BIO *bp, const EVP_PKEY *pkey, int indent,
                            ASN1_PCTX *ctx)
 {
 }
 
 static int eckey_pub_print(BIO *bp, const EVP_PKEY *pkey, int indent,
                            ASN1_PCTX *ctx)
 {
-    return do_EC_KEY_print(bp, pkey->pkey.ec, indent, 1);
+    return do_EC_KEY_print(bp, pkey->pkey.ec, indent, EC_KEY_PRINT_PUBLIC);
 }
 
 static int eckey_priv_print(BIO *bp, const EVP_PKEY *pkey, int indent,
                             ASN1_PCTX *ctx)
 {
 }
 
 static int eckey_priv_print(BIO *bp, const EVP_PKEY *pkey, int indent,
                             ASN1_PCTX *ctx)
 {
-    return do_EC_KEY_print(bp, pkey->pkey.ec, indent, 2);
+    return do_EC_KEY_print(bp, pkey->pkey.ec, indent, EC_KEY_PRINT_PRIVATE);
 }
 
 static int old_ec_priv_decode(EVP_PKEY *pkey,
 }
 
 static int old_ec_priv_decode(EVP_PKEY *pkey,