botan: Encode private keys as PKCS#8

Since we can now parse that encoding directly we can simplify the private
key export and stick to PKCS#8.
This commit is contained in:
Tobias Brunner
2018-09-12 16:25:00 +02:00
parent 607f10dca4
commit bd267c863f
4 changed files with 46 additions and 145 deletions
@@ -257,38 +257,7 @@ METHOD(private_key_t, get_encoding, bool,
private_botan_rsa_private_key_t *this, cred_encoding_type_t type,
chunk_t *encoding)
{
switch (type)
{
case PRIVKEY_ASN1_DER:
case PRIVKEY_PEM:
{
uint32_t format = BOTAN_PRIVKEY_EXPORT_FLAG_DER;
size_t len = 0;
bool success = TRUE;
if (type == PRIVKEY_PEM)
{
format = BOTAN_PRIVKEY_EXPORT_FLAG_PEM;
}
if (botan_privkey_rsa_get_privkey(this->key, NULL, &len, format)
!= BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE)
{
return FALSE;
}
*encoding = chunk_alloc(len);
if (botan_privkey_rsa_get_privkey(this->key, encoding->ptr, &len,
format))
{
chunk_clear(encoding);
return FALSE;
}
return success;
}
default:
return FALSE;
}
return botan_get_privkey_encoding(this->key, type, encoding);
}
METHOD(private_key_t, get_ref, private_key_t*,