-#include "ll.h"
-#include "stats.h"
-
-int parse_subpackets(unsigned char *data, bool html)
-{
- int offset = 0;
- int length = 0;
- int packetlen = 0;
- char *uid;
-
- assert(data != NULL);
-
- length = (data[0] << 8) + data[1] + 2;
-
- offset = 2;
- while (offset < length) {
- packetlen = data[offset++];
- if (packetlen > 191 && packetlen < 255) {
- packetlen = ((packetlen - 192) << 8) +
- data[offset++] + 192;
- } else if (packetlen == 255) {
- packetlen = data[offset++];
- packetlen <<= 8;
- packetlen = data[offset++];
- packetlen <<= 8;
- packetlen = data[offset++];
- packetlen <<= 8;
- packetlen = data[offset++];
- }
- switch (data[offset]) {
- case 2:
- /*
- * Signature creation time. Might want to output this?
- */
- break;
- case 16:
- uid = keyid2uid(
- ((uint64_t) data[offset+packetlen - 8] << 56) +
- ((uint64_t) data[offset+packetlen - 7] << 48) +
- ((uint64_t) data[offset+packetlen - 6] << 40) +
- ((uint64_t) data[offset+packetlen - 5] << 32) +
- ((uint64_t) data[offset+packetlen - 4] << 24) +
- ((uint64_t) data[offset+packetlen - 3] << 16) +
- ((uint64_t) data[offset+packetlen - 2] << 8) +
- data[offset+packetlen - 1]);
- if (html && uid != NULL) {
- printf("sig <a href=\"lookup?op=get&"
- "search=%02X%02X%02X%02X\">"
- "%02X%02X%02X%02X</a> "
- "<a href=\"lookup?op=vindex&"
- "search=0x%02X%02X%02X%02X\">"
- "%s</a>\n",
- data[offset+packetlen - 4],
- data[offset+packetlen - 3],
- data[offset+packetlen - 2],
- data[offset+packetlen - 1],
- data[offset+packetlen - 4],
- data[offset+packetlen - 3],
- data[offset+packetlen - 2],
- data[offset+packetlen - 1],
-
- data[offset+packetlen - 4],
- data[offset+packetlen - 3],
- data[offset+packetlen - 2],
- data[offset+packetlen - 1],
- txt2html(uid));
- } else if (html && uid == NULL) {
- printf("sig "
- "%02X%02X%02X%02X "
- "[User id not found]\n",
- data[offset+packetlen - 4],
- data[offset+packetlen - 3],
- data[offset+packetlen - 2],
- data[offset+packetlen - 1]);
- } else {
- printf("sig %02X%02X%02X%02X"
- " %s\n",
- data[offset+packetlen - 4],
- data[offset+packetlen - 3],
- data[offset+packetlen - 2],
- data[offset+packetlen - 1],
- (uid != NULL) ? uid :
- "[User id not found]");
- }
- break;
- default:
- /*
- * We don't care about unrecognized packets unless bit
- * 7 is set in which case we prefer an error than
- * ignoring it.
- */
- assert(!(data[offset] & 0x80));
- }
- offset += packetlen;
- }
-
- return length;
-}