Extend EVP_PKEY_copy_parameters()
Make EVP_PKEY_copy_parameters() work if the destination has no type (e.g. if obtained from EVP_PKEY_new()) or the underlying key is NULL. This is useful where we want to copy the parameters from an existing key to a new key. Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
This commit is contained in:
@@ -129,7 +129,10 @@ int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode)
|
||||
|
||||
int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
|
||||
{
|
||||
if (to->type != from->type) {
|
||||
if (to->type == EVP_PKEY_NONE) {
|
||||
if (EVP_PKEY_set_type(to, from->type) == 0)
|
||||
return 0;
|
||||
} else if (to->type != from->type) {
|
||||
EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, EVP_R_DIFFERENT_KEY_TYPES);
|
||||
goto err;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user