libfreerdp: certificate: Add key_clone

This commit is contained in:
kubistika 2019-07-16 13:26:26 +03:00 committed by akallabeth
parent 1916da35ee
commit 8acea82288
2 changed files with 39 additions and 0 deletions

View File

@ -826,6 +826,44 @@ out_free:
return NULL;
}
rdpRsaKey* key_clone(const rdpRsaKey* key)
{
rdpRsaKey* _key = (rdpRsaKey*) calloc(1, sizeof(rdpRsaKey));
if (!_key)
return NULL;
CopyMemory(_key, key, sizeof(rdpRsaKey));
if (key->Modulus)
{
_key->Modulus = (BYTE*) malloc(key->ModulusLength);
if (!_key->Modulus)
goto out_fail;
CopyMemory(_key->Modulus, key->Modulus, key->ModulusLength);
}
if (key->PrivateExponent)
{
_key->PrivateExponent = (BYTE*) malloc(key->PrivateExponentLength);
if (!_key->PrivateExponent)
goto out_fail;
CopyMemory(_key->PrivateExponent, key->PrivateExponent, key->PrivateExponentLength);
}
return _key;
out_fail:
free(_key->Modulus);
free(_key->PrivateExponent);
free(_key);
return NULL;
}
void key_free(rdpRsaKey* key)
{
if (!key)

View File

@ -57,6 +57,7 @@ FREERDP_LOCAL rdpRsaKey* key_new(const char* keyfile);
FREERDP_LOCAL rdpRsaKey* key_new_from_content(const char* keycontent,
const char* keyfile);
FREERDP_LOCAL void key_free(rdpRsaKey* key);
FREERDP_LOCAL rdpRsaKey* key_clone(const rdpRsaKey* key);
#define CERTIFICATE_TAG FREERDP_TAG("core.certificate")
#ifdef WITH_DEBUG_CERTIFICATE