[Pkg-gnupg-commit] [gpgme] 47/62: doc, tests: Require use of ctx_flag before use of session_key.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Sat Nov 19 04:03:37 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch experimental
in repository gpgme.

commit 573064742145aa5f9bf04baa88af918c0c4d5e12
Author: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
Date:   Wed Nov 16 14:10:22 2016 +0900

    doc,tests: Require use of ctx_flag before use of session_key.
    
    * doc/gpgme.texi: Document requirements of verifying that it is OK to
    use session_key.
    * tests/run-decrypt.c: Ensure that we fail if we're unable to access
    the session key, so that we do not violate the guidance above.
    
    Signed-off-by: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
    
    Changed the description
    
     - at code{gpgme_set_ctx_flag (ctx, "export-session-key")} returns
     - at code{GPG_ERR_NO_ERROR} or @code{gpgme_get_ctx_flag (ctx,
     -"export-session-key")} returns @code{"1"}.
     + at code{gpgme_set_ctx_flag (ctx, "export-session-key")} returns success
     +or @code{gpgme_get_ctx_flag (ctx, "export-session-key")} returns true
     +(non-empty string).
    
    to get gpgme_get_ctx_flag for boolean values in sync with its own
    description.
    
    Note that I don't agree with the above suggestion but it does not
    really harm to have it in the man page.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>
---
 doc/gpgme.texi      |  5 +++++
 tests/run-decrypt.c | 29 +++++++++++++++++++++++------
 2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/doc/gpgme.texi b/doc/gpgme.texi
index fd396e0..4f899a9 100644
--- a/doc/gpgme.texi
+++ b/doc/gpgme.texi
@@ -4814,6 +4814,11 @@ set to export session keys (see @code{gpgme_set_ctx_flag,
 "export-session-key"}), and a session key was available for the most
 recent decryption operation.  Otherwise, this is a null pointer.
 
+You must not try to access this member of the struct unless
+ at code{gpgme_set_ctx_flag (ctx, "export-session-key")} returns success
+or @code{gpgme_get_ctx_flag (ctx, "export-session-key")} returns true
+(non-empty string).
+
 @end table
 @end deftp
 
diff --git a/tests/run-decrypt.c b/tests/run-decrypt.c
index 65624d0..07a8747 100644
--- a/tests/run-decrypt.c
+++ b/tests/run-decrypt.c
@@ -174,9 +174,25 @@ main (int argc, char **argv)
       gpgme_set_ctx_flag (ctx, "full-status", "1");
     }
   if (export_session_key)
-    gpgme_set_ctx_flag (ctx, "export-session-key", "1");
+    {
+      err = gpgme_set_ctx_flag (ctx, "export-session-key", "1");
+      if (err)
+        {
+          fprintf (stderr, PGM ": error requesting exported session key: %s\n",
+                   gpgme_strerror (err));
+          exit (1);
+        }
+    }
   if (override_session_key)
-    gpgme_set_ctx_flag (ctx, "override-session-key", override_session_key);
+    {
+      err = gpgme_set_ctx_flag (ctx, "overrride-session-key", "1");
+      if (err)
+        {
+          fprintf (stderr, PGM ": error overriding session key: %s\n",
+                   gpgme_strerror (err));
+          exit (1);
+        }
+    }
 
   err = gpgme_data_new_from_stream (&in, fp_in);
   if (err)
@@ -201,10 +217,11 @@ main (int argc, char **argv)
       fprintf (stderr, PGM ": decrypt failed: %s\n", gpgme_strerror (err));
       exit (1);
     }
-  if (result) {
-    print_result (result);
-    print_data (out);
-  }
+  if (result)
+    {
+      print_result (result);
+      print_data (out);
+    }
 
   gpgme_data_release (out);
   gpgme_data_release (in);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git



More information about the Pkg-gnupg-commit mailing list