[git] GnuPG - branch, master, updated. gnupg-2.1.9-91-gd89a9fc

by Werner Koch cvs at cvs.gnupg.org
Fri Oct 30 12:44:53 CET 2015


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  d89a9fca46d9bba497dde0793b57217c800b0e8d (commit)
       via  5aadb4b62d26e1bfb40a1ce444a81c2a5a56159c (commit)
      from  965486031bd094bd017c3eba9b53cf7b1e3ab6a8 (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 d89a9fca46d9bba497dde0793b57217c800b0e8d
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Oct 30 12:40:22 2015 +0100

    common: Improve t-zb32 to be used for manual encoding.
    
    * common/t-support.h (no_exit_on_fail, errcount): New.
    (fail): Bump errcount.
    * common/t-zb32.c (main): Add options to allow manual use.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/common/Makefile.am b/common/Makefile.am
index fd3a04f..f84cea1 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -192,7 +192,10 @@ t_session_env_LDADD = $(t_common_ldadd)
 t_openpgp_oid_LDADD = $(t_common_ldadd)
 t_ssh_utils_LDADD = $(t_common_ldadd)
 t_mapstrings_LDADD = $(t_common_ldadd)
+
+t_zb32_SOURCES = t-zb32.c $(t_extra_src)
 t_zb32_LDADD = $(t_common_ldadd)
+
 t_mbox_util_LDADD = $(t_common_ldadd)
 t_iobuf_LDADD = $(t_common_ldadd)
 
diff --git a/common/t-support.h b/common/t-support.h
index 555158e..c0d0c8c 100644
--- a/common/t-support.h
+++ b/common/t-support.h
@@ -69,8 +69,15 @@ void  gcry_free (void *a);
 #define pass()  do { ; } while(0)
 #define fail(a)  do { fprintf (stderr, "%s:%d: test %d failed\n",\
                                __FILE__,__LINE__, (a));          \
-                     exit (1);                                   \
+                      errcount++;                                \
+                      if (!no_exit_on_fail)                      \
+                         exit (1);                               \
                    } while(0)
 
+/* If this flag is set the fail macro does not call exit.  */
+static int no_exit_on_fail;
+/* Error counter.  */
+static int errcount;
+
 
 #endif /*GNUPG_COMMON_T_SUPPORT_H*/
diff --git a/common/t-zb32.c b/common/t-zb32.c
index 2b19c09..c46d47f 100644
--- a/common/t-zb32.c
+++ b/common/t-zb32.c
@@ -30,17 +30,21 @@
 #include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <errno.h>
+#ifdef HAVE_DOSISH_SYSTEM
+# include <fcntl.h>
+#endif
 
-#include "util.h"
+#include "zb32.h"
+#include "t-support.h"
 
-#define pass()  do { ; } while(0)
-#define fail(a)  do { fprintf (stderr, "%s:%d: test %d failed\n",\
-                               __FILE__,__LINE__, (a));          \
-                     errcount++;                                 \
-                   } while(0)
+#define PGM "t-zb32"
 
+static int verbose;
+static int debug;
 static int errcount;
 
 
@@ -89,8 +93,8 @@ test_zb32enc (void)
       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));
+          fprintf (stderr, PGM": error encoding test %d: %s\n",
+                   tidx, strerror (errno));
           exit (1);
         }
       /* puts (output); */
@@ -101,13 +105,201 @@ test_zb32enc (void)
 }
 
 
+/* Read the file FNAME or stdin if FNAME is NULL and return a malloced
+   buffer with the content.  R_LENGTH received the length of the file.
+   Print a diagnostic and returns NULL on error.  */
+static char *
+read_file (const char *fname, size_t *r_length)
+{
+  FILE *fp;
+  char *buf;
+  size_t buflen;
+
+  if (!fname)
+    {
+      size_t nread, bufsize = 0;
+
+      fp = stdin;
+#ifdef HAVE_DOSISH_SYSTEM
+      setmode (fileno(fp) , O_BINARY );
+#endif
+      buf = NULL;
+      buflen = 0;
+#define NCHUNK 8192
+      do
+        {
+          bufsize += NCHUNK;
+          if (!buf)
+            buf = xmalloc (bufsize);
+          else
+            buf = xrealloc (buf, bufsize);
+
+          nread = fread (buf+buflen, 1, NCHUNK, fp);
+          if (nread < NCHUNK && ferror (fp))
+            {
+              fprintf (stderr, PGM": error reading '[stdin]': %s\n",
+                       strerror (errno));
+              xfree (buf);
+              return NULL;
+            }
+          buflen += nread;
+        }
+      while (nread == NCHUNK);
+#undef NCHUNK
+
+    }
+  else
+    {
+      struct stat st;
+
+      fp = fopen (fname, "rb");
+      if (!fp)
+        {
+          fprintf (stderr, PGM": can't open '%s': %s\n",
+                   fname, strerror (errno));
+          return NULL;
+        }
+
+      if (fstat (fileno(fp), &st))
+        {
+          fprintf (stderr, PGM": can't stat '%s': %s\n",
+                   fname, strerror (errno));
+          fclose (fp);
+          return NULL;
+        }
+
+      buflen = st.st_size;
+      buf = xmalloc (buflen+1);
+      if (fread (buf, buflen, 1, fp) != 1)
+        {
+          fprintf (stderr, PGM": error reading '%s': %s\n",
+                   fname, strerror (errno));
+          fclose (fp);
+          xfree (buf);
+          return NULL;
+        }
+      fclose (fp);
+    }
+
+  *r_length = buflen;
+  return buf;
+}
+
+
+/* Debug helper to encode or decode to/from zb32.  */
+static void
+endecode_file (const char *fname, int decode)
+{
+  char *buffer;
+  size_t buflen;
+  char *result;
+
+  if (decode)
+    {
+      fprintf (stderr, PGM": decode mode has not yet been implemented\n");
+      errcount++;
+      return;
+    }
+
+#ifdef HAVE_DOSISH_SYSTEM
+  if (decode)
+    setmode (fileno (stdout), O_BINARY);
+#endif
+
+
+  buffer = read_file (fname, &buflen);
+  if (!buffer)
+    {
+      errcount++;
+      return;
+    }
+
+  result = zb32_encode (buffer, 8 * buflen);
+  if (!result)
+    {
+      fprintf (stderr, PGM": error encoding data: %s\n", strerror (errno));
+      errcount++;
+      xfree (buffer);
+      return;
+    }
+
+  fputs (result, stdout);
+  putchar ('\n');
+
+  xfree (result);
+  xfree (buffer);
+}
+
+
 int
 main (int argc, char **argv)
 {
-  (void)argc;
-  (void)argv;
+  int last_argc = -1;
+  int opt_endecode = 0;
 
-  test_zb32enc ();
+  no_exit_on_fail = 1;
+
+  if (argc)
+    { argc--; argv++; }
+  while (argc && last_argc != argc )
+    {
+      last_argc = argc;
+      if (!strcmp (*argv, "--"))
+        {
+          argc--; argv++;
+          break;
+        }
+      else if (!strcmp (*argv, "--help"))
+        {
+          fputs ("usage: " PGM " [FILE]\n"
+                 "Options:\n"
+                 "  --verbose         Print timings etc.\n"
+                 "  --debug           Flyswatter\n"
+                 "  --encode          Encode FILE or stdin\n"
+                 "  --decode          Decode FILE or stdin\n"
+                 , stdout);
+          exit (0);
+        }
+      else if (!strcmp (*argv, "--verbose"))
+        {
+          verbose++;
+          argc--; argv++;
+        }
+      else if (!strcmp (*argv, "--debug"))
+        {
+          verbose += 2;
+          debug++;
+          argc--; argv++;
+        }
+      else if (!strcmp (*argv, "--encode"))
+        {
+          opt_endecode = 1;
+          argc--; argv++;
+        }
+      else if (!strcmp (*argv, "--decode"))
+        {
+          opt_endecode = -1;
+          argc--; argv++;
+        }
+      else if (!strncmp (*argv, "--", 2))
+        {
+          fprintf (stderr, PGM ": unknown option '%s'\n", *argv);
+          exit (1);
+        }
+    }
+
+  if (argc > 1)
+    {
+      fprintf (stderr, PGM ": to many arguments given\n");
+      exit (1);
+    }
+
+  if (opt_endecode)
+    {
+      endecode_file (argc? *argv : NULL, (opt_endecode < 0));
+    }
+  else
+    test_zb32enc ();
 
   return !!errcount;
 }

commit 5aadb4b62d26e1bfb40a1ce444a81c2a5a56159c
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Oct 30 12:33:40 2015 +0100

    common: Add separate header for zb32.c.
    
    * common/util.h (zb32_encode): Move prototype to ...
    * common/zb32.h: new.  Include this for all callers of zb32_encode.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/common/Makefile.am b/common/Makefile.am
index 6cbde0b..fd3a04f 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -64,7 +64,7 @@ common_sources = \
 	homedir.c \
 	gettime.c gettime.h \
 	yesno.c \
-	b64enc.c b64dec.c zb32.c \
+	b64enc.c b64dec.c zb32.c zb32.h \
 	convert.c \
 	percent.c \
 	mbox-util.c mbox-util.h \
diff --git a/common/util.h b/common/util.h
index 06d5f87..b2651c4 100644
--- a/common/util.h
+++ b/common/util.h
@@ -274,11 +274,6 @@ gpg_error_t b64dec_proc (struct b64state *state, void *buffer, size_t length,
                          size_t *r_nbytes);
 gpg_error_t b64dec_finish (struct b64state *state);
 
-
-/*-- zb32.c --*/
-char *zb32_encode (const void *data, unsigned int databits);
-
-
 /*-- sexputil.c */
 char *canon_sexp_to_string (const unsigned char *canon, size_t canonlen);
 void log_printcanon (const char *text,
diff --git a/common/zb32.h b/common/zb32.h
new file mode 100644
index 0000000..1fb41ec
--- /dev/null
+++ b/common/zb32.h
@@ -0,0 +1,38 @@
+/* zb32.h - 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/>.
+ */
+
+#ifndef GNUPG_COMMON_ZB32_H
+#define GNUPG_COMMON_ZB32_H
+
+/* Encode DATA which has a length of DATABITS (bits!) using the
+   zbase32 encoder and return a malloced string.  Returns NULL on
+   error and sets ERRNO.  */
+char *zb32_encode (const void *data, unsigned int databits);
+
+#endif /*GNUPG_COMMON_ZB32_H*/
diff --git a/dirmngr/server.c b/dirmngr/server.c
index a41d34f..74e00fb 100644
--- a/dirmngr/server.c
+++ b/dirmngr/server.c
@@ -52,6 +52,7 @@
 #endif
 #include "dns-stuff.h"
 #include "mbox-util.h"
+#include "zb32.h"
 
 /* To avoid DoS attacks we limit the size of a certificate to
    something reasonable.  The DoS was actually only an issue back when
diff --git a/g10/keylist.c b/g10/keylist.c
index 509cf7c..cc97846 100644
--- a/g10/keylist.c
+++ b/g10/keylist.c
@@ -43,6 +43,7 @@
 #include "status.h"
 #include "call-agent.h"
 #include "mbox-util.h"
+#include "zb32.h"
 #include "tofu.h"
 
 
diff --git a/g10/misc.c b/g10/misc.c
index 5c77714..7f0b08a 100644
--- a/g10/misc.c
+++ b/g10/misc.c
@@ -67,6 +67,7 @@
 #include "options.h"
 #include "call-agent.h"
 #include "i18n.h"
+#include "zb32.h"
 
 #include <assert.h>
 

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

Summary of changes:
 common/Makefile.am             |   5 +-
 common/t-support.h             |   9 +-
 common/t-zb32.c                | 214 ++++++++++++++++++++++++++++++++++++++---
 common/util.h                  |   5 -
 common/{ssh-utils.h => zb32.h} |  19 ++--
 dirmngr/server.c               |   1 +
 g10/keylist.c                  |   1 +
 g10/misc.c                     |   1 +
 8 files changed, 227 insertions(+), 28 deletions(-)
 copy common/{ssh-utils.h => zb32.h} (71%)


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




More information about the Gnupg-commits mailing list