src/cryptotech.c
author Roker <roker@pep-project.org>
Tue, 20 Sep 2016 15:54:57 +0200
branchroker-linux
changeset 1168 4d4e3ecbaf8b
parent 1030 4354451338cd
child 1057 abff13590a4c
child 1126 129b561095a6
permissions -rw-r--r--
merge "default" into my branch
     1 #include "pEp_internal.h"
     2 
     3 #ifdef USE_GPG
     4 #include "pgp_gpg.h"
     5 #else
     6 #ifdef USE_NETPGP
     7 #include "pgp_netpgp.h"
     8 #endif
     9 #endif
    10 // 
    11 
    12 #include <stdlib.h>
    13 #include <memory.h>
    14 #include <assert.h>
    15 
    16 PEP_cryptotech_t cryptotech[PEP_crypt__count];
    17 
    18 PEP_STATUS init_cryptotech(PEP_SESSION session, bool in_first)
    19 {
    20     PEP_STATUS status = PEP_STATUS_OK;
    21 
    22     assert(PEP_crypt__count == 2);
    23 
    24     if (in_first) {
    25         memset(cryptotech, 0, sizeof(PEP_cryptotech_t) * PEP_crypt__count);
    26 
    27         cryptotech[PEP_crypt_none].id = PEP_crypt_none;
    28         cryptotech[PEP_crypt_none].unconfirmed_comm_type = PEP_ct_no_encryption;
    29         cryptotech[PEP_crypt_none].confirmed_comm_type = PEP_ct_no_encryption;
    30 
    31         cryptotech[PEP_crypt_OpenPGP].id = PEP_crypt_OpenPGP;
    32         cryptotech[PEP_crypt_OpenPGP].unconfirmed_comm_type = PEP_ct_OpenPGP_unconfirmed;
    33         cryptotech[PEP_crypt_OpenPGP].confirmed_comm_type = PEP_ct_OpenPGP;
    34         cryptotech[PEP_crypt_OpenPGP].decrypt_and_verify = pgp_decrypt_and_verify;
    35         cryptotech[PEP_crypt_OpenPGP].encrypt_and_sign = pgp_encrypt_and_sign;
    36         cryptotech[PEP_crypt_OpenPGP].verify_text = pgp_verify_text;
    37         cryptotech[PEP_crypt_OpenPGP].delete_keypair = pgp_delete_keypair;
    38         cryptotech[PEP_crypt_OpenPGP].export_key = pgp_export_keydata;
    39         cryptotech[PEP_crypt_OpenPGP].find_keys = pgp_find_keys;
    40         cryptotech[PEP_crypt_OpenPGP].generate_keypair = pgp_generate_keypair;
    41         cryptotech[PEP_crypt_OpenPGP].get_key_rating = pgp_get_key_rating;
    42         cryptotech[PEP_crypt_OpenPGP].import_key = pgp_import_keydata;
    43         cryptotech[PEP_crypt_OpenPGP].recv_key = pgp_recv_key;
    44         cryptotech[PEP_crypt_OpenPGP].send_key = pgp_send_key;
    45         cryptotech[PEP_crypt_OpenPGP].renew_key = pgp_renew_key;
    46         cryptotech[PEP_crypt_OpenPGP].revoke_key = pgp_revoke_key;
    47         cryptotech[PEP_crypt_OpenPGP].key_expired = pgp_key_expired;
    48         cryptotech[PEP_crypt_OpenPGP].key_revoked = pgp_key_revoked;
    49 #ifdef PGP_BINARY_PATH
    50         cryptotech[PEP_crypt_OpenPGP].binary_path = PGP_BINARY_PATH;
    51 #endif
    52     }
    53 
    54     session->cryptotech = cryptotech;
    55 
    56     status = pgp_init(session, in_first);
    57     if (status != PEP_STATUS_OK)
    58         goto pep_error;
    59 
    60     return PEP_STATUS_OK;
    61 
    62 pep_error:
    63     pgp_release(session, in_first);
    64     return status;
    65 }
    66 
    67 void release_cryptotech(PEP_SESSION session, bool out_last)
    68 {
    69     pgp_release(session, out_last);
    70 }