Skip to content

Commit

Permalink
Refactor pgpDigParams construction to helper function
Browse files Browse the repository at this point in the history
No functional changes, just to reduce code duplication and needed by
the following commits.
  • Loading branch information
pmatilai committed Sep 30, 2021
1 parent db7ab0a commit e3dd156
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions rpmio/rpmpgp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,13 @@ unsigned int pgpDigParamsAlgo(pgpDigParams digp, unsigned int algotype)
return algo;
}

static pgpDigParams pgpDigParamsNew(uint8_t tag)
{
pgpDigParams digp = xcalloc(1, sizeof(*digp));
digp->tag = tag;
return digp;
}

int pgpPrtParams(const uint8_t * pkts, size_t pktlen, unsigned int pkttype,
pgpDigParams * ret)
{
Expand All @@ -1072,8 +1079,7 @@ int pgpPrtParams(const uint8_t * pkts, size_t pktlen, unsigned int pkttype,
if (pkttype && pkt.tag != pkttype) {
break;
} else {
digp = xcalloc(1, sizeof(*digp));
digp->tag = pkt.tag;
digp = pgpDigParamsNew(pkt.tag);
}
}

Expand Down Expand Up @@ -1121,8 +1127,7 @@ int pgpPrtParamsSubkeys(const uint8_t *pkts, size_t pktlen,
digps = xrealloc(digps, alloced * sizeof(*digps));
}

digps[count] = xcalloc(1, sizeof(**digps));
digps[count]->tag = PGPTAG_PUBLIC_SUBKEY;
digps[count] = pgpDigParamsNew(PGPTAG_PUBLIC_SUBKEY);
/* Copy UID from main key to subkey */
digps[count]->userid = xstrdup(mainkey->userid);

Expand Down

0 comments on commit e3dd156

Please sign in to comment.