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,
|
private_openssl_ec_public_key_t *this, cred_encoding_type_t type,
|
||||||
chunk_t *encoding)
|
chunk_t *encoding)
|
||||||
{
|
{
|
||||||
|
bool success = TRUE;
|
||||||
u_char *p;
|
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:
|
chunk_t asn1_encoding = *encoding;
|
||||||
case PUBKEY_PEM:
|
|
||||||
{
|
|
||||||
bool success = TRUE;
|
|
||||||
|
|
||||||
*encoding = chunk_alloc(i2d_EC_PUBKEY(this->ec, NULL));
|
success = lib->encoding->encode(lib->encoding, type,
|
||||||
p = encoding->ptr;
|
NULL, encoding, CRED_PART_ECDSA_PUB_ASN1_DER,
|
||||||
i2d_EC_PUBKEY(this->ec, &p);
|
asn1_encoding, CRED_PART_END);
|
||||||
|
chunk_clear(&asn1_encoding);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(public_key_t, get_ref, public_key_t*,
|
METHOD(public_key_t, get_ref, public_key_t*,
|
||||||
|
|||||||
Reference in New Issue
Block a user