crypt-mod.h 5.18 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (C) 2004 g10 Code GmbH
 *
 *     This program is free software; you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation; either version 2 of the License, or
 *     (at your option) any later version.
 * 
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 * 
 *     You should have received a copy of the GNU General Public License
 *     along with this program; if not, write to the Free Software
16
 *     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 18 19 20 21 22 23 24 25 26 27 28
 */

#ifndef CRYPTOGRAPHY_H
#define CRYPTOGRAPHY_H

#include "mutt.h"
#include "mutt_crypt.h"

#define CRYPTO_SUPPORT(identifier) (WithCrypto & APPLICATION_ ## identifier)


/* 
Ondřej Bílka's avatar
Ondřej Bílka committed
29
    Type definitions for crypto module functions.
30 31 32 33 34 35 36
 */
typedef void (*crypt_func_void_passphrase_t) (void);
typedef int (*crypt_func_valid_passphrase_t)  (void);

typedef int (*crypt_func_decrypt_mime_t) (FILE *a, FILE **b,
                                          BODY *c, BODY **d);

37 38
typedef int (*crypt_func_application_handler_t) (BODY *m, STATE *s);
typedef int (*crypt_func_encrypted_handler_t) (BODY *m, STATE *s);
39 40 41

typedef void (*crypt_func_pgp_invoke_getkeys_t) (ADDRESS *addr);
typedef int (*crypt_func_pgp_check_traditional_t) (FILE *fp, BODY *b,
42
                                                   int just_one);
43 44 45
typedef BODY *(*crypt_func_pgp_traditional_encryptsign_t) (BODY *a, int flags,
                                                           char *keylist);
typedef BODY *(*crypt_func_pgp_make_key_attachment_t) (char *tempf);
46
typedef char *(*crypt_func_findkeys_t) (ADDRESS *adrlist, int oppenc_mode);
47 48 49 50 51 52 53 54 55
typedef BODY *(*crypt_func_sign_message_t) (BODY *a);
typedef BODY *(*crypt_func_pgp_encrypt_message_t) (BODY *a, char *keylist,
                                                   int sign);
typedef void (*crypt_func_pgp_invoke_import_t) (const char *fname);
typedef int (*crypt_func_verify_one_t) (BODY *sigbdy, STATE *s,
                                        const char *tempf);
typedef void (*crypt_func_pgp_extract_keys_from_attachment_list_t) 
                                           (FILE *fp, int tag, BODY *top);

56
typedef int (*crypt_func_send_menu_t) (HEADER *msg);
57 58 59 60 61 62 63 64 65 66 67 68

 /* (SMIME) */
typedef void (*crypt_func_smime_getkeys_t) (ENVELOPE *env);
typedef int (*crypt_func_smime_verify_sender_t) (HEADER *h);

typedef BODY *(*crypt_func_smime_build_smime_entity_t) (BODY *a,
                                                        char *certlist);

typedef void (*crypt_func_smime_invoke_import_t) (char *infile, char *mailbox);

typedef void (*crypt_func_init_t) (void);

69
typedef void (*crypt_func_set_sender_t) (const char *sender);
70 71

/*
72
   A structure to keep all crypto module functions together.
73 74 75 76 77 78 79 80 81 82 83 84 85 86
 */
typedef struct crypt_module_functions
{
  /* Common/General functions.  */
  crypt_func_init_t init;
  crypt_func_void_passphrase_t void_passphrase;
  crypt_func_valid_passphrase_t valid_passphrase;
  crypt_func_decrypt_mime_t decrypt_mime;
  crypt_func_application_handler_t application_handler;
  crypt_func_encrypted_handler_t encrypted_handler;
  crypt_func_findkeys_t findkeys;
  crypt_func_sign_message_t sign_message;
  crypt_func_verify_one_t verify_one;
  crypt_func_send_menu_t send_menu;
87
  crypt_func_set_sender_t set_sender;
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108

  /* PGP specific functions.  */
  crypt_func_pgp_encrypt_message_t pgp_encrypt_message;
  crypt_func_pgp_make_key_attachment_t pgp_make_key_attachment;
  crypt_func_pgp_check_traditional_t pgp_check_traditional;
  crypt_func_pgp_traditional_encryptsign_t pgp_traditional_encryptsign;
  crypt_func_pgp_invoke_getkeys_t pgp_invoke_getkeys;
  crypt_func_pgp_invoke_import_t pgp_invoke_import;
  crypt_func_pgp_extract_keys_from_attachment_list_t
                                 pgp_extract_keys_from_attachment_list;

  /* S/MIME specific functions.  */

  crypt_func_smime_getkeys_t smime_getkeys;
  crypt_func_smime_verify_sender_t smime_verify_sender;
  crypt_func_smime_build_smime_entity_t smime_build_smime_entity;
  crypt_func_smime_invoke_import_t smime_invoke_import;
} crypt_module_functions_t;


/*
Ondřej Bílka's avatar
Ondřej Bílka committed
109
   A structure to describe a crypto module. 
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
 */
typedef struct crypt_module_specs
{
  int identifier;			/* Identifying bit.  */
  crypt_module_functions_t functions;
} *crypt_module_specs_t;



/* 
   High Level crypto module interface. 
 */

void crypto_module_register (crypt_module_specs_t specs);
crypt_module_specs_t crypto_module_lookup (int identifier);

/* If the crypto module identifier by IDENTIFIER has been registered,
   call its function FUNC.  Do nothing else.  This may be used as an
   expression. */
#define CRYPT_MOD_CALL_CHECK(identifier, func) \
  (crypto_module_lookup (APPLICATION_ ## identifier) \
   && (crypto_module_lookup (APPLICATION_ ## identifier))->functions.func)

/* Call the function FUNC in the crypto module identified by
   IDENTIFIER. This may be used as an expression. */
#define CRYPT_MOD_CALL(identifier, func) \
  *(crypto_module_lookup (APPLICATION_ ## identifier))->functions.func

#endif