Skip to content

Commit

Permalink
Add pgpPubKeyCertLen() to get the length of the pub key certificate.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lubos Kardos committed Jul 14, 2015
1 parent 5b4805d commit 168a6a2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
23 changes: 23 additions & 0 deletions rpmio/rpmpgp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,29 @@ pgpArmor pgpParsePkts(const char *armor, uint8_t ** pkt, size_t * pktlen)
return ec;
}

int pgpPubKeyCertLen(const uint8_t *pkts, size_t pktslen, size_t *certlen)
{
const uint8_t *p = pkts;
const uint8_t *pend = pkts + pktslen;
struct pgpPkt pkt;

while (p < pend) {
if (decodePkt(p, (pend - p), &pkt))
return -1;

if (pkt.tag == PGPTAG_PUBLIC_KEY && pkts != p) {
*certlen = p - pkts;
return 0;
}

p += (pkt.body - pkt.head) + pkt.blen;
}

*certlen = pktslen;

return 0;
}

char * pgpArmorWrap(int atype, const unsigned char * s, size_t ns)
{
char *buf = NULL, *val = NULL;
Expand Down
14 changes: 14 additions & 0 deletions rpmio/rpmpgp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,20 @@ pgpArmor pgpReadPkts(const char * fn, uint8_t ** pkt, size_t * pktlen);
*/
pgpArmor pgpParsePkts(const char *armor, uint8_t ** pkt, size_t * pktlen);

/** \ingroup rpmpgp
* Return a length of the first public key certificate in a buffer given
* by pkts that contains one or more certificates. A public key certificate
* consits of packets like Public key packet, User ID packet and so on.
* In a buffer every certificate starts with Public key packet and it ends
* with the start of the next certificate or with the end of the buffer.
*
* @param pkts pointer to a buffer with certificates
* @param pktslen length of the buffer with certificates
* @param certlen length of the first certificate in the buffer
* @return 0 on success
*/
int pgpPubKeyCertLen(const uint8_t *pkts, size_t pktslen, size_t *certlen);

/** \ingroup rpmpgp
* Wrap a OpenPGP packets in ascii armor for transport.
* @param atype type of armor
Expand Down

0 comments on commit 168a6a2

Please sign in to comment.