From 3536960eb766bb7d113a61db0ad2ae27e052bc9b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 29 Aug 2018 16:12:40 +0200 Subject: [PATCH] libnm/crypto: minor cleanup confusing comment in crypto_decrypt_openssl_private_key_data() the comment and code made it sound like parse_old_openssl_key_file() would set @key_type if the parsing was only done partially. That is not the case, @key_type is only set, if parsing was successful. Adjust the code. While at it, don't require the caller to initialize @out_key_type. It's just an enum, if we care to always set it, just do it. --- libnm-core/crypto.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libnm-core/crypto.c b/libnm-core/crypto.c index 319f8055fe..13afd4698f 100644 --- a/libnm-core/crypto.c +++ b/libnm-core/crypto.c @@ -487,17 +487,13 @@ crypto_decrypt_openssl_private_key_data (const guint8 *data, char *cipher = NULL; g_return_val_if_fail (data != NULL, NULL); - if (out_key_type) - g_return_val_if_fail (*out_key_type == NM_CRYPTO_KEY_TYPE_UNKNOWN, NULL); + + NM_SET_OUT (out_key_type, NM_CRYPTO_KEY_TYPE_UNKNOWN); if (!crypto_init (error)) return NULL; parsed = parse_old_openssl_key_file (data, data_len, &key_type, &cipher, &iv, NULL); - /* return the key type even if decryption failed */ - if (out_key_type) - *out_key_type = key_type; - if (!parsed) { g_set_error (error, NM_CRYPTO_ERROR, NM_CRYPTO_ERROR_INVALID_DATA, @@ -505,6 +501,8 @@ crypto_decrypt_openssl_private_key_data (const guint8 *data, return NULL; } + NM_SET_OUT (out_key_type, key_type); + if (password) { if (!cipher || !iv) { g_set_error (error, NM_CRYPTO_ERROR,