mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-21 14:47:03 +01:00
gpg: Add a new function for creating binary notations.
* g10/build-packet.c (blob_to_notation): New function. -- Signed-off-by: Neal H. Walfield <neal@g10code.com>
This commit is contained in:
parent
fd2d00ccf5
commit
1a62458614
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user