From 30764edd12716a425621862e39c4b061e0dd6bdc Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Wed, 28 Jan 2009 21:45:12 -0800 Subject: [PATCH] rsaenh: Use helper function to install keys. --- dlls/rsaenh/rsaenh.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/dlls/rsaenh/rsaenh.c b/dlls/rsaenh/rsaenh.c index 4dc8aa6db00..c775082936c 100644 --- a/dlls/rsaenh/rsaenh.c +++ b/dlls/rsaenh/rsaenh.c @@ -2442,6 +2442,23 @@ BOOL WINAPI RSAENH_CPExportKey(HCRYPTPROV hProv, HCRYPTKEY hKey, HCRYPTKEY hPubK pbData, pdwDataLen); } +/****************************************************************************** + * release_and_install_key [Internal] + * + * Release an existing key, if present, and replaces it with a new one. + * + * PARAMS + * hProv [I] Key container into which the key is to be imported. + * src [I] Key which will replace *dest + * dest [I] Points to key to be released and replaced with src + */ +static void release_and_install_key(HCRYPTPROV hProv, HCRYPTKEY src, + HCRYPTKEY *dest) +{ + RSAENH_CPDestroyKey(hProv, *dest); + copy_handle(&handle_table, src, RSAENH_MAGIC_KEY, dest); +} + /****************************************************************************** * CPImportKey (RSAENH.@) * @@ -2517,16 +2534,14 @@ BOOL WINAPI RSAENH_CPImportKey(HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDat case AT_SIGNATURE: case CALG_RSA_SIGN: TRACE("installing signing key\n"); - RSAENH_CPDestroyKey(hProv, pKeyContainer->hSignatureKeyPair); - copy_handle(&handle_table, *phKey, RSAENH_MAGIC_KEY, - &pKeyContainer->hSignatureKeyPair); + release_and_install_key(hProv, *phKey, + &pKeyContainer->hSignatureKeyPair); break; case AT_KEYEXCHANGE: case CALG_RSA_KEYX: TRACE("installing key exchange key\n"); - RSAENH_CPDestroyKey(hProv, pKeyContainer->hKeyExchangeKeyPair); - copy_handle(&handle_table, *phKey, RSAENH_MAGIC_KEY, - &pKeyContainer->hKeyExchangeKeyPair); + release_and_install_key(hProv, *phKey, + &pKeyContainer->hKeyExchangeKeyPair); break; } } @@ -2558,9 +2573,8 @@ BOOL WINAPI RSAENH_CPImportKey(HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDat case AT_KEYEXCHANGE: case CALG_RSA_KEYX: TRACE("installing public key\n"); - RSAENH_CPDestroyKey(hProv, pKeyContainer->hKeyExchangeKeyPair); - copy_handle(&handle_table, *phKey, RSAENH_MAGIC_KEY, - &pKeyContainer->hKeyExchangeKeyPair); + release_and_install_key(hProv, *phKey, + &pKeyContainer->hKeyExchangeKeyPair); break; } }