[git] GnuPG - branch, master, updated. gnupg-2.1.0beta3-388-ge184a11

by Werner Koch cvs at cvs.gnupg.org
Thu Apr 17 21:43:57 CEST 2014


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".

The branch, master has been updated
       via  e184a11f94e2d41cd9266484542631bec23628b5 (commit)
       via  b8a91ebf46a927801866e99bb5a66ab00651424e (commit)
      from  a34afa8f2053d75f276d6d28dbf1a43db0fd9768 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit e184a11f94e2d41cd9266484542631bec23628b5
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Apr 15 16:40:48 2014 +0200

    gpg: New %U expando for the photo viewer.
    
    * g10/photoid.c (show_photos): Set namehash.
    * g10/misc.c (pct_expando): Add "%U" expando.
    --
    
    This makes is possible to extract all photos ids from a key to
    different files.

diff --git a/doc/gpg.texi b/doc/gpg.texi
index 607a611..f72775e 100644
--- a/doc/gpg.texi
+++ b/doc/gpg.texi
@@ -1195,7 +1195,7 @@ for the key fingerprint, "%t" for the extension of the image type
 (e.g. "jpg"), "%T" for the MIME type of the image (e.g. "image/jpeg"),
 "%v" for the single-character calculated validity of the image being
 viewed (e.g. "f"), "%V" for the calculated validity as a string (e.g.
-"full"),
+"full"), "%U" for a base32 encoded hash of the user ID,
 and "%%" for an actual percent sign. If neither %i or %I are present,
 then the photo will be supplied to the viewer on standard input.
 
diff --git a/g10/main.h b/g10/main.h
index 04abb4f..d8b9a4d 100644
--- a/g10/main.h
+++ b/g10/main.h
@@ -119,6 +119,7 @@ struct expando_args
   byte imagetype;
   int validity_info;
   const char *validity_string;
+  const byte *namehash;
 };
 
 char *pct_expando(const char *string,struct expando_args *args);
diff --git a/g10/misc.c b/g10/misc.c
index ba83b19..77928aa 100644
--- a/g10/misc.c
+++ b/g10/misc.c
@@ -822,6 +822,23 @@ pct_expando(const char *string,struct expando_args *args)
 		}
 	      break;
 
+	    case 'U': /* z-base-32 encoded user id hash. */
+              if (args->namehash)
+                {
+                  char *tmp = zb32_encode (args->namehash, 8*20);
+                  if (tmp)
+                    {
+                      if (idx + strlen (tmp) < maxlen)
+                        {
+                          strcpy (ret+idx, tmp);
+                          idx += strlen (tmp);
+                        }
+                      xfree (tmp);
+                      done = 1;
+                    }
+                }
+	      break;
+
 	    case 'c': /* signature count from card, if any. */
 	      if(idx+10<maxlen)
 		{
diff --git a/g10/photoid.c b/g10/photoid.c
index 829d36c..f6e625a 100644
--- a/g10/photoid.c
+++ b/g10/photoid.c
@@ -305,6 +305,8 @@ show_photos(const struct user_attribute *attrs, int count,
   args.pk = pk;
   args.validity_info = get_validity_info (pk, uid);
   args.validity_string = get_validity_string (pk, uid);
+  namehash_from_uid (uid);
+  args.namehash = uid->namehash;
 
   if (pk)
     keyid_from_pk (pk, kid);

commit b8a91ebf46a927801866e99bb5a66ab00651424e
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Apr 15 16:40:48 2014 +0200

    common: Add z-base-32 encoder.
    
    * common/zb32.c: New.
    * common/t-zb32.c: New.
    * common/Makefile.am (common_sources): Add zb82.c
    (module_tests): Add t-zb32.

diff --git a/common/Makefile.am b/common/Makefile.am
index 21f779c..f1cf28c 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -72,7 +72,7 @@ common_sources = \
 	homedir.c \
 	gettime.c gettime.h \
 	yesno.c \
-	b64enc.c b64dec.c \
+	b64enc.c b64dec.c zb32.c \
 	convert.c \
 	percent.c \
 	miscellaneous.c \
@@ -166,7 +166,7 @@ jnlib_tests += t-w32-reg
 endif
 module_tests = t-convert t-percent t-gettime t-sysutils t-sexputil \
 	       t-session-env t-openpgp-oid t-ssh-utils t-dns-cert \
-	       t-mapstrings
+	       t-mapstrings t-zb32
 if !HAVE_W32CE_SYSTEM
 module_tests += t-exechelp
 endif
@@ -202,3 +202,4 @@ t_openpgp_oid_LDADD = $(t_common_ldadd)
 t_ssh_utils_LDADD = $(t_common_ldadd)
 t_dns_cert_LDADD = $(t_common_ldadd) $(DNSLIBS)
 t_mapstrings_LDADD = $(t_common_ldadd)
+t_zb32_LDADD = $(t_common_ldadd)
diff --git a/common/t-zb32.c b/common/t-zb32.c
new file mode 100644
index 0000000..7d509da
--- /dev/null
+++ b/common/t-zb32.c
@@ -0,0 +1,110 @@
+/* t-zb32.c - Module tests for zb32.c
+ * Copyright (C) 2014  Werner Koch
+ *
+ * This file is part of GnuPG.
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of either
+ *
+ *   - the GNU Lesser General Public License as published by the Free
+ *     Software Foundation; either version 3 of the License, or (at
+ *     your option) any later version.
+ *
+ * or
+ *
+ *   - the GNU General Public License as published by the Free
+ *     Software Foundation; either version 2 of the License, or (at
+ *     your option) any later version.
+ *
+ * or both in parallel, as here.
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "util.h"
+
+#define pass()  do { ; } while(0)
+#define fail(a)  do { fprintf (stderr, "%s:%d: test %d failed\n",\
+                               __FILE__,__LINE__, (a));          \
+                     errcount++;                                 \
+                   } while(0)
+
+static int errcount;
+
+
+static void
+test_zb32enc (void)
+{
+  static struct {
+    size_t datalen;
+    char *data;
+    const char *expected;
+  } tests[] = {
+    /* From the DESIGN document.  */
+    {  1, "\x00", "y" },
+    {  1, "\x80", "o" },
+    {  2, "\x40", "e" },
+    {  2, "\xc0", "a" },
+    { 10, "\x00\x00", "yy" },
+    { 10, "\x80\x80", "on" },
+    { 20, "\x8b\x88\x80", "tqre" },
+    { 24, "\xf0\xbf\xc7", "6n9hq" },
+    { 24, "\xd4\x7a\x04", "4t7ye" },
+    /* The next vector is strange: The DESIGN document from 2007 gives
+       "8ik66o" as result, the revision from 2009 gives "6im5sd".  I
+       look at it for quite some time and came to the conclusion that
+       "6im54d" is the right encoding.  */
+    { 30, "\xf5\x57\xbd\x0c", "6im54d" },
+    /* From ccrtp's Java code.  */
+    { 40, "\x01\x01\x01\x01\x01", "yryonyeb" },
+    { 15, "\x01\x01", "yry" },
+    { 80, "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01", "yryonyebyryonyeb" },
+    { 15, "\x81\x81", "ogy" },
+    { 16, "\x81\x81", "ogyo" },
+    { 20, "\x81\x81\x81", "ogya" },
+    { 64, "\x81\x81\x81\x81\x81\x81\x81\x81", "ogyadycbogyan" },
+    /* More tests.  */
+    { 0,  "", "" }
+  };
+  int tidx;
+  char *output;
+
+  for (tidx = 0; tidx < DIM(tests); tidx++)
+    {
+      output = zb32_encode (tests[tidx].data, tests[tidx].datalen);
+      if (!output)
+        {
+          fprintf (stderr, "%s:%d: error encoding test %d: %s\n",
+                   __FILE__, __LINE__, tidx, strerror (errno));
+          exit (1);
+        }
+      /* puts (output); */
+      if (strcmp (output, tests[tidx].expected))
+        fail (tidx);
+      xfree (output);
+    }
+}
+
+
+int
+main (int argc, char **argv)
+{
+  (void)argc;
+  (void)argv;
+
+  test_zb32enc ();
+
+  return !!errcount;
+}
diff --git a/common/util.h b/common/util.h
index 4b3cbfc..4dad163 100644
--- a/common/util.h
+++ b/common/util.h
@@ -164,6 +164,8 @@ gpg_error_t b64dec_proc (struct b64state *state, void *buffer, size_t length,
 gpg_error_t b64dec_finish (struct b64state *state);
 
 
+/*-- zb32.c --*/
+char *zb32_encode (const void *data, unsigned int databits);
 
 
 /*-- sexputil.c */
diff --git a/common/zb32.c b/common/zb32.c
new file mode 100644
index 0000000..05aa0ea
--- /dev/null
+++ b/common/zb32.c
@@ -0,0 +1,120 @@
+/* zb32.c - z-base-32 functions
+ * Copyright (C) 2014  Werner Koch
+ *
+ * This file is part of GnuPG.
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of either
+ *
+ *   - the GNU Lesser General Public License as published by the Free
+ *     Software Foundation; either version 3 of the License, or (at
+ *     your option) any later version.
+ *
+ * or
+ *
+ *   - the GNU General Public License as published by the Free
+ *     Software Foundation; either version 2 of the License, or (at
+ *     your option) any later version.
+ *
+ * or both in parallel, as here.
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <assert.h>
+
+#include "util.h"
+
+
+/* Zooko's base32 variant. See RFC-6189 and
+   http://philzimmermann.com/docs/human-oriented-base-32-encoding.txt
+   Caller must xfree the returned string.  Returns NULL and sets ERRNO
+   on error.  To avoid integer overflow DATALEN is limited to 2^16
+   bytes.  Note, that DATABITS is measured in bits!.  */
+char *
+zb32_encode (const void *data, unsigned int databits)
+{
+  static char const zb32asc[32] = {'y','b','n','d','r','f','g','8',
+                                   'e','j','k','m','c','p','q','x',
+                                   'o','t','1','u','w','i','s','z',
+                                   'a','3','4','5','h','7','6','9' };
+  const unsigned char *s;
+  char *output, *d;
+  size_t datalen;
+
+  datalen = (databits + 7) / 8;
+  if (datalen > (1 << 16))
+    {
+      errno = EINVAL;
+      return NULL;
+    }
+
+  d = output = xtrymalloc (8 * (datalen / 5)
+                           + 2 * (datalen % 5)
+                           - ((datalen%5)>2)
+                           + 1);
+  if (!output)
+    return NULL;
+
+  /* I use straightforward code.  The compiler should be able to do a
+     better job on optimization than me and it is easier to read.  */
+  for (s = data; datalen >= 5; s += 5, datalen -= 5)
+    {
+      *d++ = zb32asc[((s[0]      ) >> 3)               ];
+      *d++ = zb32asc[((s[0] &   7) << 2) | (s[1] >> 6) ];
+      *d++ = zb32asc[((s[1] &  63) >> 1)               ];
+      *d++ = zb32asc[((s[1] &   1) << 4) | (s[2] >> 4) ];
+      *d++ = zb32asc[((s[2] &  15) << 1) | (s[3] >> 7) ];
+      *d++ = zb32asc[((s[3] & 127) >> 2)               ];
+      *d++ = zb32asc[((s[3] &   3) << 3) | (s[4] >> 5) ];
+      *d++ = zb32asc[((s[4] &  31)     )               ];
+    }
+
+  switch (datalen)
+    {
+    case 4:
+      *d++ = zb32asc[((s[0]      ) >> 3)               ];
+      *d++ = zb32asc[((s[0] &   7) << 2) | (s[1] >> 6) ];
+      *d++ = zb32asc[((s[1] &  63) >> 1)               ];
+      *d++ = zb32asc[((s[1] &   1) << 4) | (s[2] >> 4) ];
+      *d++ = zb32asc[((s[2] &  15) << 1) | (s[3] >> 7) ];
+      *d++ = zb32asc[((s[3] & 127) >> 2)               ];
+      *d++ = zb32asc[((s[3] &   3) << 3)               ];
+      break;
+    case 3:
+      *d++ = zb32asc[((s[0]      ) >> 3)               ];
+      *d++ = zb32asc[((s[0] &   7) << 2) | (s[1] >> 6) ];
+      *d++ = zb32asc[((s[1] &  63) >> 1)               ];
+      *d++ = zb32asc[((s[1] &   1) << 4) | (s[2] >> 4) ];
+      *d++ = zb32asc[((s[2] &  15) << 1)               ];
+      break;
+    case 2:
+      *d++ = zb32asc[((s[0]      ) >> 3)               ];
+      *d++ = zb32asc[((s[0] &   7) << 2) | (s[1] >> 6) ];
+      *d++ = zb32asc[((s[1] &  63) >> 1)               ];
+      *d++ = zb32asc[((s[1] &   1) << 4)               ];
+      break;
+    case 1:
+      *d++ = zb32asc[((s[0]      ) >> 3)               ];
+      *d++ = zb32asc[((s[0] &   7) << 2)               ];
+      break;
+    default:
+      break;
+    }
+  *d = 0;
+
+  /* Need to strip some bytes if not a multiple of 40.  */
+  output[(databits + 5 - 1) / 5] = 0;
+  return output;
+}

-----------------------------------------------------------------------

Summary of changes:
 common/Makefile.am |    5 ++-
 common/t-zb32.c    |  110 +++++++++++++++++++++++++++++++++++++++++++++++
 common/util.h      |    2 +
 common/zb32.c      |  120 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 doc/gpg.texi       |    2 +-
 g10/main.h         |    1 +
 g10/misc.c         |   17 ++++++++
 g10/photoid.c      |    2 +
 8 files changed, 256 insertions(+), 3 deletions(-)
 create mode 100644 common/t-zb32.c
 create mode 100644 common/zb32.c


hooks/post-receive
-- 
The GNU Privacy Guard
http://git.gnupg.org




More information about the Gnupg-commits mailing list