From 573064742145aa5f9bf04baa88af918c0c4d5e12 Mon Sep 17 00:00:00 2001 From: Daniel Kahn Gillmor Date: Wed, 16 Nov 2016 14:10:22 +0900 Subject: [PATCH] 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 Changed the description -@code{gpgme_set_ctx_flag (ctx, "export-session-key")} returns -@code{GPG_ERR_NO_ERROR} or @code{gpgme_get_ctx_flag (ctx, -"export-session-key")} returns @code{"1"}. +@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 --- 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 fd396e02..4f899a9e 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 +@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 65624d09..07a8747f 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);