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.
This commit is contained in:
Thomas Haller 2018-08-29 16:12:40 +02:00
parent c366c155f1
commit 3536960eb7

View file

@ -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,