[Pkg-gnupg-commit] [gnupg2] 79/205: gpg: Refactor the printing of binary notations.
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Wed May 11 08:38:19 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 fd2d00ccf558b1ac1184967d8702ef01cd60bf60
Author: Neal H. Walfield <neal at g10code.com>
Date: Mon Feb 29 14:09:43 2016 +0100
gpg: Refactor the printing of binary notations.
* g10/build-packet.c (sig_to_notation): Break printing of binary
notations into...
(notation_value_to_human_readable_string): ... this new function.
Provide a small preview of the binary data substituting non-printable
characters with '?'.
--
Signed-off-by: Neal H. Walfield <neal at g10code.com>
---
g10/build-packet.c | 32 ++++++++++++++++++++++++++++----
1 file changed, 28 insertions(+), 4 deletions(-)
diff --git a/g10/build-packet.c b/g10/build-packet.c
index feb7b44..8388ce3 100644
--- a/g10/build-packet.c
+++ b/g10/build-packet.c
@@ -1062,6 +1062,33 @@ build_attribute_subpkt(PKT_user_id *uid,byte type,
uid->attrib_len+=idx+headerlen+buflen;
}
+/* Returns a human-readable string corresponding to the notation.
+ This ignores notation->value. The caller must free the result. */
+static char *
+notation_value_to_human_readable_string (struct notation *notation)
+{
+ if(notation->bdat)
+ /* Binary data. */
+ {
+ size_t len = notation->blen;
+ int i;
+ char preview[20];
+
+ for (i = 0; i < len && i < sizeof (preview) - 1; i ++)
+ if (isprint (notation->bdat[i]))
+ preview[i] = notation->bdat[i];
+ else
+ preview[i] = '?';
+ preview[i] = 0;
+
+ return xasprintf (_("[ not human readable (%zd bytes: %s%s) ]"),
+ len, preview, i < len ? "..." : "");
+ }
+ else
+ /* The value is human-readable. */
+ return xstrdup (notation->value);
+}
+
/* Turn the notation described by the string STRING into a notation.
STRING has the form:
@@ -1222,10 +1249,7 @@ sig_to_notation(PKT_signature *sig)
n->blen=n2;
memcpy(n->bdat,&p[8+n1],n2);
- n->value=xmalloc(2+strlen(_("not human readable"))+2+1);
- strcpy(n->value,"[ ");
- strcat(n->value,_("not human readable"));
- strcat(n->value," ]");
+ n->value = notation_value_to_human_readable_string (n);
}
n->flags.critical=crit;
--
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