Skip to content

Commit

Permalink
* parse_subpacket() are split into parse_signature_subpacket() and
Browse files Browse the repository at this point in the history
  parse_userattr_subpacket(). A bug of length calculation is fixed.
* The critical bit of the signature subpackets are supported.
        Peter Palfrader <peter>
  • Loading branch information
kazu-yamamoto committed Feb 19, 2010
1 parent 82dafed commit 96e36c3
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 34 deletions.
7 changes: 7 additions & 0 deletions CHANGES
@@ -1,5 +1,12 @@
Change Log

0.22 2004/01/23

* parse_subpacket() are split into parse_signature_subpacket() and
parse_userattr_subpacket(). A bug of length calculation is fixed.
* The critical bit of the signature subpackets are supported.
Peter Palfrader <peter>

0.21 2004/01/13

* Removing compiler warnings.
Expand Down
84 changes: 56 additions & 28 deletions packet.c
Expand Up @@ -18,6 +18,9 @@ private int is_partial(int);
#define OLD_TAG_SHIFT 2
#define OLD_LEN_MASK 0x03

#define CRITICAL_BIT 0x80
#define CRITICAL_MASK 0x7f

private char *
TAG[] = {
"Reserved",
Expand Down Expand Up @@ -366,33 +369,57 @@ parse_packet(void)
}

public void
parse_subpacket(char *prefix, int tlen, int type)
parse_signature_subpacket(char *prefix, int tlen)
{
int len, sub, slen;
char **exptbl;
funcptr *sw;
int len, subtype, critical;

switch (type) {
case 1:
slen = SIGSUB_NUM;
exptbl = SIGSUB;
sw = sigsub_func;
break;
case 2:
slen = UATSUB_NUM;
exptbl = UATSUB;
sw = uatsub_func;
break;
default:
warn_exit("unknown type (%d) for subpacket.", type);
break;
while (tlen > 0) {
len = Getc();
if (len < 192)
tlen--;
else if (len < 255) {
len = ((len - 192) << 8) + Getc() + 192;
tlen -= 2;
} else if (len == 255) {
len = Getc() << 24;
len |= Getc() << 16;
len |= Getc() << 8;
len |= Getc();
tlen -= 5;
}
tlen -= len;
subtype = Getc(); /* len includes this field byte */
len--;

/* Handle critical bit of subpacket type */
critical = NO;
if (subtype & CRITICAL_BIT) {
critical = YES;
subtype &= CRITICAL_MASK;
}

if (subtype < SIGSUB_NUM)
printf("\t%s: %s%s", prefix, SIGSUB[subtype], critical ? "(critical)" : "");
else
printf("\t%s: unknown(sub %d%s)", prefix, subtype, critical ? ", critical" : "");
printf("(%d bytes)\n", len);
if (subtype < SIGSUB_NUM && sigsub_func[subtype] != NULL)
(*sigsub_func[subtype])(len);
else
skip(len);
}

}

public void
parse_userattr_subpacket(char *prefix, int tlen)
{
int len, subtype;

while (tlen > 0) {
len = Getc();
if (len < 192)
tlen --;
else if (len < 223) {
tlen--;
else if (len < 255) {
len = ((len - 192) << 8) + Getc() + 192;
tlen -= 2;
} else if (len == 255) {
Expand All @@ -403,15 +430,16 @@ parse_subpacket(char *prefix, int tlen, int type)
tlen -= 5;
}
tlen -= len;
sub = Getc(); /* len includes this field byte */
len --;
if (sub < slen)
printf("\t%s: %s", prefix, exptbl[sub]);
subtype = Getc();
len--; /* len includes this field byte */

if (subtype < UATSUB_NUM)
printf("\t%s: %s", prefix, UATSUB[subtype]);
else
printf("\t%s: unknown(sub %d)", prefix, sub);
printf("\t%s: unknown(sub %d)", prefix, subtype);
printf("(%d bytes)\n", len);
if (sub < slen && sw[sub] != NULL)
(*sw[sub])(len);
if (subtype < UATSUB_NUM && uatsub_func[subtype] != NULL)
(*uatsub_func[subtype])(len);
else
skip(len);
}
Expand Down
2 changes: 1 addition & 1 deletion pgpdump.c
Expand Up @@ -13,7 +13,7 @@ int mflag;
int pflag;
int uflag;

private char *pgpdump_version = "0.21, Copyright (C) 1998-2004 Kazu Yamamoto";
private char *pgpdump_version = "0.22, Copyright (C) 1998-2004 Kazu Yamamoto";
private char *prog;

private char *getprog(void);
Expand Down
3 changes: 2 additions & 1 deletion pgpdump.h
Expand Up @@ -66,7 +66,8 @@ public void Getc_resetlen(void);
*/

public void parse_packet(void);
public void parse_subpacket(char *, int, int);
public void parse_signature_subpacket(char *, int);
public void parse_userattr_subpacket(char *, int);

/*
* types.c
Expand Down
4 changes: 2 additions & 2 deletions signature.c
Expand Up @@ -168,10 +168,10 @@ new_Signature_Packet(int len)
hash_algs(Getc());
hsplen = Getc() * 256;
hsplen += Getc();
parse_subpacket("Hashed Sub", hsplen, 1);
parse_signature_subpacket("Hashed Sub", hsplen);
usplen = Getc() * 256;
usplen += Getc();
parse_subpacket("Sub", usplen, 1);
parse_signature_subpacket("Sub", usplen);
hash2();
signature_multi_precision_integer(pub, len - 9 - hsplen - usplen);
}
Expand Down
2 changes: 1 addition & 1 deletion tagfuncs.c
Expand Up @@ -178,7 +178,7 @@ User_ID_Packet(int len)
public void
User_Attribute_Packet(int len)
{
parse_subpacket("Sub", len, 2);
parse_userattr_subpacket("Sub", len);
}

public void
Expand Down
2 changes: 1 addition & 1 deletion uatfunc.c
Expand Up @@ -15,7 +15,7 @@ image_attribute(int len)
if (hver == 1) {
int enc = Getc();
printf("\t\tImage encoding - %s(enc %d)\n",
enc==1 ? "JPEG" : "Unknown",
enc == 1 ? "JPEG" : "Unknown",
enc);
printf("\t\tImage data(%d bytes)\n", len - hlen);
skip(len - 4);
Expand Down

0 comments on commit 96e36c3

Please sign in to comment.