src/pgp_gpg_internal.h
author us@chu.huenfield.org
Tue, 25 Dec 2018 14:46:45 +0100
branchsync
changeset 3209 c15b4ca2b52a
parent 3133 16fa0ec5951d
child 3234 538a03bab6b8
permissions -rw-r--r--
Replace use of Sequoia's backend with a custom key store.

- Sequoia's key store doesn't meet pep's needs (in particular, the
ability to search on a key's user id) and trying to shoehorn pep's
needs onto Sequoia's key store abstractions is just introducing
overhead with no appreciable gain in functionality.

- This patch changes the Sequoia backend to use a local sqlite
database to store the public keys.
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #pragma once
     5 
     6 #include <gpgme.h>
     7 
     8 // init
     9 
    10 typedef const char * (*gpgme_check_t)(const char*);
    11 typedef gpgme_error_t (*gpgme_get_engine_info_t)(gpgme_engine_info_t *INFO);
    12 typedef gpgme_error_t(*gpgme_set_locale_t)(gpgme_ctx_t CTX, int CATEGORY,
    13     const char *VALUE);
    14 typedef gpgme_error_t(*gpgme_new_t)(gpgme_ctx_t *CTX);
    15 typedef void(*gpgme_release_t)(gpgme_ctx_t CTX);
    16 typedef gpgme_error_t(*gpgme_set_protocol_t)(gpgme_ctx_t CTX,
    17     gpgme_protocol_t PROTO);
    18 typedef void(*gpgme_set_armor_t)(gpgme_ctx_t CTX, int YES);
    19 
    20 // data
    21 
    22 typedef gpgme_error_t(*gpgme_data_new_t)(gpgme_data_t *DH);
    23 typedef gpgme_error_t(*gpgme_data_new_from_mem_t)(gpgme_data_t *DH,
    24     const char *BUFFER, size_t SIZE, int COPY);
    25 typedef gpgme_error_t (*gpgme_data_new_from_cbs_t)(gpgme_data_t *DH,
    26         gpgme_data_cbs_t CBS, void *HANDLE);
    27 typedef void(*gpgme_data_release_t)(gpgme_data_t DH);
    28 typedef gpgme_data_type_t(*gpgme_data_identify_t)(gpgme_data_t DH);
    29 typedef size_t(*gpgme_data_seek_t)(gpgme_data_t DH, size_t OFFSET,
    30     int WHENCE);
    31 typedef size_t(*gpgme_data_read_t)(gpgme_data_t DH, void *BUFFER,
    32     size_t LENGTH);
    33 
    34 // encrypt and decrypt
    35 
    36 typedef gpgme_error_t(*gpgme_op_decrypt_t)(gpgme_ctx_t CTX,
    37     gpgme_data_t CIPHER, gpgme_data_t PLAIN);
    38 typedef gpgme_error_t(*gpgme_op_verify_t)(gpgme_ctx_t CTX, gpgme_data_t SIG,
    39     gpgme_data_t SIGNED_TEXT, gpgme_data_t PLAIN);
    40 typedef gpgme_error_t(*gpgme_op_decrypt_verify_t)(gpgme_ctx_t CTX,
    41     gpgme_data_t CIPHER, gpgme_data_t PLAIN);
    42 typedef gpgme_decrypt_result_t(*gpgme_op_decrypt_result_t)(gpgme_ctx_t CTX);
    43 typedef gpgme_error_t(*gpgme_op_encrypt_sign_t)(gpgme_ctx_t CTX,
    44     gpgme_key_t RECP[], gpgme_encrypt_flags_t FLAGS, gpgme_data_t PLAIN,
    45     gpgme_data_t CIPHER);
    46 typedef gpgme_error_t(*gpgme_op_encrypt_t)(gpgme_ctx_t CTX,
    47         gpgme_key_t RECP[], gpgme_encrypt_flags_t FLAGS, gpgme_data_t PLAIN,
    48         gpgme_data_t CIPHER);
    49 typedef gpgme_error_t(*gpgme_op_sign_t)(gpgme_ctx_t CTX,
    50         gpgme_data_t PLAIN, gpgme_data_t SIG, gpgme_sig_mode_t MODE);        
    51 typedef gpgme_verify_result_t(*gpgme_op_verify_result_t)(gpgme_ctx_t CTX);
    52 typedef void(*gpgme_signers_clear_t)(gpgme_ctx_t CTX);
    53 typedef gpgme_error_t(*gpgme_signers_add_t)(gpgme_ctx_t CTX, const gpgme_key_t KEY);
    54 
    55 // keys
    56 
    57 typedef gpgme_error_t(*gpgme_get_key_t)(gpgme_ctx_t CTX, const char *FPR,
    58     gpgme_key_t *R_KEY, int SECRET);
    59 typedef gpgme_error_t(*gpgme_op_genkey_t)(gpgme_ctx_t CTX, const char *PARMS,
    60     gpgme_data_t PUBLIC, gpgme_data_t SECRET);
    61 typedef gpgme_genkey_result_t(*gpgme_op_genkey_result_t)(gpgme_ctx_t CTX);
    62 typedef gpgme_error_t(*gpgme_op_delete_t)(gpgme_ctx_t CTX,
    63     const gpgme_key_t KEY, int ALLOW_SECRET);
    64 typedef gpgme_error_t(*gpgme_op_import_t)(gpgme_ctx_t CTX,
    65     gpgme_data_t KEYDATA);
    66 typedef gpgme_import_result_t(*gpgme_op_import_result_t)(gpgme_ctx_t CTX);
    67 typedef gpgme_error_t(*gpgme_op_export_t)(gpgme_ctx_t CTX,
    68     const char *PATTERN, gpgme_export_mode_t MODE, gpgme_data_t KEYDATA);
    69 typedef gpgme_error_t(*gpgme_set_keylist_mode_t)(gpgme_ctx_t CTX,
    70     gpgme_keylist_mode_t MODE);
    71 typedef gpgme_keylist_mode_t(*gpgme_get_keylist_mode_t)(gpgme_ctx_t CTX);
    72 typedef gpgme_error_t(*gpgme_op_keylist_start_t)(gpgme_ctx_t CTX,
    73     const char *PATTERN, int SECRET_ONLY);
    74 typedef gpgme_error_t(*gpgme_op_keylist_next_t)(gpgme_ctx_t CTX,
    75     gpgme_key_t *R_KEY);
    76 typedef gpgme_error_t(*gpgme_op_keylist_end_t)(gpgme_ctx_t CTX);
    77 typedef gpgme_error_t(*gpgme_op_import_keys_t)(gpgme_ctx_t CTX,
    78     gpgme_key_t *KEYS);
    79 typedef void(*gpgme_key_ref_t)(gpgme_key_t KEY);
    80 typedef void(*gpgme_key_unref_t)(gpgme_key_t KEY);
    81 typedef void(*gpgme_key_release_t)(gpgme_key_t KEY);
    82 typedef gpgme_error_t (*gpgme_op_edit_t)(gpgme_ctx_t CTX, gpgme_key_t KEY,
    83         gpgme_edit_cb_t FNC, void *HANDLE, gpgme_data_t OUT);
    84 typedef gpgme_ssize_t (*gpgme_io_write_t)(int fd, const void *buffer,
    85         size_t count);
    86 
    87 #ifdef GPGME_VERSION_NUMBER 
    88 #if (GPGME_VERSION_NUMBER >= 0x010700)
    89 typedef gpgme_error_t(*gpgme_op_createkey_t)(gpgme_ctx_t CTX, 
    90     const char *USERID, const char *ALGO, unsigned long RESERVED, 
    91     unsigned long EXPIRES, gpgme_key_t EXTRAKEY, unsigned int FLAGS);
    92 typedef gpgme_error_t(*gpgme_op_createsubkey_t)(gpgme_ctx_t ctx, 
    93     gpgme_key_t key, const char *algo, unsigned long reserved, 
    94     unsigned long expires, unsigned int flags);    
    95 #endif
    96 #endif
    97 
    98 
    99 typedef gpgme_error_t(*gpgme_set_passphrase_cb_t)(gpgme_ctx_t ctx, 
   100 		gpgme_passphrase_cb_t passfunc, void *hook_value);
   101 
   102 
   103 struct gpg_s {
   104     const char * version;
   105     gpgme_check_t gpgme_check;
   106     gpgme_get_engine_info_t gpgme_get_engine_info;
   107     gpgme_set_locale_t gpgme_set_locale;
   108     gpgme_new_t gpgme_new;
   109     gpgme_release_t gpgme_release;
   110     gpgme_set_protocol_t gpgme_set_protocol;
   111     gpgme_set_armor_t gpgme_set_armor;
   112 
   113     gpgme_data_new_t gpgme_data_new;
   114     gpgme_data_new_from_mem_t gpgme_data_new_from_mem;
   115     gpgme_data_new_from_cbs_t gpgme_data_new_from_cbs;
   116     gpgme_data_release_t gpgme_data_release;
   117     gpgme_data_identify_t gpgme_data_identify;
   118     gpgme_data_seek_t gpgme_data_seek;
   119     gpgme_data_read_t gpgme_data_read;
   120 
   121     gpgme_op_decrypt_t gpgme_op_decrypt;
   122     gpgme_op_verify_t gpgme_op_verify;
   123     gpgme_op_decrypt_verify_t gpgme_op_decrypt_verify;
   124     gpgme_op_decrypt_result_t gpgme_op_decrypt_result;
   125     gpgme_op_encrypt_sign_t gpgme_op_encrypt_sign;
   126     gpgme_op_encrypt_t gpgme_op_encrypt;
   127     gpgme_op_sign_t gpgme_op_sign;    
   128     gpgme_op_verify_result_t gpgme_op_verify_result;
   129     gpgme_signers_clear_t gpgme_signers_clear;
   130     gpgme_signers_add_t gpgme_signers_add;
   131 
   132     gpgme_get_key_t gpgme_get_key;
   133     gpgme_op_genkey_t gpgme_op_genkey;
   134     gpgme_op_genkey_result_t gpgme_op_genkey_result;
   135 #ifdef GPGME_VERSION_NUMBER 
   136 #if (GPGME_VERSION_NUMBER >= 0x010700)    
   137     gpgme_op_createkey_t gpgme_op_createkey;
   138     gpgme_op_createsubkey_t gpgme_op_createsubkey;
   139 #endif
   140 #endif    
   141     gpgme_op_delete_t gpgme_op_delete;
   142     gpgme_op_import_t gpgme_op_import;
   143     gpgme_op_import_result_t gpgme_op_import_result;
   144     gpgme_op_export_t gpgme_op_export;
   145     gpgme_set_keylist_mode_t gpgme_set_keylist_mode;
   146     gpgme_get_keylist_mode_t gpgme_get_keylist_mode;
   147     gpgme_op_keylist_start_t gpgme_op_keylist_start;
   148     gpgme_op_keylist_next_t gpgme_op_keylist_next;
   149     gpgme_op_keylist_end_t gpgme_op_keylist_end;
   150     gpgme_op_import_keys_t gpgme_op_import_keys;
   151     gpgme_key_ref_t gpgme_key_ref;
   152     gpgme_key_unref_t gpgme_key_unref;
   153 	gpgme_key_release_t gpgme_key_release;
   154     gpgme_op_edit_t gpgme_op_edit;
   155     gpgme_io_write_t gpgme_io_write;
   156 
   157     gpgme_set_passphrase_cb_t gpgme_set_passphrase_cb;
   158 };