]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
Remove duplicit error check in engine key loading 242/head
authorPetr Menšík <pemensik@redhat.com>
Fri, 19 Jul 2024 13:45:09 +0000 (15:45 +0200)
committerPetr Menšík <pemensik@redhat.com>
Fri, 19 Jul 2024 13:45:09 +0000 (15:45 +0200)
ldns_key_set_algorithm cannot change state of the key. Check it only
once, return specialized error code if failed.

keys.c

diff --git a/keys.c b/keys.c
index b0927391eaefe9d6446a48437170d0681ec085f6..8125de3f6b9fd0e77d1f2c4f3c4b205a7f98dd0d 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -120,16 +120,12 @@ ldns_key_new_frm_engine(ldns_key **key, ENGINE *e, char *key_id, ldns_algorithm
        k = ldns_key_new();
         if(!k) return LDNS_STATUS_MEM_ERR;
 #ifndef S_SPLINT_S
-       k->_key.key = ENGINE_load_private_key(e, key_id, UI_OpenSSL(), NULL);
-        if(!k->_key.key) {
-                ldns_key_free(k);
-                return LDNS_STATUS_ERR;
-        }
        ldns_key_set_algorithm(k, (ldns_signing_algorithm) alg);
+       k->_key.key = ENGINE_load_private_key(e, key_id, UI_OpenSSL(), NULL);
        if (!k->_key.key) {
                 ldns_key_free(k);
                return LDNS_STATUS_ENGINE_KEY_NOT_LOADED;
-       } 
+       }
 #endif /* splint */
        *key = k;
        return LDNS_STATUS_OK;