--- /dev/null
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id F3AE46DE17A0\r
+ for <notmuch@notmuchmail.org>; Fri, 11 Dec 2015 05:55:07 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.319\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.319 tagged_above=-999 required=5 tests=[AWL=0.232,\r
+ RP_MATCHES_RCVD=-0.55, SPF_PASS=-0.001] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id g5cwXdcAEN1d for <notmuch@notmuchmail.org>;\r
+ Fri, 11 Dec 2015 05:55:06 -0800 (PST)\r
+Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id AC90B6DE00DD\r
+ for <notmuch@notmuchmail.org>; Fri, 11 Dec 2015 05:54:58 -0800 (PST)\r
+Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1a7O9u-0000Rs-DA; Fri, 11 Dec 2015 08:54:54 -0500\r
+Received: (nullmailer pid 11204 invoked by uid 1000);\r
+ Fri, 11 Dec 2015 13:54:52 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [Patch v2 2/8] crypto: make crypto ctx initialization an array\r
+Date: Fri, 11 Dec 2015 09:54:41 -0400\r
+Message-Id: <1449842087-10972-3-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.6.2\r
+In-Reply-To: <1449842087-10972-1-git-send-email-david@tethera.net>\r
+References: <1449842087-10972-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 11 Dec 2015 13:55:08 -0000\r
+\r
+From: Jani Nikula <jani@nikula.org>\r
+\r
+Make it trivial to add handlers for new protocols without duplicating\r
+code. No functional changes.\r
+---\r
+ crypto.c | 27 +++++++++++++++++++++------\r
+ 1 file changed, 21 insertions(+), 6 deletions(-)\r
+\r
+diff --git a/crypto.c b/crypto.c\r
+index 1187ad7..da0289d 100644\r
+--- a/crypto.c\r
++++ b/crypto.c\r
+@@ -43,12 +43,27 @@ create_gpg_context (notmuch_crypto_t *crypto)\r
+ return gpgctx;\r
+ }\r
+ \r
++static const struct {\r
++ const char *protocol;\r
++ notmuch_crypto_context_t *(*get_context) (notmuch_crypto_t *crypto);\r
++} protocols[] = {\r
++ {\r
++ .protocol = "application/pgp-signature",\r
++ .get_context = create_gpg_context,\r
++ },\r
++ {\r
++ .protocol = "application/pgp-encrypted",\r
++ .get_context = create_gpg_context,\r
++ },\r
++};\r
++\r
+ /* for the specified protocol return the context pointer (initializing\r
+ * if needed) */\r
+ notmuch_crypto_context_t *\r
+ notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol)\r
+ {\r
+ notmuch_crypto_context_t *cryptoctx = NULL;\r
++ size_t i;\r
+ \r
+ if (! protocol) {\r
+ fprintf (stderr, "Cryptographic protocol is empty.\n");\r
+@@ -61,14 +76,14 @@ notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol)\r
+ * parameter names as defined in this document are\r
+ * case-insensitive." Thus, we use strcasecmp for the protocol.\r
+ */\r
+- if (strcasecmp (protocol, "application/pgp-signature") == 0 ||\r
+- strcasecmp (protocol, "application/pgp-encrypted") == 0) {\r
+- cryptoctx = create_gpg_context (crypto);\r
+- } else {\r
+- fprintf (stderr, "Unknown or unsupported cryptographic protocol.\n");\r
++ for (i = 0; i < ARRAY_SIZE (protocols); i++) {\r
++ if (strcasecmp (protocol, protocols[i].protocol) == 0)\r
++ return protocols[i].get_context (crypto);\r
+ }\r
+ \r
+- return cryptoctx;\r
++ fprintf (stderr, "Unknown or unsupported cryptographic protocol.\n");\r
++\r
++ return NULL;\r
+ }\r
+ \r
+ int\r
+-- \r
+2.6.2\r
+\r