aboutsummaryrefslogtreecommitdiffstats
path: root/g10/build-packet.c
diff options
context:
space:
mode:
authorNeal H. Walfield <[email protected]>2016-02-29 13:12:57 +0000
committerNeal H. Walfield <[email protected]>2016-03-02 19:36:13 +0000
commit1a624586149f9e34206e5d5e1ba0b7d2b7004c80 (patch)
treec5a502da46e68fe97aff4c902de6a5177027e9d6 /g10/build-packet.c
parentgpg: Refactor the printing of binary notations. (diff)
downloadgnupg-1a624586149f9e34206e5d5e1ba0b7d2b7004c80.tar.gz
gnupg-1a624586149f9e34206e5d5e1ba0b7d2b7004c80.zip
gpg: Add a new function for creating binary notations.
* g10/build-packet.c (blob_to_notation): New function. -- Signed-off-by: Neal H. Walfield <[email protected]>
Diffstat (limited to 'g10/build-packet.c')
-rw-r--r--g10/build-packet.c79
1 files changed, 77 insertions, 2 deletions
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)
{