[git] GPGME - branch, master, updated. gpgme-1.6.0-284-gfe1e8e7

by Werner Koch cvs at cvs.gnupg.org
Fri Aug 12 15:35:34 CEST 2016


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 "GnuPG Made Easy".

The branch, master has been updated
       via  fe1e8e71aa18b4ac6471292b2894b8859f42f7c8 (commit)
       via  293d1736911fd5e77b8cec305168b35b2420c612 (commit)
      from  06e601ad1a169ec8e941125afe698e722eca657d (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 fe1e8e71aa18b4ac6471292b2894b8859f42f7c8
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Aug 12 15:24:46 2016 +0200

    core: Make use of the "size-hint" in engine-gpg.
    
    * src/engine-gpg.c: Include data.h.
    (add_input_size_hint): New.
    (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign, gpg_sign)
    (gpg_verify): Call new function,
    
    * tests/run-encrypt.c (status_cb): Print to stderr.
    (progress_cb): New.o
    (main): Add option --progress.  Print full-status lines.  Provide a
    size for the input data.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/doc/gpgme.texi b/doc/gpgme.texi
index 2bbed28..8b0ec52 100644
--- a/doc/gpgme.texi
+++ b/doc/gpgme.texi
@@ -2177,6 +2177,30 @@ The function @code{gpgme_data_set_encoding} changes the encoding of
 the data object with the handle @var{dh} to @var{enc}.
 @end deftypefun
 
+ at deftypefun {gpgme_error_t} gpgme_data_set_flag  @
+            (@w{gpgme_data_t @var{dh}}, @
+            @w{const char *@var{name}}, @
+            @w{const char *@var{value}})
+
+Some minor properties of the data object can be controlled with flags
+set by this function.  The properties are identified by the following
+values for @var{name}:
+
+ at table @code
+ at item size-hint
+The value is a decimal number with the length gpgme shall assume for
+this data object.  This is useful if the data is provided by callbacks
+or via file descriptors but the applications knows the total size of
+the data.  If this is set the OpenPGP engine may use this to decide on
+buffer allocation strategies and to provide a total value for its
+progress information.
+
+ at end table
+
+This function returns @code{0} on success.
+ at end deftypefun
+
+
 @node Data Buffer Convenience
 @subsection Data Buffer Convenience Functions
 @cindex data buffer, convenience
diff --git a/src/engine-gpg.c b/src/engine-gpg.c
index efab80a..3edac6c 100644
--- a/src/engine-gpg.c
+++ b/src/engine-gpg.c
@@ -42,6 +42,7 @@
 #include "priv-io.h"
 #include "sema.h"
 #include "debug.h"
+#include "data.h"
 
 #include "engine-backend.h"
 
@@ -1483,6 +1484,35 @@ start (engine_gpg_t gpg)
 }
 
 
+/* Add the --input-size-hint option if requested.  */
+static gpgme_error_t
+add_input_size_hint (engine_gpg_t gpg, gpgme_data_t data)
+{
+  gpgme_error_t err;
+  gpgme_off_t value = _gpgme_data_get_size_hint (data);
+  char numbuf[50];  /* Large enough for even 2^128 in base-10.  */
+  char *p;
+
+  if (!value || !have_gpg_version (gpg, "2.1.15"))
+    return 0;
+
+  err = add_arg (gpg, "--input-size-hint");
+  if (!err)
+    {
+      p = numbuf + sizeof numbuf;
+      *--p = 0;
+      do
+        {
+          *--p = '0' + (value % 10);
+          value /= 10;
+        }
+      while (value);
+      err = add_arg (gpg, p);
+    }
+  return err;
+}
+
+
 static gpgme_error_t
 gpg_decrypt (void *engine, gpgme_data_t ciph, gpgme_data_t plain)
 {
@@ -1499,6 +1529,8 @@ gpg_decrypt (void *engine, gpgme_data_t ciph, gpgme_data_t plain)
   if (!err)
     err = add_data (gpg, plain, 1, 1);
   if (!err)
+    err = add_input_size_hint (gpg, ciph);
+  if (!err)
     err = add_arg (gpg, "--");
   if (!err)
     err = add_data (gpg, ciph, -1, 0);
@@ -1764,6 +1796,8 @@ gpg_encrypt (void *engine, gpgme_key_t recp[], gpgme_encrypt_flags_t flags,
 	err = add_arg (gpg, gpgme_data_get_file_name (plain));
     }
   if (!err)
+    err = add_input_size_hint (gpg, plain);
+  if (!err)
     err = add_arg (gpg, "--");
   if (!err)
     err = add_data (gpg, plain, -1, 0);
@@ -1837,6 +1871,8 @@ gpg_encrypt_sign (void *engine, gpgme_key_t recp[],
 	err = add_arg (gpg, gpgme_data_get_file_name (plain));
     }
   if (!err)
+    err = add_input_size_hint (gpg, plain);
+  if (!err)
     err = add_arg (gpg, "--");
   if (!err)
     err = add_data (gpg, plain, -1, 0);
@@ -2291,7 +2327,7 @@ gpg_keylist_build_options (engine_gpg_t gpg, int secret_only,
   err = add_arg (gpg, "--with-colons");
 
   /* Since gpg 2.1.15 fingerprints are always printed, thus there is
-   * no more need to explictly reqeust them.  */
+   * no more need to explictly request them.  */
   if (!have_gpg_version (gpg, "2.1.15"))
     {
       if (!err)
@@ -2436,6 +2472,8 @@ gpg_sign (void *engine, gpgme_data_t in, gpgme_data_t out,
 
   /* Tell the gpg object about the data.  */
   if (!err)
+    err = add_input_size_hint (gpg, in);
+  if (!err)
     err = add_arg (gpg, "--");
   if (!err)
     err = add_data (gpg, in, -1, 0);
@@ -2481,11 +2519,12 @@ gpg_verify (void *engine, gpgme_data_t sig, gpgme_data_t signed_text,
   if (plaintext)
     {
       /* Normal or cleartext signature.  */
-
       err = add_arg (gpg, "--output");
       if (!err)
 	err = add_arg (gpg, "-");
       if (!err)
+        err = add_input_size_hint (gpg, sig);
+      if (!err)
 	err = add_arg (gpg, "--");
       if (!err)
 	err = add_data (gpg, sig, -1, 0);
@@ -2496,6 +2535,8 @@ gpg_verify (void *engine, gpgme_data_t sig, gpgme_data_t signed_text,
     {
       err = add_arg (gpg, "--verify");
       if (!err)
+        err = add_input_size_hint (gpg, signed_text);
+      if (!err)
 	err = add_arg (gpg, "--");
       if (!err)
 	err = add_data (gpg, sig, -1, 0);
diff --git a/tests/run-encrypt.c b/tests/run-encrypt.c
index 210f88a..b94b028 100644
--- a/tests/run-encrypt.c
+++ b/tests/run-encrypt.c
@@ -36,16 +36,33 @@
 
 static int verbose;
 
+
 static gpg_error_t
 status_cb (void *opaque, const char *keyword, const char *value)
 {
   (void)opaque;
-  printf ("status_cb: %s %s\n", keyword, value);
+  fprintf (stderr, "status_cb: %s %s\n", nonnull(keyword), nonnull(value));
   return 0;
 }
 
 
 static void
+progress_cb (void *opaque, const char *what, int type, int current, int total)
+{
+  (void)opaque;
+  (void)type;
+
+  if (total)
+    fprintf (stderr, "progress for '%s' %u%% (%d of %d)\n",
+             nonnull (what),
+             (unsigned)(((double)current / total) * 100), current, total);
+  else
+    fprintf (stderr, "progress for '%s' %d\n", nonnull(what), current);
+  fflush (stderr);
+}
+
+
+static void
 print_result (gpgme_encrypt_result_t result)
 {
   gpgme_invalid_key_t invkey;
@@ -65,6 +82,7 @@ show_usage (int ex)
          "Options:\n"
          "  --verbose        run in verbose mode\n"
          "  --status         print status lines from the backend\n"
+         "  --progress       print progress info\n"
          "  --openpgp        use the OpenPGP protocol (default)\n"
          "  --cms            use the CMS protocol\n"
          "  --uiserver       use the UI server\n"
@@ -87,12 +105,14 @@ main (int argc, char **argv)
   gpgme_data_t in, out;
   gpgme_encrypt_result_t result;
   int print_status = 0;
+  int print_progress = 0;
   int use_loopback = 0;
   char *keyargs[10];
   gpgme_key_t keys[10+1];
   int keycount = 0;
   int i;
   gpgme_encrypt_flags_t flags = GPGME_ENCRYPT_ALWAYS_TRUST;
+  gpgme_off_t offset;
 
   if (argc)
     { argc--; argv++; }
@@ -120,6 +140,11 @@ main (int argc, char **argv)
           print_status = 1;
           argc--; argv++;
         }
+      else if (!strcmp (*argv, "--progress"))
+        {
+          print_progress = 1;
+          argc--; argv++;
+        }
       else if (!strcmp (*argv, "--openpgp"))
         {
           protocol = GPGME_PROTOCOL_OpenPGP;
@@ -179,7 +204,12 @@ main (int argc, char **argv)
   gpgme_set_protocol (ctx, protocol);
   gpgme_set_armor (ctx, 1);
   if (print_status)
-    gpgme_set_status_cb (ctx, status_cb, NULL);
+    {
+      gpgme_set_status_cb (ctx, status_cb, NULL);
+      gpgme_set_ctx_flag (ctx, "full-status", "1");
+    }
+  if (print_progress)
+    gpgme_set_progress_cb (ctx, progress_cb, NULL);
   if (use_loopback)
     {
       gpgme_set_pinentry_mode (ctx, GPGME_PINENTRY_MODE_LOOPBACK);
@@ -200,6 +230,41 @@ main (int argc, char **argv)
                *argv, gpg_strerror (err));
       exit (1);
     }
+  offset = gpgme_data_seek (in, 0, SEEK_END);
+  if (offset == (gpgme_off_t)(-1))
+    {
+      err = gpg_error_from_syserror ();
+      fprintf (stderr, PGM ": error seeking `%s': %s\n",
+               *argv, gpg_strerror (err));
+      exit (1);
+    }
+  if (gpgme_data_seek (in, 0, SEEK_SET) == (gpgme_off_t)(-1))
+    {
+      err = gpg_error_from_syserror ();
+      fprintf (stderr, PGM ": error seeking `%s': %s\n",
+               *argv, gpg_strerror (err));
+      exit (1);
+    }
+  {
+    char numbuf[50];
+    char *p;
+
+    p = numbuf + sizeof numbuf;
+    *--p = 0;
+    do
+      {
+        *--p = '0' + (offset % 10);
+        offset /= 10;
+      }
+    while (offset);
+    err = gpgme_data_set_flag (in, "size-hint", p);
+    if (err)
+      {
+        fprintf (stderr, PGM ": error setting size-hint for `%s': %s\n",
+                 *argv, gpg_strerror (err));
+        exit (1);
+      }
+  }
 
   err = gpgme_data_new (&out);
   fail_if_err (err);

commit 293d1736911fd5e77b8cec305168b35b2420c612
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Aug 12 15:21:16 2016 +0200

    core: Add gpgme_data_set_flag to add more meta data to data objects.
    
    * src/gpgme.h.in (gpgme_data_set_flag): New public function.
    * src/data.c (gpgme_data_set_flag): New.
    (_gpgme_data_get_size_hint): New.
    * src/data.h (strucy gpgme_data): Add field 'size_hint'.
    * src/gpgme.def, src/libgpgme.vers: Add new function.
    * src/conversion.c (_gpgme_string_to_off): New.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/NEWS b/NEWS
index b3a250b..e47ec91 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,7 @@ Noteworthy changes in version 1.7.0 (unreleased) [C25/A14/R_]
  gpgme_pubkey_algo_string       NEW.
  GPGME_PK_EDDSA                 NEW.
  gpgme_set_ctx_flag             NEW.
+ gpgme_data_set_flag            NEW.
  gpgme_signature_t              EXTENDED: New field tofu.
  gpgme_subkey_t                 EXTENDED: New field keygrip.
  gpgme_tofu_policy_t            NEW.
diff --git a/src/conversion.c b/src/conversion.c
index c2b27a1..3df8fe5 100644
--- a/src/conversion.c
+++ b/src/conversion.c
@@ -364,6 +364,25 @@ _gpgme_strtoul_field (const char *string, unsigned long *result)
 }
 
 
+/* Convert STRING into an offset value.  Note that this functions only
+ * allows for a base-10 length.  This function is similar to atoi()
+ * and thus there is no error checking.  */
+gpgme_off_t
+_gpgme_string_to_off (const char *string)
+{
+  gpgme_off_t value = 0;
+
+  while (*string == ' ' || *string == '\t')
+    string++;
+  for (; *string >= '0' && *string <= '9'; string++)
+    {
+      value *= 10;
+      value += atoi_1 (string);
+    }
+  return value;
+}
+
+
 #ifdef HAVE_W32_SYSTEM
 static time_t
 _gpgme_timegm (struct tm *tm)
diff --git a/src/data.c b/src/data.c
index 87b619e..6964246 100644
--- a/src/data.c
+++ b/src/data.c
@@ -243,6 +243,28 @@ gpgme_data_get_file_name (gpgme_data_t dh)
   return dh->file_name;
 }
 
+
+/* Set a flag for the data object DH.  See the manual for details.  */
+gpg_error_t
+gpgme_data_set_flag (gpgme_data_t dh, const char *name, const char *value)
+{
+  TRACE_BEG2 (DEBUG_DATA, "gpgme_data_set_flag", dh,
+	      "%s=%s", name, value);
+
+  if (!dh)
+    return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
+
+  if (!strcmp (name, "size-hint"))
+    {
+      dh->size_hint= value? _gpgme_string_to_off (value) : 0;
+    }
+  else
+    return gpg_error (GPG_ERR_UNKNOWN_NAME);
+
+  return 0;
+}
+
+
 

 /* Functions to support the wait interface.  */
 
@@ -334,3 +356,11 @@ _gpgme_data_get_fd (gpgme_data_t dh)
     return -1;
   return (*dh->cbs->get_fd) (dh);
 }
+
+
+/* Get the size-hint value for DH or 0 if not available.  */
+gpgme_off_t
+_gpgme_data_get_size_hint (gpgme_data_t dh)
+{
+  return dh ? dh->size_hint : 0;
+}
diff --git a/src/data.h b/src/data.h
index 3d404af..0a15b61 100644
--- a/src/data.h
+++ b/src/data.h
@@ -89,6 +89,9 @@ struct gpgme_data
   /* File name of the data object.  */
   char *file_name;
 
+  /* Hint on the to be expected toatl size of the data.  */
+  gpgme_off_t size_hint;
+
   union
   {
     /* For gpgme_data_new_from_fd.  */
@@ -134,4 +137,7 @@ void _gpgme_data_release (gpgme_data_t dh);
    return -1.  */
 int _gpgme_data_get_fd (gpgme_data_t dh);
 
+/* Get the size-hint value for DH or 0 if not available.  */
+gpgme_off_t _gpgme_data_get_size_hint (gpgme_data_t dh);
+
 #endif	/* DATA_H */
diff --git a/src/gpgme.def b/src/gpgme.def
index dfdb6c6..a15c35b 100644
--- a/src/gpgme.def
+++ b/src/gpgme.def
@@ -226,5 +226,8 @@ EXPORTS
 
     gpgme_pubkey_algo_string              @169
     gpgme_set_ctx_flag                    @170
+
+    gpgme_data_set_flag                   @171
+
 ; END
 
diff --git a/src/gpgme.h.in b/src/gpgme.h.in
index 56d15f4..40f5442 100644
--- a/src/gpgme.h.in
+++ b/src/gpgme.h.in
@@ -1282,6 +1282,10 @@ char *gpgme_data_get_file_name (gpgme_data_t dh);
 gpgme_error_t gpgme_data_set_file_name (gpgme_data_t dh,
 					const char *file_name);
 
+/* Set a flag for the data object DH.  See the manual for details.  */
+gpg_error_t gpgme_data_set_flag (gpgme_data_t dh,
+                                 const char *name, const char *value);
+
 /* Try to identify the type of the data in DH.  */
 gpgme_data_type_t gpgme_data_identify (gpgme_data_t dh, int reserved);
 
diff --git a/src/libgpgme.vers b/src/libgpgme.vers
index 873cb19..d29bc14 100644
--- a/src/libgpgme.vers
+++ b/src/libgpgme.vers
@@ -230,6 +230,8 @@ GPGME_1.0 {
     gpgme_err_code_from_syserror;
     gpgme_err_set_errno;
 
+    gpgme_data_set_flag;
+
   local:
     *;
 
diff --git a/src/util.h b/src/util.h
index 5a0f790..a3425f0 100644
--- a/src/util.h
+++ b/src/util.h
@@ -134,6 +134,9 @@ int _gpgme_split_fields (char *string, char **array, int arraysize);
  * trailing garbage.  */
 gpgme_error_t _gpgme_strtoul_field (const char *string, unsigned long *result);
 
+/* Convert STRING into an offset value similar to atoi().  */
+gpgme_off_t _gpgme_string_to_off (const char *string);
+
 /* Parse the string TIMESTAMP into a time_t.  The string may either be
    seconds since Epoch or in the ISO 8601 format like
    "20390815T143012".  Returns 0 for an empty string or seconds since

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

Summary of changes:
 NEWS                |  1 +
 doc/gpgme.texi      | 24 +++++++++++++++++++
 src/conversion.c    | 19 +++++++++++++++
 src/data.c          | 30 +++++++++++++++++++++++
 src/data.h          |  6 +++++
 src/engine-gpg.c    | 45 ++++++++++++++++++++++++++++++++--
 src/gpgme.def       |  3 +++
 src/gpgme.h.in      |  4 ++++
 src/libgpgme.vers   |  2 ++
 src/util.h          |  3 +++
 tests/run-encrypt.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 11 files changed, 202 insertions(+), 4 deletions(-)


hooks/post-receive
-- 
GnuPG Made Easy
http://git.gnupg.org




More information about the Gnupg-commits mailing list