diff --git a/g10/build-packet.c b/g10/build-packet.c index 8388ce3e4..623533f7c 100644 --- a/g10/build-packet.c +++ b/g10/build-packet.c @@ -1188,8 +1188,83 @@ string_to_notation(const char *string,int is_utf8) return NULL; } -/* Return all of the notations stored in the signature SIG. The - caller must free them using free_notation(). */ +/* Like string_to_notation, but store opaque data rather than human + readable data. */ +struct notation * +blob_to_notation(const char *name, const char *data, size_t len) +{ + const char *s; + int saw_at=0; + struct notation *notation; + + notation=xmalloc_clear(sizeof(*notation)); + + if(*name=='-') + { + notation->flags.ignore=1; + name++; + } + + if(*name=='!') + { + notation->flags.critical=1; + name++; + } + + /* If and when the IETF assigns some official name tags, we'll have + to add them here. */ + + for( s=name ; *s; s++ ) + { + if( *s=='@') + saw_at++; + + /* -notationname is legal without an = sign */ + if(!*s && notation->flags.ignore) + break; + + if (*s == '=') + { + log_error(_("a notation name may not contain an '=' character\n")); + goto fail; + } + + if (!isascii (*s) || (!isgraph(*s) && !isspace(*s))) + { + log_error(_("a notation name must have only printable characters" + " or spaces\n") ); + goto fail; + } + } + + notation->name=xstrdup (name); + + if(!saw_at && !opt.expert) + { + log_error(_("a user notation name must contain the '@' character\n")); + goto fail; + } + + if (saw_at > 1) + { + log_error(_("a notation name must not contain more than" + " one '@' character\n")); + goto fail; + } + + notation->bdat = xmalloc (len); + memcpy (notation->bdat, data, len); + notation->blen = len; + + notation->value = notation_value_to_human_readable_string (notation); + + return notation; + + fail: + free_notation(notation); + return NULL; +} + struct notation * sig_to_notation(PKT_signature *sig) { diff --git a/g10/packet.h b/g10/packet.h index 1be9ec389..21c06d776 100644 --- a/g10/packet.h +++ b/g10/packet.h @@ -762,6 +762,8 @@ void build_attribute_subpkt(PKT_user_id *uid,byte type, const void *buf,u32 buflen, const void *header,u32 headerlen); struct notation *string_to_notation(const char *string,int is_utf8); +struct notation *blob_to_notation(const char *name, + const char *data, size_t len); struct notation *sig_to_notation(PKT_signature *sig); void free_notation(struct notation *notation);