Parse pubkey parameters on rpmPubkeyNew() already and store results

- Yet more pre-requisites for separating key and signature management.
  In addition this gains us more thorough initial sanity checking and
  will allow reusing the parameters instead of having to parse
  the same packets over and over again on every single verification
  against this key. Unfortunately rpmKeyringLookup() is so braindead
  it prevents us from doing this right now, we'll need a better
  interface to take advantage of the stored pgp key parameters.
This commit is contained in:
Panu Matilainen 2011-11-09 11:59:31 +02:00
parent 345a061240
commit 564242f23b
1 changed files with 7 additions and 0 deletions

View File

@ -15,6 +15,7 @@ struct rpmPubkey_s {
uint8_t *pkt;
size_t pktlen;
pgpKeyID_t keyid;
pgpDigParams pgpkey;
int nrefs;
};
@ -124,6 +125,7 @@ exit:
rpmPubkey rpmPubkeyNew(const uint8_t *pkt, size_t pktlen)
{
rpmPubkey key = NULL;
pgpDigParams pgpkey = NULL;
pgpKeyID_t keyid;
if (pkt == NULL || pktlen == 0)
@ -132,9 +134,13 @@ rpmPubkey rpmPubkeyNew(const uint8_t *pkt, size_t pktlen)
if (pgpPubkeyFingerprint(pkt, pktlen, keyid))
goto exit;
if (pgpPrtParams(pkt, pktlen, PGPTAG_PUBLIC_KEY, &pgpkey))
goto exit;
key = xcalloc(1, sizeof(*key));
key->pkt = xmalloc(pktlen);
key->pktlen = pktlen;
key->pgpkey = pgpkey;
key->nrefs = 0;
memcpy(key->pkt, pkt, pktlen);
memcpy(key->keyid, keyid, sizeof(keyid));
@ -151,6 +157,7 @@ rpmPubkey rpmPubkeyFree(rpmPubkey key)
if (key->nrefs > 1)
return rpmPubkeyUnlink(key);
pgpDigParamsFree(key->pgpkey);
free(key->pkt);
free(key);
return NULL;