Skip to content

Commit

Permalink
Use rpmKeyringModify with RPMKEYRING_MERGE
Browse files Browse the repository at this point in the history
Simplify rpmtxnImportPubkey
No functional change
  • Loading branch information
ffesti committed Nov 26, 2024
1 parent 8eff293 commit 3938a82
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions lib/rpmts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ rpmRC rpmtxnImportPubkey(rpmtxn txn, const unsigned char * pkt, size_t pktlen)
rpmRC rc = RPMRC_FAIL; /* assume failure */
char *lints = NULL;
rpmPubkey pubkey = NULL;
rpmPubkey oldkey = NULL;
rpmKeyring keyring = NULL;
int krc;

Expand Down Expand Up @@ -353,34 +352,20 @@ rpmRC rpmtxnImportPubkey(rpmtxn txn, const unsigned char * pkt, size_t pktlen)
if ((pubkey = rpmPubkeyNew(pkt, pktlen)) == NULL)
goto exit;

oldkey = rpmKeyringLookupKey(keyring, pubkey);
if (oldkey) {
rpmPubkey mergedkey = NULL;
if (rpmPubkeyMerge(oldkey, pubkey, &mergedkey) != RPMRC_OK)
goto exit;
if (!mergedkey) {
rc = RPMRC_OK; /* already have key */
goto exit;
}
rpmPubkeyFree(pubkey);
pubkey = mergedkey;
}

krc = rpmKeyringModify(keyring, pubkey, oldkey ? RPMKEYRING_REPLACE : RPMKEYRING_ADD);
krc = rpmKeyringModify(keyring, pubkey, RPMKEYRING_MERGE);
if (krc < 0)
goto exit;

/* If we dont already have the key, make a persistent record of it */
if (krc == 0) {
rc = ts->keystore->import_key(txn, pubkey, oldkey ? 1 : 0);
rc = ts->keystore->import_key(txn, pubkey, 1);
} else {
rc = RPMRC_OK; /* already have key */
}

exit:
/* Clean up. */
rpmPubkeyFree(pubkey);
rpmPubkeyFree(oldkey);

rpmKeyringFree(keyring);
return rc;
Expand Down

0 comments on commit 3938a82

Please sign in to comment.