<commit_before>#include "system.h"

#include <rpmio.h>
#include <rpmbf.h>
#include <rpmdir.h>
#include <rpmdav.h>
#include <rpmmacro.h>
#include <rpmcb.h>

#define	_RPMPGP_INTERNAL
#include <rpmpgp.h>

#include <poptIO.h>

#include "debug.h"

static int _debug = 0;
static int _printing = 0;

int noNeon;

static rpmbf awol;
static size_t awol_n = 100000;
static double awol_e = 1.0e-4;
static size_t awol_m;
static size_t awol_k;

typedef struct _Astats_s {
    size_t good;
    size_t bad;
} _Astats;

typedef struct _BAstats_s {
    _Astats DSA;
    _Astats RSA;
    _Astats HASH;
    _Astats AWOL;
    _Astats SKIP;
    size_t count;
} _BAstats;

static _BAstats SUM;

static int _spew;
#define	SPEW(_list)	if (_spew) fprintf _list

static uint64_t _keyids[] = {
	0x87CC9EC7F9033421ULL,	/* XXX rpmhkpHashKey: 98 */
	0xc2b079fcf5c75256ULL,
	0x94cd5742e418e3aaULL,
	0xb44269d04f2a6fd2ULL,
	0xda84cbd430c9ecf8ULL,
	0x29d5ba248df56d05ULL,
	0xa520e8f1cba29bf9ULL, /* V2 revocations (and V3 RSA) */
	0x219180cddb42a60eULL,
	0xfd372689897da07aULL,
	0xe1385d4e1cddbca9ULL,
	0x58e727c4c621be0fULL,
	0x6bddfe8e54a2acf1ULL,
	0xb873641b2039b291ULL,
/* --- RHEL6 */
	0x2fa658e0,
	0x37017186,
	0x42193e6b,
	0x897da07a,
	0xdb42a60e,
	0xf21541eb,
	0xfd431d51,
/* --- Fedorable */
	0xd22e77f2,	/* F11 */
	0x57bbccba,	/* F12 */
	0xe8e40fde,	/* F13 */
	0,0
};

/*==============================================================*/

static const char * _pgpSigType2Name(uint32_t sigtype)
{
    return pgpValStr(pgpSigTypeTbl, (rpmuint8_t)sigtype);
}

static const char * _pgpHashAlgo2Name(uint32_t algo)
{
    return pgpValStr(pgpHashTbl, (rpmuint8_t)algo);
}

static const char * _pgpPubkeyAlgo2Name(uint32_t algo)
{
    return pgpValStr(pgpPubkeyTbl, (rpmuint8_t)algo);
}

struct pgpPkt_s {
    pgpTag tag;
    unsigned int pktlen;
    const rpmuint8_t * h;
    unsigned int hlen;
};

static const rpmuint8_t * pgpGrabSubTagVal(const rpmuint8_t * h, size_t hlen,
		rpmuint8_t subtag, /*@null@*/ size_t * tlenp)
{
    const rpmuint8_t * p = h;
    const rpmuint8_t * pend = h + hlen;
    unsigned plen = 0;
    unsigned len;
    rpmuint8_t stag;

    if (tlenp)
	*tlenp = 0;

    while (hlen > 0) {
	len = pgpLen(p, &plen);
	p += len;
	hlen -= len;

	stag = (*p & ~PGPSUBTYPE_CRITICAL);

	if (stag == subtag) {
SPEW((stderr, "\tSUBTAG %02X %p[%2u]\t%s\n", stag, p+1, plen-1, pgpHexStr(p+1, plen-1)));
	    if (tlenp)
		*tlenp = plen-1;
	    return p+1;
	}

	p += plen;
assert(p < pend);
	hlen -= plen;<commit_msg>- hkp: fix: simplify signature subpacket parsing loop termionation.<commit_after>#include "system.h"

#include <rpmio.h>
#include <rpmbf.h>
#include <rpmdir.h>
#include <rpmdav.h>
#include <rpmmacro.h>
#include <rpmcb.h>

#define	_RPMPGP_INTERNAL
#include <rpmpgp.h>

#include <poptIO.h>

#include "debug.h"

static int _debug = 0;
static int _printing = 0;

int noNeon;

static rpmbf awol;
static size_t awol_n = 100000;
static double awol_e = 1.0e-4;
static size_t awol_m;
static size_t awol_k;

typedef struct _Astats_s {
    size_t good;
    size_t bad;
} _Astats;

typedef struct _BAstats_s {
    _Astats DSA;
    _Astats RSA;
    _Astats HASH;
    _Astats AWOL;
    _Astats SKIP;
    size_t count;
} _BAstats;

static _BAstats SUM;

static int _spew;
#define	SPEW(_list)	if (_spew) fprintf _list

static uint64_t _keyids[] = {
	0x87CC9EC7F9033421ULL,	/* XXX rpmhkpHashKey: 98 */
	0xc2b079fcf5c75256ULL,
	0x94cd5742e418e3aaULL,
	0xb44269d04f2a6fd2ULL,
	0xda84cbd430c9ecf8ULL,
	0x29d5ba248df56d05ULL,
	0xa520e8f1cba29bf9ULL, /* V2 revocations (and V3 RSA) */
	0x219180cddb42a60eULL,
	0xfd372689897da07aULL,
	0xe1385d4e1cddbca9ULL,
	0x58e727c4c621be0fULL,
	0x6bddfe8e54a2acf1ULL,
	0xb873641b2039b291ULL,
/* --- RHEL6 */
	0x2fa658e0,
	0x37017186,
	0x42193e6b,
	0x897da07a,
	0xdb42a60e,
	0xf21541eb,
	0xfd431d51,
/* --- Fedorable */
	0xd22e77f2,	/* F11 */
	0x57bbccba,	/* F12 */
	0xe8e40fde,	/* F13 */
	0,0
};

/*==============================================================*/

static const char * _pgpSigType2Name(uint32_t sigtype)
{
    return pgpValStr(pgpSigTypeTbl, (rpmuint8_t)sigtype);
}

static const char * _pgpHashAlgo2Name(uint32_t algo)
{
    return pgpValStr(pgpHashTbl, (rpmuint8_t)algo);
}

static const char * _pgpPubkeyAlgo2Name(uint32_t algo)
{
    return pgpValStr(pgpPubkeyTbl, (rpmuint8_t)algo);
}

struct pgpPkt_s {
    pgpTag tag;
    unsigned int pktlen;
    const rpmuint8_t * h;
    unsigned int hlen;
};

static const rpmuint8_t * pgpGrabSubTagVal(const rpmuint8_t * h, size_t hlen,
		rpmuint8_t subtag, /*@null@*/ size_t * tlenp)
{
    const rpmuint8_t * p = h;
    const rpmuint8_t * pend = h + hlen;
    unsigned plen = 0;
    unsigned len;
    rpmuint8_t stag;

    if (tlenp)
	*tlenp = 0;

    while (p < pend) {
	len = pgpLen(p, &plen);
	p += len;

	stag = (*p & ~PGPSUBTYPE_CRITICAL);

	if (stag == subtag) {
SPEW((stderr, "\tSUBTAG %02X %p[%2u]\t%s\n", stag, p+1, plen-1, pgpHexStr(p+1, plen-1)));
	    if (tlenp)
		*tlenp = plen-1;
	    return p+1;
	}
	p += plen;
{'fraction_non_alphanumeric': 0.14251401120896717, 'fraction_numerical': 0.10028022417934347, 'mean_word_length': 4.032225579053374, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1245542', 'n_tokens_mistral': 2661, 'n_tokens_neox': 2391, 'n_words': 465}