src/cryptotech.c
author Volker Birk <vb@pep-project.org>
Fri, 08 May 2015 16:53:39 +0200
changeset 259 71d6c073fda4
parent 214 79333debeee0
child 331 5ddf7c537b05
permissions -rw-r--r--
fixing database access
     1 #include "pEp_internal.h"
     2 
     3 #ifdef USE_GPG
     4 #include "pgp_gpg.h"
     5 #elif USE_NETPGP
     6 #include "pgp_netpgp.h"
     7 #endif
     8 
     9 #include <stdlib.h>
    10 #include <memory.h>
    11 #include <assert.h>
    12 
    13 PEP_cryptotech_t cryptotech[PEP_crypt__count];
    14 
    15 PEP_STATUS init_cryptotech(PEP_SESSION session, bool in_first)
    16 {
    17     PEP_STATUS status = PEP_STATUS_OK;
    18 
    19     assert(PEP_crypt__count == 2);
    20 
    21     if (in_first) {
    22         memset(cryptotech, 0, sizeof(PEP_cryptotech_t) * PEP_crypt__count);
    23 
    24         cryptotech[PEP_crypt_none].id = PEP_crypt_none;
    25         cryptotech[PEP_crypt_none].unconfirmed_comm_type = PEP_ct_no_encryption;
    26         cryptotech[PEP_crypt_none].confirmed_comm_type = PEP_ct_no_encryption;
    27 
    28         cryptotech[PEP_crypt_OpenPGP].id = PEP_crypt_OpenPGP;
    29         cryptotech[PEP_crypt_OpenPGP].unconfirmed_comm_type = PEP_ct_OpenPGP_unconfirmed;
    30         cryptotech[PEP_crypt_OpenPGP].confirmed_comm_type = PEP_ct_OpenPGP;
    31         cryptotech[PEP_crypt_OpenPGP].decrypt_and_verify = pgp_decrypt_and_verify;
    32         cryptotech[PEP_crypt_OpenPGP].encrypt_and_sign = pgp_encrypt_and_sign;
    33         cryptotech[PEP_crypt_OpenPGP].verify_text = pgp_verify_text;
    34         cryptotech[PEP_crypt_OpenPGP].delete_keypair = pgp_delete_keypair;
    35         cryptotech[PEP_crypt_OpenPGP].export_key = pgp_export_keydata;
    36         cryptotech[PEP_crypt_OpenPGP].find_keys = pgp_find_keys;
    37         cryptotech[PEP_crypt_OpenPGP].generate_keypair = pgp_generate_keypair;
    38         cryptotech[PEP_crypt_OpenPGP].get_key_rating = pgp_get_key_rating;
    39         cryptotech[PEP_crypt_OpenPGP].import_key = pgp_import_keydata;
    40         cryptotech[PEP_crypt_OpenPGP].recv_key = pgp_recv_key;
    41         cryptotech[PEP_crypt_OpenPGP].send_key = pgp_send_key;
    42         cryptotech[PEP_crypt_OpenPGP].renew_key = pgp_renew_key;
    43         cryptotech[PEP_crypt_OpenPGP].revoke_key = pgp_revoke_key;
    44         cryptotech[PEP_crypt_OpenPGP].key_expired = pgp_key_expired;
    45     }
    46 
    47     session->cryptotech = cryptotech;
    48 
    49     status = pgp_init(session, in_first);
    50     if (status != PEP_STATUS_OK)
    51         goto pep_error;
    52 
    53     return PEP_STATUS_OK;
    54 
    55 pep_error:
    56     pgp_release(session, in_first);
    57     return status;
    58 }
    59 
    60 void release_cryptotech(PEP_SESSION session, bool out_last)
    61 {
    62     pgp_release(session, out_last);
    63 }