openssl: Add support for generic encoding of EC public keys
This commit is contained in:
@@ -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;
|
||||
chunk_t asn1_encoding = *encoding;
|
||||
|
||||
*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;
|
||||
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*,
|
||||
|
||||
Reference in New Issue
Block a user