From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
To: Notmuch Mail <notmuch@notmuchmail.org>
Subject: [PATCH 3/3] crypto: Avoid explicit handling of GMimeCryptoContext in gmime 3.0
Date: Fri, 14 Jul 2017 15:12:02 +0200 [thread overview]
Message-ID: <20170714131202.24966-3-dkg@fifthhorseman.net> (raw)
In-Reply-To: <20170714131202.24966-1-dkg@fifthhorseman.net>
gmime 3.0 knows how to select the correct GMimeCryptoContext
automatically, so a bunch of the code in notmuch can be dropped in
that case.
The #ifdef removal of the crypto stuff is better than #define aliasing
in gmime-extra.h for this stuff. When built against gmime 3.0:
* it reduces compiled code,
* it avoids initializing unused gpgme contexts, and
* it avoids compiled-time warnings about passing unnecessary
notmuch_cryptoctx_t*s.
---
crypto.c | 2 ++
mime-node.c | 28 ++++++++++++++++++++++++----
notmuch-client.h | 8 ++++++--
notmuch-reply.c | 2 ++
notmuch-show.c | 2 ++
5 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/crypto.c b/crypto.c
index 3e8ce7ca..ab1fb77a 100644
--- a/crypto.c
+++ b/crypto.c
@@ -20,6 +20,7 @@
#include "notmuch-client.h"
+#if (GMIME_MAJOR_VERSION < 3)
/* Create a GPG context (GMime 2.6) */
static notmuch_crypto_context_t *
create_gpg_context (notmuch_crypto_t *crypto)
@@ -132,3 +133,4 @@ notmuch_crypto_cleanup (notmuch_crypto_t *crypto)
return 0;
}
+#endif
diff --git a/mime-node.c b/mime-node.c
index f719422e..226e9c2f 100644
--- a/mime-node.c
+++ b/mime-node.c
@@ -150,8 +150,11 @@ set_signature_list_destructor (mime_node_t *node)
/* Verify a signed mime node (GMime 2.6) */
static void
-node_verify (mime_node_t *node, GMimeObject *part,
- notmuch_crypto_context_t *cryptoctx)
+node_verify (mime_node_t *node, GMimeObject *part
+#if (GMIME_MAJOR_VERSION < 3)
+ , notmuch_crypto_context_t *cryptoctx
+#endif
+ )
{
GError *err = NULL;
@@ -171,8 +174,11 @@ node_verify (mime_node_t *node, GMimeObject *part,
/* Decrypt and optionally verify an encrypted mime node (GMime 2.6) */
static void
-node_decrypt_and_verify (mime_node_t *node, GMimeObject *part,
- notmuch_crypto_context_t *cryptoctx)
+node_decrypt_and_verify (mime_node_t *node, GMimeObject *part
+#if (GMIME_MAJOR_VERSION < 3)
+ , notmuch_crypto_context_t *cryptoctx
+#endif
+ )
{
GError *err = NULL;
GMimeDecryptResult *decrypt_result = NULL;
@@ -207,7 +213,11 @@ static mime_node_t *
_mime_node_create (mime_node_t *parent, GMimeObject *part)
{
mime_node_t *node = talloc_zero (parent, mime_node_t);
+#if (GMIME_MAJOR_VERSION < 3)
notmuch_crypto_context_t *cryptoctx = NULL;
+#else
+ notmuch_bool_t cryptoctx = TRUE;
+#endif
/* Set basic node properties */
node->part = part;
@@ -240,12 +250,14 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
return NULL;
}
+#if (GMIME_MAJOR_VERSION < 3)
if ((GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt)
|| (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify)) {
GMimeContentType *content_type = g_mime_object_get_content_type (part);
const char *protocol = g_mime_content_type_get_parameter (content_type, "protocol");
cryptoctx = notmuch_crypto_get_context (node->ctx->crypto, protocol);
}
+#endif
/* Handle PGP/MIME parts */
if (GMIME_IS_MULTIPART_ENCRYPTED (part) && node->ctx->crypto->decrypt && cryptoctx) {
@@ -255,7 +267,11 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
"message (must be exactly 2)\n",
node->nchildren);
} else {
+#if (GMIME_MAJOR_VERSION < 3)
node_decrypt_and_verify (node, part, cryptoctx);
+#else
+ node_decrypt_and_verify (node, part);
+#endif
}
} else if (GMIME_IS_MULTIPART_SIGNED (part) && node->ctx->crypto->verify && cryptoctx) {
if (node->nchildren != 2) {
@@ -264,7 +280,11 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
"(must be exactly 2)\n",
node->nchildren);
} else {
+#if (GMIME_MAJOR_VERSION < 3)
node_verify (node, part, cryptoctx);
+#else
+ node_verify (node, part);
+#endif
}
}
diff --git a/notmuch-client.h b/notmuch-client.h
index 11aefbb4..c520089e 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -31,7 +31,9 @@
#include "gmime-extra.h"
+#if (GMIME_MAJOR_VERSION < 3)
typedef GMimeCryptoContext notmuch_crypto_context_t;
+#endif
/* This is automatically included only since gmime 2.6.10 */
#include <gmime/gmime-pkcs7-context.h>
@@ -72,11 +74,11 @@ typedef struct notmuch_show_format {
} notmuch_show_format_t;
typedef struct notmuch_crypto {
- notmuch_crypto_context_t* gpgctx;
- notmuch_crypto_context_t* pkcs7ctx;
notmuch_bool_t verify;
notmuch_bool_t decrypt;
#if (GMIME_MAJOR_VERSION < 3)
+ notmuch_crypto_context_t* gpgctx;
+ notmuch_crypto_context_t* pkcs7ctx;
const char *gpgpath;
#endif
} notmuch_crypto_t;
@@ -180,11 +182,13 @@ typedef struct _notmuch_config notmuch_config_t;
void
notmuch_exit_if_unsupported_format (void);
+#if (GMIME_MAJOR_VERSION < 3)
notmuch_crypto_context_t *
notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol);
int
notmuch_crypto_cleanup (notmuch_crypto_t *crypto);
+#endif
int
notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]);
diff --git a/notmuch-reply.c b/notmuch-reply.c
index b4a55362..69c26359 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -759,7 +759,9 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])
if (do_reply (config, query, ¶ms, format, reply_all) != 0)
return EXIT_FAILURE;
+#if (GMIME_MAJOR_VERSION < 3)
notmuch_crypto_cleanup (¶ms.crypto);
+#endif
notmuch_query_destroy (query);
notmuch_database_destroy (notmuch);
diff --git a/notmuch-show.c b/notmuch-show.c
index 6c135278..626bca80 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -1257,7 +1257,9 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
g_mime_stream_flush (params.out_stream);
g_object_unref (params.out_stream);
+#if (GMIME_MAJOR_VERSION < 3)
notmuch_crypto_cleanup (¶ms.crypto);
+#endif
notmuch_query_destroy (query);
notmuch_database_destroy (notmuch);
--
2.13.2
next prev parent reply other threads:[~2017-07-14 13:12 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-03 17:47 David Bremner
2017-06-03 17:47 ` [PATCH 01/23] emacs: convert to use format-version 3 David Bremner
2017-06-03 17:47 ` [PATCH 02/23] devel/schemata: describe version 4 David Bremner
2017-06-03 17:47 ` [PATCH 03/23] cli: implement structured output " David Bremner
2017-07-04 11:37 ` David Bremner
2017-06-03 17:47 ` [PATCH 04/23] test/multipart: reorganize creation of multipart message David Bremner
2017-06-03 17:47 ` [PATCH 05/23] test: mark inclusion of headers as broken in gmime-2.x David Bremner
2017-06-03 17:47 ` [PATCH 06/23] test: mark test as broken in gmime 3.0 David Bremner
2017-06-03 17:47 ` [PATCH 07/23] test/crypto: mark extra space in userid as a bug in gmime-2.6 David Bremner
2017-07-05 20:26 ` Tomi Ollila
2017-07-06 14:15 ` Daniel Kahn Gillmor
2017-06-03 17:47 ` [PATCH 08/23] test: add test for modified pgp/mime signed message David Bremner
2017-06-03 17:47 ` [PATCH 09/23] test/crypto: add test for corrupted signatures David Bremner
2017-07-05 11:03 ` David Bremner
2017-06-03 17:47 ` [PATCH 10/23] test: test parsing of malformed from addresses David Bremner
2017-06-03 17:47 ` [PATCH 11/23] cli: replace use of g_mime_message_get_date_as_string David Bremner
2017-06-03 17:47 ` [PATCH 12/23] cli: replace use of g_mime_message_get_reply_to David Bremner
2017-06-03 17:47 ` [PATCH 13/23] lib/cli: replace use of g_mime_message_get_sender David Bremner
2017-06-03 17:47 ` [PATCH 14/23] cli: replace use of g_mime_message_get_recipients David Bremner
2017-06-03 17:47 ` [PATCH 15/23] util: fake gmime-2.6 compatible API for gmime-3.0 David Bremner
2017-06-03 17:47 ` [PATCH 16/23] cli: generalize use of GMIME_SIGNATURE_{ERROR, STATUS} to gmime-3 David Bremner
2017-07-07 22:18 ` Daniel Kahn Gillmor
2017-06-03 17:47 ` [PATCH 17/23] cli: hide rename of GMimeCertificateTrust David Bremner
2017-06-03 17:47 ` [PATCH 18/23] lib: wrap use of g_mime_utils_header_decode_date David Bremner
2017-06-03 17:47 ` [PATCH 19/23] lib: refactor _notmuch_messsage_file_get_combined_header David Bremner
2017-06-03 17:47 ` [PATCH 20/23] lib: add version of _n_m_f_get_combinded_header for gmime 3.0 David Bremner
2017-06-03 17:47 ` [PATCH 21/23] lib: paper over allocation difference David Bremner
2017-06-03 17:47 ` [PATCH 22/23] cli: make keyid from fingerprint in gmime 3.0 David Bremner
2017-06-03 17:47 ` [PATCH 23/23] cli: wrap getting uid David Bremner
2017-07-14 13:12 ` [PATCH 1/3] config: deprecate/drop crypto.gpg_path under gmime 2.6/3.0 Daniel Kahn Gillmor
2017-07-14 13:12 ` [PATCH 2/3] clean up use of constants in g_mime_multipart_ wrappers Daniel Kahn Gillmor
2017-07-14 13:12 ` Daniel Kahn Gillmor [this message]
2017-07-15 11:55 ` [PATCH 3/3] crypto: Avoid explicit handling of GMimeCryptoContext in gmime 3.0 David Bremner
2017-07-15 18:57 ` [PATCH 1/4] cli/crypto: treat failure to create a crypto context as fatal David Bremner
2017-07-15 18:57 ` [PATCH 2/4] cli/crypto: eliminated compiler warnings about unused arguments David Bremner
2017-07-15 18:57 ` [PATCH 3/4] crypto: Avoid explicit handling of GMimeCryptoContext in gmime 3 David Bremner
2017-07-15 22:45 ` Daniel Kahn Gillmor
2017-07-15 23:01 ` [PATCH v2 1/4] cli/crypto: treat failure to create a crypto context as fatal Daniel Kahn Gillmor
2017-07-15 23:01 ` [PATCH v2 2/4] cli/crypto: eliminated compiler warnings about unused arguments Daniel Kahn Gillmor
2017-07-15 23:01 ` [PATCH v2 3/4] crypto: Avoid explicit handling of GMimeCryptoContext in gmime 3 Daniel Kahn Gillmor
2017-07-15 23:01 ` [PATCH v2 4/4] crypto: clean up unused definitions in gmime 3.0 Daniel Kahn Gillmor
2017-07-16 10:53 ` [PATCH v2 1/4] cli/crypto: treat failure to create a crypto context as fatal David Bremner
2017-07-15 18:57 ` [PATCH 4/4] crypto: clean up unused definitions in gmime 3.0 David Bremner
2017-07-14 13:19 ` [PATCH 1/3] config: deprecate/drop crypto.gpg_path under gmime 2.6/3.0 Daniel Kahn Gillmor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170714131202.24966-3-dkg@fifthhorseman.net \
--to=dkg@fifthhorseman.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).