1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-23 10:29:58 +01:00

* mainproc.c (get_pka_address), keylist.c (show_notation): Remove

duplicate code by using notation functions.
This commit is contained in:
David Shaw 2006-03-09 03:35:26 +00:00
parent cc9a71c6ce
commit 5460153264
3 changed files with 60 additions and 88 deletions

View File

@ -1,5 +1,8 @@
2006-03-08 David Shaw <dshaw@jabberwocky.com> 2006-03-08 David Shaw <dshaw@jabberwocky.com>
* mainproc.c (get_pka_address), keylist.c (show_notation): Remove
duplicate code by using notation functions.
* packet.h, build-packet.c (sig_to_notation), keygen.c * packet.h, build-packet.c (sig_to_notation), keygen.c
(keygen_add_notations): Provide printable text for (keygen_add_notations): Provide printable text for
non-human-readable notation values. non-human-readable notation values.

View File

@ -332,33 +332,20 @@ show_keyserver_url(PKT_signature *sig,int indent,int mode)
void void
show_notation(PKT_signature *sig,int indent,int mode,int which) show_notation(PKT_signature *sig,int indent,int mode,int which)
{ {
const byte *p;
size_t len;
int seq=0,crit;
FILE *fp=mode?log_stream():stdout; FILE *fp=mode?log_stream():stdout;
struct notation *nd,*notations;
if(which==0) if(which==0)
which=3; which=3;
notations=sig_to_notation(sig);
/* There may be multiple notations in the same sig. */ /* There may be multiple notations in the same sig. */
for(nd=notations;nd;nd=nd->next)
while((p=enum_sig_subpkt(sig->hashed,SIGSUBPKT_NOTATION,&len,&seq,&crit)))
if(len>=8)
{ {
int n1,n2;
n1=(p[4]<<8)|p[5];
n2=(p[6]<<8)|p[7];
if(8+n1+n2!=len)
{
log_info(_("WARNING: invalid notation data found\n"));
continue;
}
if(mode!=2) if(mode!=2)
{ {
int has_at=!!memchr(p+8,'@',n1); int has_at=!!strchr(nd->name,'@');
if((which&1 && !has_at) || (which&2 && has_at)) if((which&1 && !has_at) || (which&2 && has_at))
{ {
@ -368,8 +355,7 @@ show_notation(PKT_signature *sig,int indent,int mode,int which)
for(i=0;i<indent;i++) for(i=0;i<indent;i++)
putchar(' '); putchar(' ');
/* This is UTF8 */ if(nd->flags.critical)
if(crit)
str=_("Critical signature notation: "); str=_("Critical signature notation: ");
else else
str=_("Signature notation: "); str=_("Signature notation: ");
@ -377,26 +363,24 @@ show_notation(PKT_signature *sig,int indent,int mode,int which)
log_info("%s",str); log_info("%s",str);
else else
printf("%s",str); printf("%s",str);
print_utf8_string(fp,p+8,n1); /* This is all UTF8 */
print_utf8_string(fp,nd->name,strlen(nd->name));
fprintf(fp,"="); fprintf(fp,"=");
print_utf8_string(fp,nd->value,strlen(nd->value));
if(*p&0x80)
print_utf8_string(fp,p+8+n1,n2);
else
fprintf(fp,"[ %s ]",_("not human readable"));
fprintf(fp,"\n"); fprintf(fp,"\n");
} }
} }
if(mode) if(mode)
{ {
write_status_buffer ( STATUS_NOTATION_NAME, p+8 , n1, 0 ); write_status_buffer(STATUS_NOTATION_NAME,
write_status_buffer ( STATUS_NOTATION_DATA, p+8+n1, n2, 50 ); nd->name,strlen(nd->name),0);
write_status_buffer(STATUS_NOTATION_DATA,
nd->value,strlen(nd->value),50);
} }
} }
else
log_info(_("WARNING: invalid notation data found\n")); free_notation(notations);
} }
static void static void

View File

@ -1334,46 +1334,31 @@ do_proc_packets( CTX c, IOBUF a )
static pka_info_t * static pka_info_t *
get_pka_address (PKT_signature *sig) get_pka_address (PKT_signature *sig)
{ {
const unsigned char *p;
size_t len, n1, n2;
int seq = 0;
pka_info_t *pka = NULL; pka_info_t *pka = NULL;
struct notation *nd,*notation;
while ((p = enum_sig_subpkt (sig->hashed, SIGSUBPKT_NOTATION, notation=sig_to_notation(sig);
&len, &seq, NULL)))
for(nd=notation;nd;nd=nd->next)
{ {
if (len < 8) if(strcmp(nd->name,"pka-address@gnupg.org")!=0)
continue; /* Notation packet is too short. */
n1 = (p[4]<<8)|p[5];
n2 = (p[6]<<8)|p[7];
if (8 + n1 + n2 != len)
continue; /* Length fields of notation packet are inconsistent. */
p += 8;
if (n1 != 21 || memcmp (p, "pka-address@gnupg.org", 21))
continue; /* Not the notation we want. */ continue; /* Not the notation we want. */
p += n1;
if (n2 < 3)
continue; /* Impossible email address. */
if (pka) /* For now we only use the first valid PKA notation. In future
break; /* For now we only use the first valid PKA notation. In we might want to keep additional PKA notations in a linked
future we might want to keep additional PKA list. */
notations in a linked list. */ if (is_valid_mailbox (pka->email))
{
pka = xmalloc (sizeof *pka + n2); pka = xmalloc (sizeof *pka + strlen(nd->value));
pka->valid = 0; pka->valid = 0;
pka->checked = 0; pka->checked = 0;
pka->uri = NULL; pka->uri = NULL;
memcpy (pka->email, p, n2); strcpy (pka->email, nd->value);
pka->email[n2] = 0; break;
}
}
if (!is_valid_mailbox (pka->email)) free_notation(notation);
{
/* We don't accept invalid mail addresses. */
xfree (pka);
pka = NULL;
}
}
return pka; return pka;
} }