From e5b3778591e0ba9306ea4151c209dc44f453da13 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Sun, 18 Jan 2015 12:45:52 +0200 Subject: [PATCH] [PATCH 2/3] crypto: make crypto ctx initialization an array --- 6d/e4a2b478383cd1e374d910f78f7f2b8b9a196d | 137 ++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 6d/e4a2b478383cd1e374d910f78f7f2b8b9a196d diff --git a/6d/e4a2b478383cd1e374d910f78f7f2b8b9a196d b/6d/e4a2b478383cd1e374d910f78f7f2b8b9a196d new file mode 100644 index 000000000..484aba47d --- /dev/null +++ b/6d/e4a2b478383cd1e374d910f78f7f2b8b9a196d @@ -0,0 +1,137 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 0FFED431FDD + for ; Sun, 18 Jan 2015 02:45:50 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +X-Spam-Flag: NO +X-Spam-Score: 1.738 +X-Spam-Level: * +X-Spam-Status: No, score=1.738 tagged_above=-999 required=5 + tests=[DNS_FROM_AHBL_RHSBL=2.438, RCVD_IN_DNSWL_LOW=-0.7] + autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id hbQjwuVxHR8O for ; + Sun, 18 Jan 2015 02:45:46 -0800 (PST) +Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com + [209.85.212.177]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 9CE61431FAF + for ; Sun, 18 Jan 2015 02:45:46 -0800 (PST) +Received: by mail-wi0-f177.google.com with SMTP id r20so3446881wiv.4 + for ; Sun, 18 Jan 2015 02:45:45 -0800 (PST) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to + :references:in-reply-to:references; + bh=s5EvZrwOzpq6z17W7jr3MwupDGayXQnmQwpBa5litsE=; + b=aQoGBofJh9+/rBIgnXU+hAEfl3HkWc7rpEvlkjsdl8TYZiZoDa8FFRsqNEKS1Mh6Os + yWnXcWQQfWy5Q9m5JWQIO1W1b3GJMuTh9Z0ww8xBl1B2DuubuELHuKHvAIQUO10EMSMX + 9WV7wIsDpslyD7WD+S1Mf6zecRN4hMyUcbTQcUNBzXIGTvl36XSyjmjn90gK/fpPqkGH + PI5fg6qtG0cf8J3DcYqPXLAvcKmvzMXhZIz7XtBoc/wNqmidkXHPhzF5PF58tbKcm92A + kK+3wrAziwr+cXHstxDAxomB1luW7NucHR8z3XPiq1LJjpY6RuSlb3Ben5Jj8g/R9jRj + BLYQ== +X-Gm-Message-State: + ALoCoQm6w7FJtO5rqBdBWNPR1hhapn/cmVN+yBjlKunxC5RWfG0mJSsIXPSVpkEKt7ZiOli2aNuv +X-Received: by 10.180.105.68 with SMTP id gk4mr23492789wib.30.1421577945454; + Sun, 18 Jan 2015 02:45:45 -0800 (PST) +Received: from localhost (mobile-internet-bcee14-89.dhcp.inet.fi. + [188.238.20.89]) by mx.google.com with ESMTPSA id + u13sm12925112wjr.26.2015.01.18.02.45.44 + (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Sun, 18 Jan 2015 02:45:44 -0800 (PST) +From: Jani Nikula +To: david@tethera.net, + notmuch@notmuchmail.org +Subject: [PATCH 2/3] crypto: make crypto ctx initialization an array +Date: Sun, 18 Jan 2015 12:45:52 +0200 +Message-Id: + <9778978083b0a086678803e79df2c901a9d7f3e7.1421577605.git.jani@nikula.org> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: +References: <1421568167-18683-3-git-send-email-david@tethera.net> + +In-Reply-To: +References: +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sun, 18 Jan 2015 10:45:50 -0000 + +--- + crypto.c | 30 ++++++++++++++++++++++-------- + 1 file changed, 22 insertions(+), 8 deletions(-) + +diff --git a/crypto.c b/crypto.c +index 7cd7b69d1221..8e58dcca4ee5 100644 +--- a/crypto.c ++++ b/crypto.c +@@ -74,16 +74,30 @@ create_gpg_context (notmuch_crypto_t *crypto) + + #endif /* GMIME_ATLEAST_26 */ + ++static struct { ++ const char *protocol; ++ notmuch_crypto_context_t *(*get_context) (notmuch_crypto_t *crypto); ++} protocols[] = { ++ { ++ .protocol = "application/pgp-signature", ++ .get_context = create_gpg_context, ++ }, ++ { ++ .protocol = "application/pgp-encrypted", ++ .get_context = create_gpg_context, ++ }, ++}; ++ + /* for the specified protocol return the context pointer (initializing + * if needed) */ + notmuch_crypto_context_t * + notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol) + { +- notmuch_crypto_context_t *cryptoctx = NULL; ++ size_t i; + + if (! protocol) { + fprintf (stderr, "Cryptographic protocol is empty.\n"); +- return cryptoctx; ++ return NULL; + } + + /* As per RFC 1847 section 2.1: "the [protocol] value token is +@@ -92,14 +106,14 @@ notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol) + * parameter names as defined in this document are + * case-insensitive." Thus, we use strcasecmp for the protocol. + */ +- if (strcasecmp (protocol, "application/pgp-signature") == 0 || +- strcasecmp (protocol, "application/pgp-encrypted") == 0) { +- cryptoctx = create_gpg_context (crypto); +- } else { +- fprintf (stderr, "Unknown or unsupported cryptographic protocol.\n"); ++ for (i = 0; i < ARRAY_SIZE (protocols); i++) { ++ if (strcasecmp (protocol, protocols[i].protocol) == 0) ++ return protocols[i].get_context (crypto); + } + +- return cryptoctx; ++ fprintf (stderr, "Unknown or unsupported cryptographic protocol.\n"); ++ ++ return NULL; + } + + int +-- +2.1.4 + -- 2.26.2