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