From c55aa3dacb53b38f4acc9f8679927756c6ddde2a Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Tue, 3 Apr 2007 01:50:28 +0200 Subject: [PATCH] and even less cruft. Signed-off-by: Pierre Habouzit --- lib-crypt/Makefile.am | 4 +-- lib-crypt/crypt-gpgme.c | 34 ++++++++------------------ lib-crypt/crypt-gpgme.h | 54 ----------------------------------------- lib-crypt/cryptglue.c | 53 ---------------------------------------- 4 files changed, 12 insertions(+), 133 deletions(-) delete mode 100644 lib-crypt/crypt-gpgme.h diff --git a/lib-crypt/Makefile.am b/lib-crypt/Makefile.am index e5af18b..87c3c1e 100644 --- a/lib-crypt/Makefile.am +++ b/lib-crypt/Makefile.am @@ -1,8 +1,8 @@ noinst_LIBRARIES = libcrypt.a -libcrypt_a_SOURCES = crypt.h crypt-gpgme.h \ +libcrypt_a_SOURCES = crypt.h \ crypt.c crypt-gpgme.c cryptglue.c -noinst_HEADERS = crypt.h crypt-gpgme.h +noinst_HEADERS = crypt.h -include $(top_builddir)/tools/cflags.mk diff --git a/lib-crypt/crypt-gpgme.c b/lib-crypt/crypt-gpgme.c index 7b6787e..7c24186 100644 --- a/lib-crypt/crypt-gpgme.c +++ b/lib-crypt/crypt-gpgme.c @@ -27,31 +27,19 @@ #include #include - #include #include #include +#include "crypt.h" + #include "lib.h" #include "alias.h" -#include #include "handler.h" #include "copy.h" #include "pager.h" #include "recvattach.h" #include "sort.h" -#include "crypt-gpgme.h" - -/* - * Helper macros. - */ -#define digitp(p) (*(p) >= '0' && *(p) <= '9') -#define hexdigitp(a) (digitp (a) \ - || (*(a) >= 'A' && *(a) <= 'F') \ - || (*(a) >= 'a' && *(a) <= 'f')) -#define xtoi_1(p) (*(p) <= '9'? (*(p)- '0'): \ - *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10)) -#define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1)) /* Values used for comparing addresses. */ #define CRYPT_KV_VALID 1 @@ -875,7 +863,7 @@ BODY *crypt_pgp_encrypt_message (BODY * a, char *keylist, int sign) /* Encrypt the mail body A to all keys given as space separated fingerprints in KEYLIST and return the S/MIME encrypted body. */ -BODY *smime_gpgme_build_smime_entity (BODY * a, char *keylist) +BODY *crypt_smime_build_smime_entity (BODY * a, char *keylist) { char *outfile = NULL; BODY *t; @@ -1980,12 +1968,10 @@ int crypt_pgp_application_pgp_handler (BODY * m, STATE * s) return (err); } -/* - * Implementation of `encrypted_handler'. - */ +/* Implementation of `encrypted_handler'. */ /* MIME handler for pgp/mime encrypted messages. */ -int pgp_gpgme_encrypted_handler (BODY * a, STATE * s) +int crypt_pgp_encrypted_handler (BODY * a, STATE * s) { char tempfile[_POSIX_PATH_MAX]; FILE *fpout; @@ -2525,7 +2511,7 @@ static const unsigned char *parse_dn_part (struct dn_array_s *array, if (*string == '#') { /* hexstring */ string++; - for (s = string; hexdigitp (s); s++) + for (s = string; hexval(*s) >= 0; s++) s++; n = s - string; if (!n || (n & 1)) @@ -2534,7 +2520,7 @@ static const unsigned char *parse_dn_part (struct dn_array_s *array, p = p_new(unsigned char, n + 1); array->value = (char *) p; for (s1 = string; n; s1 += 2, n--) - *p++ = xtoi_2 (s1); + *p++ = (hexval(*s1) << 8) | hexval(*s1); *p = 0; } else { /* regular v3 quoted string */ @@ -2545,7 +2531,7 @@ static const unsigned char *parse_dn_part (struct dn_array_s *array, || *s == '<' || *s == '>' || *s == '#' || *s == ';' || *s == '\\' || *s == '\"' || *s == ' ') n++; - else if (hexdigitp (s) && hexdigitp (s + 1)) { + else if (hexval(*s) >= 0 && hexval(*s + 1) >= 0) { s++; n++; } @@ -2566,8 +2552,8 @@ static const unsigned char *parse_dn_part (struct dn_array_s *array, for (s = string; n; s++, n--) { if (*s == '\\') { s++; - if (hexdigitp (s)) { - *p++ = xtoi_2 (s); + if (hexval(*s) >= 0) { + *p++ = (hexval(*s) << 8) | hexval(*s + 1); s++; } else diff --git a/lib-crypt/crypt-gpgme.h b/lib-crypt/crypt-gpgme.h deleted file mode 100644 index 4c4e021..0000000 --- a/lib-crypt/crypt-gpgme.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright notice from original mutt: - * Copyright (C) 2004 g10 Code GmbH - * - * This file is part of mutt-ng, see http://www.muttng.org/. - * It's licensed under the GNU General Public License, - * please see the file GPL in the top level source directory. - */ - -#ifndef CRYPT_GPGME_H -#define CRYPT_GPGME_H - -#include - -/* {{{ cruft */ - -/* Type defintions for crypto module functions. */ -typedef int (*crypt_func_encrypted_handler_t) (BODY * m, STATE * s); - -typedef void (*crypt_func_pgp_invoke_getkeys_t) (address_t * addr); -typedef BODY *(*crypt_func_pgp_make_key_attachment_t) (char *tempf); -typedef int (*crypt_func_send_menu_t) (HEADER * msg, int *redraw); - - /* (SMIME) */ -typedef void (*crypt_func_smime_getkeys_t) (ENVELOPE * env); -typedef BODY *(*crypt_func_smime_build_smime_entity_t) (BODY * a, - char *certlist); - -typedef struct crypt_module_specs { - /* Common/General functions. */ - crypt_func_encrypted_handler_t encrypted_handler; - - /* PGP specific functions. */ - crypt_func_pgp_make_key_attachment_t pgp_make_key_attachment; - crypt_func_pgp_invoke_getkeys_t pgp_invoke_getkeys; - - /* S/MIME specific functions. */ - crypt_func_smime_getkeys_t smime_getkeys; - crypt_func_smime_build_smime_entity_t smime_build_smime_entity; -} crypt_module_specs_t; - -extern struct crypt_module_specs crypt_mod_SMIME_gpgme; -extern struct crypt_module_specs crypt_mod_PGP_gpgme; - -/* }}} */ - -BODY *pgp_gpgme_encrypt_message (BODY * a, char *keylist, int sign); -BODY *smime_gpgme_build_smime_entity (BODY * a, char *keylist); - -int pgp_gpgme_check_traditional (FILE * fp, BODY * b, int tagged_only); -int pgp_gpgme_encrypted_handler (BODY * a, STATE * s); -BODY *pgp_gpgme_make_key_attachment (char *tempf); - -#endif diff --git a/lib-crypt/cryptglue.c b/lib-crypt/cryptglue.c index c6b4e94..e349698 100644 --- a/lib-crypt/cryptglue.c +++ b/lib-crypt/cryptglue.c @@ -23,60 +23,17 @@ #include "mutt.h" #include "crypt.h" -#include "crypt-gpgme.h" - -#define CRYPT_MOD_CALL_CHECK(identifier, func) \ - ((crypt_mod_##identifier##_gpgme).func) - -#define CRYPT_MOD_CALL(identifier, func) \ - (*((crypt_mod_##identifier##_gpgme).func)) - - -struct crypt_module_specs crypt_mod_SMIME_gpgme = { - NULL, /* encrypted_handler */ - - NULL, /* pgp_make_key_attachment */ - NULL, /* pgp_invoke_getkeys */ - - NULL, /* smime_getkeys */ - smime_gpgme_build_smime_entity, -}; - -struct crypt_module_specs crypt_mod_PGP_gpgme = { - pgp_gpgme_encrypted_handler, - - /* PGP specific. */ - NULL, /* pgp_make_key_attachment, */ - NULL, /* pgp_invoke_getkeys */ - - NULL, /* smime_getkeys */ - NULL, /* smime_build_smime_entity */ -}; - /* PGP */ -/* MIME handler for an PGP/MIME encrypted message. */ -int crypt_pgp_encrypted_handler (BODY * a, STATE * s) -{ - if (CRYPT_MOD_CALL_CHECK (PGP, encrypted_handler)) - return (CRYPT_MOD_CALL (PGP, encrypted_handler)) (a, s); - return (-1); -} - /* fixme: needs documentation. */ void crypt_pgp_invoke_getkeys (address_t * addr) { - if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_getkeys)) - (CRYPT_MOD_CALL (PGP, pgp_invoke_getkeys)) (addr); } /* Generate a PGP public key attachment. */ BODY *crypt_pgp_make_key_attachment (char *tempf) { - if (CRYPT_MOD_CALL_CHECK (PGP, pgp_make_key_attachment)) - return (CRYPT_MOD_CALL (PGP, pgp_make_key_attachment)) (tempf); - return NULL; } @@ -85,15 +42,5 @@ BODY *crypt_pgp_make_key_attachment (char *tempf) /* fixme: Needs documentation. */ void crypt_smime_getkeys (ENVELOPE * env) { - if (CRYPT_MOD_CALL_CHECK (SMIME, smime_getkeys)) - (CRYPT_MOD_CALL (SMIME, smime_getkeys)) (env); } -/* fixme: needs documentation. */ -BODY *crypt_smime_build_smime_entity (BODY * a, char *certlist) -{ - if (CRYPT_MOD_CALL_CHECK (SMIME, smime_build_smime_entity)) - return (CRYPT_MOD_CALL (SMIME, smime_build_smime_entity)) (a, certlist); - - return NULL; -} -- 2.20.1