[Pkg-gnupg-commit] [gnupg2] 80/205: gpg: Add a new function for creating binary notations.
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Wed May 11 08:38:20 UTC 2016
This is an automated email from the git hooks/post-receive script.
dkg pushed a commit to branch experimental
in repository gnupg2.
commit 1a624586149f9e34206e5d5e1ba0b7d2b7004c80
Author: Neal H. Walfield <neal at g10code.com>
Date: Mon Feb 29 14:12:57 2016 +0100
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 at g10code.com>
---
g10/build-packet.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
g10/packet.h | 2 ++
2 files changed, 79 insertions(+), 2 deletions(-)
diff --git a/g10/build-packet.c b/g10/build-packet.c
index 8388ce3..623533f 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 1be9ec3..21c06d7 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);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git
More information about the Pkg-gnupg-commit
mailing list