[PATCH 2/3] crypto: make crypto ctx initialization an array
authorJani Nikula <jani@nikula.org>
Sun, 18 Jan 2015 10:45:52 +0000 (12:45 +0200)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 21:47:32 +0000 (14:47 -0700)
6d/e4a2b478383cd1e374d910f78f7f2b8b9a196d [new file with mode: 0644]

diff --git a/6d/e4a2b478383cd1e374d910f78f7f2b8b9a196d b/6d/e4a2b478383cd1e374d910f78f7f2b8b9a196d
new file mode 100644 (file)
index 0000000..484aba4
--- /dev/null
@@ -0,0 +1,137 @@
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 0FFED431FDD\r
+       for <notmuch@notmuchmail.org>; Sun, 18 Jan 2015 02:45:50 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 1.738\r
+X-Spam-Level: *\r
+X-Spam-Status: No, score=1.738 tagged_above=-999 required=5\r
+       tests=[DNS_FROM_AHBL_RHSBL=2.438, RCVD_IN_DNSWL_LOW=-0.7]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id hbQjwuVxHR8O for <notmuch@notmuchmail.org>;\r
+       Sun, 18 Jan 2015 02:45:46 -0800 (PST)\r
+Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com\r
+       [209.85.212.177]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 9CE61431FAF\r
+       for <notmuch@notmuchmail.org>; Sun, 18 Jan 2015 02:45:46 -0800 (PST)\r
+Received: by mail-wi0-f177.google.com with SMTP id r20so3446881wiv.4\r
+       for <notmuch@notmuchmail.org>; Sun, 18 Jan 2015 02:45:45 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=1e100.net; s=20130820;\r
+       h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
+       :references:in-reply-to:references;\r
+       bh=s5EvZrwOzpq6z17W7jr3MwupDGayXQnmQwpBa5litsE=;\r
+       b=aQoGBofJh9+/rBIgnXU+hAEfl3HkWc7rpEvlkjsdl8TYZiZoDa8FFRsqNEKS1Mh6Os\r
+       yWnXcWQQfWy5Q9m5JWQIO1W1b3GJMuTh9Z0ww8xBl1B2DuubuELHuKHvAIQUO10EMSMX\r
+       9WV7wIsDpslyD7WD+S1Mf6zecRN4hMyUcbTQcUNBzXIGTvl36XSyjmjn90gK/fpPqkGH\r
+       PI5fg6qtG0cf8J3DcYqPXLAvcKmvzMXhZIz7XtBoc/wNqmidkXHPhzF5PF58tbKcm92A\r
+       kK+3wrAziwr+cXHstxDAxomB1luW7NucHR8z3XPiq1LJjpY6RuSlb3Ben5Jj8g/R9jRj\r
+       BLYQ==\r
+X-Gm-Message-State:\r
+ ALoCoQm6w7FJtO5rqBdBWNPR1hhapn/cmVN+yBjlKunxC5RWfG0mJSsIXPSVpkEKt7ZiOli2aNuv\r
+X-Received: by 10.180.105.68 with SMTP id gk4mr23492789wib.30.1421577945454;\r
+       Sun, 18 Jan 2015 02:45:45 -0800 (PST)\r
+Received: from localhost (mobile-internet-bcee14-89.dhcp.inet.fi.\r
+       [188.238.20.89]) by mx.google.com with ESMTPSA id\r
+       u13sm12925112wjr.26.2015.01.18.02.45.44\r
+       (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+       Sun, 18 Jan 2015 02:45:44 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: david@tethera.net,\r
+       notmuch@notmuchmail.org\r
+Subject: [PATCH 2/3] crypto: make crypto ctx initialization an array\r
+Date: Sun, 18 Jan 2015 12:45:52 +0200\r
+Message-Id:\r
+ <9778978083b0a086678803e79df2c901a9d7f3e7.1421577605.git.jani@nikula.org>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <cover.1421577605.git.jani@nikula.org>\r
+References: <1421568167-18683-3-git-send-email-david@tethera.net>\r
+       <cover.1421577605.git.jani@nikula.org>\r
+In-Reply-To: <cover.1421577605.git.jani@nikula.org>\r
+References: <cover.1421577605.git.jani@nikula.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://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: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 18 Jan 2015 10:45:50 -0000\r
+\r
+---\r
+ crypto.c | 30 ++++++++++++++++++++++--------\r
+ 1 file changed, 22 insertions(+), 8 deletions(-)\r
+\r
+diff --git a/crypto.c b/crypto.c\r
+index 7cd7b69d1221..8e58dcca4ee5 100644\r
+--- a/crypto.c\r
++++ b/crypto.c\r
+@@ -74,16 +74,30 @@ create_gpg_context (notmuch_crypto_t *crypto)\r
\r
+ #endif /* GMIME_ATLEAST_26 */\r
\r
++static 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
+-      return cryptoctx;\r
++      return NULL;\r
+     }\r
\r
+     /* As per RFC 1847 section 2.1: "the [protocol] value token is\r
+@@ -92,14 +106,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.1.4\r
+\r