src/cryptotech.c
author Volker Birk <vb@pep-project.org>
Fri, 17 May 2019 17:59:06 +0200
branchsync
changeset 3720 9ed76a79d784
parent 3689 6ea4a0524c38
child 4065 7f0cf93bc2af
child 4471 2738f89bde23
permissions -rw-r--r--
...
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #include "pEp_internal.h"
     5 
     6 #ifdef USE_GPG
     7 #include "pgp_gpg.h"
     8 #else
     9 #ifdef USE_NETPGP
    10 #include "pgp_netpgp.h"
    11 #else
    12 #ifdef USE_SEQUOIA
    13 #include "pgp_sequoia.h"
    14 #endif
    15 #endif
    16 #endif
    17 // 
    18 
    19 #include <stdlib.h>
    20 #include <memory.h>
    21 #include <assert.h>
    22 
    23 PEP_cryptotech_t cryptotech[PEP_crypt__count];
    24 
    25 PEP_STATUS init_cryptotech(PEP_SESSION session, bool in_first)
    26 {
    27     PEP_STATUS status = PEP_STATUS_OK;
    28 
    29     assert(PEP_crypt__count == 2);
    30 
    31     if (in_first) {
    32         memset(cryptotech, 0, sizeof(PEP_cryptotech_t) * PEP_crypt__count);
    33 
    34         cryptotech[PEP_crypt_none].id = PEP_crypt_none;
    35         cryptotech[PEP_crypt_none].unconfirmed_comm_type = PEP_ct_no_encryption;
    36         cryptotech[PEP_crypt_none].confirmed_comm_type = PEP_ct_no_encryption;
    37 
    38         cryptotech[PEP_crypt_OpenPGP].id = PEP_crypt_OpenPGP;
    39         cryptotech[PEP_crypt_OpenPGP].unconfirmed_comm_type = PEP_ct_OpenPGP_unconfirmed;
    40         cryptotech[PEP_crypt_OpenPGP].confirmed_comm_type = PEP_ct_OpenPGP;
    41         cryptotech[PEP_crypt_OpenPGP].decrypt_and_verify = pgp_decrypt_and_verify;
    42         cryptotech[PEP_crypt_OpenPGP].encrypt_and_sign = pgp_encrypt_and_sign;
    43         cryptotech[PEP_crypt_OpenPGP].encrypt_only = pgp_encrypt_only;
    44         cryptotech[PEP_crypt_OpenPGP].sign_only = pgp_sign_only;        
    45         cryptotech[PEP_crypt_OpenPGP].verify_text = pgp_verify_text;
    46         cryptotech[PEP_crypt_OpenPGP].delete_keypair = pgp_delete_keypair;
    47         cryptotech[PEP_crypt_OpenPGP].export_key = pgp_export_keydata;
    48         cryptotech[PEP_crypt_OpenPGP].find_keys = pgp_find_keys;
    49         cryptotech[PEP_crypt_OpenPGP].generate_keypair = pgp_generate_keypair;
    50         cryptotech[PEP_crypt_OpenPGP].get_key_rating = pgp_get_key_rating;
    51         cryptotech[PEP_crypt_OpenPGP].import_key = pgp_import_keydata;
    52         cryptotech[PEP_crypt_OpenPGP].recv_key = pgp_recv_key;
    53         cryptotech[PEP_crypt_OpenPGP].send_key = pgp_send_key;
    54         cryptotech[PEP_crypt_OpenPGP].renew_key = pgp_renew_key;
    55         cryptotech[PEP_crypt_OpenPGP].revoke_key = pgp_revoke_key;
    56         cryptotech[PEP_crypt_OpenPGP].key_expired = pgp_key_expired;
    57         cryptotech[PEP_crypt_OpenPGP].key_revoked = pgp_key_revoked;
    58         cryptotech[PEP_crypt_OpenPGP].key_created = pgp_key_created;
    59         cryptotech[PEP_crypt_OpenPGP].contains_priv_key = pgp_contains_priv_key;
    60         cryptotech[PEP_crypt_OpenPGP].find_private_keys = pgp_find_private_keys;
    61         cryptotech[PEP_crypt_OpenPGP].config_cipher_suite = pgp_config_cipher_suite;
    62 #ifdef PGP_BINARY_PATH
    63         cryptotech[PEP_crypt_OpenPGP].binary_path = PGP_BINARY_PATH;
    64 #endif
    65     }
    66 
    67     session->cryptotech = cryptotech;
    68 
    69     status = pgp_init(session, in_first);
    70     if (status != PEP_STATUS_OK)
    71         goto pEp_error;
    72 
    73     return PEP_STATUS_OK;
    74 
    75 pEp_error:
    76     pgp_release(session, in_first);
    77     return status;
    78 }
    79 
    80 void release_cryptotech(PEP_SESSION session, bool out_last)
    81 {
    82     pgp_release(session, out_last);
    83 }