From 54601532648f6f36808c54597509b43cd435d4c6 Mon Sep 17 00:00:00 2001 From: David Shaw Date: Thu, 9 Mar 2006 03:35:26 +0000 Subject: [PATCH] * mainproc.c (get_pka_address), keylist.c (show_notation): Remove duplicate code by using notation functions. --- g10/ChangeLog | 3 ++ g10/keylist.c | 92 +++++++++++++++++++++----------------------------- g10/mainproc.c | 53 +++++++++++------------------ 3 files changed, 60 insertions(+), 88 deletions(-) diff --git a/g10/ChangeLog b/g10/ChangeLog index 345dfdda8..2fd0b8078 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,5 +1,8 @@ 2006-03-08 David Shaw + * 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 (keygen_add_notations): Provide printable text for non-human-readable notation values. diff --git a/g10/keylist.c b/g10/keylist.c index 295e6dca5..19f3d3f62 100644 --- a/g10/keylist.c +++ b/g10/keylist.c @@ -332,71 +332,55 @@ show_keyserver_url(PKT_signature *sig,int indent,int mode) void 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; + struct notation *nd,*notations; if(which==0) which=3; + notations=sig_to_notation(sig); + /* There may be multiple notations in the same sig. */ + for(nd=notations;nd;nd=nd->next) + { + if(mode!=2) + { + int has_at=!!strchr(nd->name,'@'); - while((p=enum_sig_subpkt(sig->hashed,SIGSUBPKT_NOTATION,&len,&seq,&crit))) - if(len>=8) - { - int n1,n2; + if((which&1 && !has_at) || (which&2 && has_at)) + { + int i; + const char *str; - n1=(p[4]<<8)|p[5]; - n2=(p[6]<<8)|p[7]; + for(i=0;iflags.critical) + str=_("Critical signature notation: "); + else + str=_("Signature notation: "); + if(mode) + log_info("%s",str); + else + printf("%s",str); + /* This is all UTF8 */ + print_utf8_string(fp,nd->name,strlen(nd->name)); + fprintf(fp,"="); + print_utf8_string(fp,nd->value,strlen(nd->value)); + fprintf(fp,"\n"); + } + } - if(mode!=2) - { - int has_at=!!memchr(p+8,'@',n1); + if(mode) + { + write_status_buffer(STATUS_NOTATION_NAME, + nd->name,strlen(nd->name),0); + write_status_buffer(STATUS_NOTATION_DATA, + nd->value,strlen(nd->value),50); + } + } - if((which&1 && !has_at) || (which&2 && has_at)) - { - int i; - const char *str; - - for(i=0;ihashed, SIGSUBPKT_NOTATION, - &len, &seq, NULL))) + notation=sig_to_notation(sig); + + for(nd=notation;nd;nd=nd->next) { - if (len < 8) - 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)) + if(strcmp(nd->name,"pka-address@gnupg.org")!=0) continue; /* Not the notation we want. */ - p += n1; - if (n2 < 3) - continue; /* Impossible email address. */ - if (pka) - break; /* For now we only use the first valid PKA notation. In - future we might want to keep additional PKA - notations in a linked list. */ - - pka = xmalloc (sizeof *pka + n2); - pka->valid = 0; - pka->checked = 0; - pka->uri = NULL; - memcpy (pka->email, p, n2); - pka->email[n2] = 0; - - if (!is_valid_mailbox (pka->email)) - { - /* We don't accept invalid mail addresses. */ - xfree (pka); - pka = NULL; - } + /* For now we only use the first valid PKA notation. In future + we might want to keep additional PKA notations in a linked + list. */ + if (is_valid_mailbox (pka->email)) + { + pka = xmalloc (sizeof *pka + strlen(nd->value)); + pka->valid = 0; + pka->checked = 0; + pka->uri = NULL; + strcpy (pka->email, nd->value); + break; + } } + free_notation(notation); + return pka; }