diff --git a/rpmio/rpmpgp.c b/rpmio/rpmpgp.c index 589322267e..cf97773cd0 100644 --- a/rpmio/rpmpgp.c +++ b/rpmio/rpmpgp.c @@ -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; diff --git a/rpmio/rpmpgp.h b/rpmio/rpmpgp.h index 4264434ee3..e4966ed4ce 100644 --- a/rpmio/rpmpgp.h +++ b/rpmio/rpmpgp.h @@ -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