}
-pgpArmor pgpReadPkts(const char * fn, uint8_t ** pkt, size_t * pktlen)
+static pgpArmor decodePkts(uint8_t *b, uint8_t **pkt, size_t *pktlen)
{
- uint8_t * b = NULL;
- ssize_t blen;
const char * enc = NULL;
const char * crcenc = NULL;
uint8_t * dec;
char * t, * te;
int pstate = 0;
pgpArmor ec = PGPARMOR_ERR_NO_BEGIN_PGP; /* XXX assume failure */
- int rc;
-
- rc = rpmioSlurp(fn, &b, &blen);
- if (rc || b == NULL || blen <= 0) {
- goto exit;
- }
-
if (pgpIsPkt(b)) {
#ifdef NOTYET /* XXX ASCII Pubkeys only, please. */
ec = 0; /* XXX fish out pkt type. */
#define TOKEQ(_s, _tok) (rstreqn((_s), (_tok), sizeof(_tok)-1))
for (t = (char *)b; t && *t; t = te) {
+ int rc;
if ((te = strchr(t, '\n')) == NULL)
te = t + strlen(t);
else
ec = PGPARMOR_ERR_CRC_CHECK;
goto exit;
}
- b = _free(b);
- b = dec;
- blen = declen;
+ if (pkt) *pkt = dec;
+ if (pktlen) *pktlen = declen;
ec = PGPARMOR_PUBKEY; /* XXX ASCII Pubkeys only, please. */
goto exit;
break;
ec = PGPARMOR_NONE;
exit:
- if (ec > PGPARMOR_NONE && pkt)
- *pkt = b;
- else if (b != NULL)
- b = _free(b);
- if (pktlen)
- *pktlen = blen;
+ return ec;
+}
+
+pgpArmor pgpReadPkts(const char * fn, uint8_t ** pkt, size_t * pktlen)
+{
+ uint8_t * b = NULL;
+ ssize_t blen;
+ pgpArmor ec = PGPARMOR_ERR_NO_BEGIN_PGP; /* XXX assume failure */
+ int rc = rpmioSlurp(fn, &b, &blen);
+ if (rc == 0 && b != NULL && blen > 0) {
+ ec = decodePkts(b, pkt, pktlen);
+ }
+ free(b);
+ return ec;
+}
+
+pgpArmor pgpParsePkts(const char *armor, uint8_t ** pkt, size_t * pktlen)
+{
+ pgpArmor ec = PGPARMOR_ERR_NO_BEGIN_PGP; /* XXX assume failure */
+ if (armor && strlen(armor) > 0) {
+ uint8_t *b = (uint8_t*) xstrdup(armor);
+ ec = decodePkts(b, pkt, pktlen);
+ free(b);
+ }
return ec;
}
pgpArmor pgpReadPkts(const char * fn, uint8_t ** pkt, size_t * pktlen);
/** \ingroup rpmpgp
+ * Parse armored OpenPGP packets from memory.
+ * @param armor armored OpenPGP packet string
+ * @retval pkt dearmored OpenPGP packet(s) (malloced)
+ * @retval pktlen dearmored OpenPGP packet(s) length in bytes
+ * @return type of armor found
+ */
+pgpArmor pgpParsePkts(const char *armor, uint8_t ** pkt, size_t * pktlen);
+
+/** \ingroup rpmpgp
* Wrap a OpenPGP packets in ascii armor for transport.
* @param atype type of armor
* @param s binary pkt data