src/cryptotech.c
author vb
Sat, 21 Feb 2015 16:55:43 +0100
changeset 62 ad5e484720e1
parent 28 7fc9fc3e680c
child 66 805bfae3cdc4
permissions -rw-r--r--
signal() and init()
     1 #include "pEp_internal.h"
     2 
     3 #ifdef NO_GPG
     4 #include "pgp_netpgp.h"
     5 #else
     6 #include "pgp_gpg.h"
     7 #endif
     8 
     9 #include <stdlib.h>
    10 #include <memory.h>
    11 #include <assert.h>
    12 
    13 PEP_STATUS init_cryptotech(PEP_SESSION session, bool in_first)
    14 {
    15     static PEP_cryptotech_t cryptotech[PEP_crypt__count];
    16     PEP_STATUS _status;
    17 
    18     assert(PEP_crypt__count == 2);
    19 
    20     if (in_first) {
    21         memset(cryptotech, 0, sizeof(PEP_cryptotech_t) * PEP_crypt__count);
    22 
    23         cryptotech[PEP_crypt_none].id = PEP_crypt_none;
    24         cryptotech[PEP_crypt_none].unconfirmed_comm_type = PEP_ct_no_encryption;
    25         cryptotech[PEP_crypt_none].confirmed_comm_type = PEP_ct_no_encryption;
    26 
    27         cryptotech[PEP_crypt_OpenPGP].id = PEP_crypt_OpenPGP;
    28         cryptotech[PEP_crypt_OpenPGP].unconfirmed_comm_type = PEP_ct_OpenPGP_unconfirmed;
    29         cryptotech[PEP_crypt_OpenPGP].confirmed_comm_type = PEP_ct_OpenPGP;
    30         cryptotech[PEP_crypt_OpenPGP].decrypt_and_verify = pgp_decrypt_and_verify;
    31         cryptotech[PEP_crypt_OpenPGP].encrypt_and_sign = pgp_encrypt_and_sign;
    32         cryptotech[PEP_crypt_OpenPGP].verify_text = pgp_verify_text;
    33         cryptotech[PEP_crypt_OpenPGP].delete_keypair = pgp_delete_keypair;
    34         cryptotech[PEP_crypt_OpenPGP].export_key = pgp_export_key;
    35         cryptotech[PEP_crypt_OpenPGP].find_keys = pgp_find_keys;
    36         cryptotech[PEP_crypt_OpenPGP].generate_keypair = pgp_generate_keypair;
    37         cryptotech[PEP_crypt_OpenPGP].get_key_rating = pgp_get_key_rating;
    38         cryptotech[PEP_crypt_OpenPGP].import_key = pgp_import_key;
    39         cryptotech[PEP_crypt_OpenPGP].recv_key = pgp_recv_key;
    40         cryptotech[PEP_crypt_OpenPGP].send_key = pgp_send_key;
    41     }
    42 
    43     session->cryptotech = cryptotech;
    44 
    45     _status = pgp_init(session, in_first);
    46     assert(_status == PEP_STATUS_OK);
    47     if (_status != PEP_STATUS_OK)
    48         return _status;
    49 
    50     return PEP_STATUS_OK;
    51 }
    52 
    53 void release_cryptotech(PEP_SESSION session, bool out_last)
    54 {
    55     pgp_release(session, out_last);
    56 }