openssl: Add support for generic encoding of EC public keys
authorTobias Brunner <tobias@strongswan.org>
Fri, 16 Aug 2013 11:12:47 +0000 (13:12 +0200)
committerTobias Brunner <tobias@strongswan.org>
Fri, 13 Sep 2013 13:23:49 +0000 (15:23 +0200)
src/libstrongswan/plugins/openssl/openssl_ec_public_key.c

index 38cc8be..382c554 100644 (file)
@@ -245,33 +245,23 @@ METHOD(public_key_t, get_encoding, bool,
        private_openssl_ec_public_key_t *this, cred_encoding_type_t type,
        chunk_t *encoding)
 {
+       bool success = TRUE;
        u_char *p;
 
-       switch (type)
+       *encoding = chunk_alloc(i2d_EC_PUBKEY(this->ec, NULL));
+       p = encoding->ptr;
+       i2d_EC_PUBKEY(this->ec, &p);
+
+       if (type != PUBKEY_SPKI_ASN1_DER)
        {
-               case PUBKEY_SPKI_ASN1_DER:
-               case PUBKEY_PEM:
-               {
-                       bool success = TRUE;
-
-                       *encoding = chunk_alloc(i2d_EC_PUBKEY(this->ec, NULL));
-                       p = encoding->ptr;
-                       i2d_EC_PUBKEY(this->ec, &p);
-
-                       if (type == PUBKEY_PEM)
-                       {
-                               chunk_t asn1_encoding = *encoding;
-
-                               success = lib->encoding->encode(lib->encoding, PUBKEY_PEM,
-                                                               NULL, encoding, CRED_PART_ECDSA_PUB_ASN1_DER,
-                                                               asn1_encoding, CRED_PART_END);
-                               chunk_clear(&asn1_encoding);
-                       }
-                       return success;
-               }
-               default:
-                       return FALSE;
+               chunk_t asn1_encoding = *encoding;
+
+               success = lib->encoding->encode(lib->encoding, type,
+                                               NULL, encoding, CRED_PART_ECDSA_PUB_ASN1_DER,
+                                               asn1_encoding, CRED_PART_END);
+               chunk_clear(&asn1_encoding);
        }
+       return success;
 }
 
 METHOD(public_key_t, get_ref, public_key_t*,