openssl: Add support for generic encoding of EC public keys

This commit is contained in:
Tobias Brunner
2013-09-13 15:23:49 +02:00
parent 90afd2c929
commit d6b3cc87ca
@@ -244,35 +244,25 @@ METHOD(public_key_t, get_fingerprint, bool,
METHOD(public_key_t, get_encoding, bool, METHOD(public_key_t, get_encoding, bool,
private_openssl_ec_public_key_t *this, cred_encoding_type_t type, private_openssl_ec_public_key_t *this, cred_encoding_type_t type,
chunk_t *encoding) chunk_t *encoding)
{
u_char *p;
switch (type)
{
case PUBKEY_SPKI_ASN1_DER:
case PUBKEY_PEM:
{ {
bool success = TRUE; bool success = TRUE;
u_char *p;
*encoding = chunk_alloc(i2d_EC_PUBKEY(this->ec, NULL)); *encoding = chunk_alloc(i2d_EC_PUBKEY(this->ec, NULL));
p = encoding->ptr; p = encoding->ptr;
i2d_EC_PUBKEY(this->ec, &p); i2d_EC_PUBKEY(this->ec, &p);
if (type == PUBKEY_PEM) if (type != PUBKEY_SPKI_ASN1_DER)
{ {
chunk_t asn1_encoding = *encoding; chunk_t asn1_encoding = *encoding;
success = lib->encoding->encode(lib->encoding, PUBKEY_PEM, success = lib->encoding->encode(lib->encoding, type,
NULL, encoding, CRED_PART_ECDSA_PUB_ASN1_DER, NULL, encoding, CRED_PART_ECDSA_PUB_ASN1_DER,
asn1_encoding, CRED_PART_END); asn1_encoding, CRED_PART_END);
chunk_clear(&asn1_encoding); chunk_clear(&asn1_encoding);
} }
return success; return success;
} }
default:
return FALSE;
}
}
METHOD(public_key_t, get_ref, public_key_t*, METHOD(public_key_t, get_ref, public_key_t*,
private_openssl_ec_public_key_t *this) private_openssl_ec_public_key_t *this)