diff options
author | Neal H. Walfield <neal@g10code.com> | 2016-02-29 14:09:43 +0100 |
---|---|---|
committer | Neal H. Walfield <neal@g10code.com> | 2016-03-02 20:36:12 +0100 |
commit | fd2d00ccf558b1ac1184967d8702ef01cd60bf60 (patch) | |
tree | 88eb419e6abf56eaf1a787dc5268be2c2f5c4222 /g10/build-packet.c | |
parent | tests/openpgp: Make tests more portable. (diff) | |
download | gnupg2-fd2d00ccf558b1ac1184967d8702ef01cd60bf60.tar.xz gnupg2-fd2d00ccf558b1ac1184967d8702ef01cd60bf60.zip |
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@g10code.com>
Diffstat (limited to 'g10/build-packet.c')
-rw-r--r-- | g10/build-packet.c | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/g10/build-packet.c b/g10/build-packet.c index feb7b44cd..8388ce3e4 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; |