src/cryptotech.c
author Volker Birk <vb@pep.foundation>
Thu, 01 Sep 2016 17:55:03 +0200
branchkeysync
changeset 1111 3c46dc58096d
parent 1057 abff13590a4c
child 1352 239640860531
permissions -rw-r--r--
merging
vb@28
     1
#include "pEp_internal.h"
vb@23
     2
Edouard@168
     3
#ifdef USE_GPG
Edouard@168
     4
#include "pgp_gpg.h"
Edouard@331
     5
#else
Edouard@331
     6
#ifdef USE_NETPGP
vb@24
     7
#include "pgp_netpgp.h"
vb@24
     8
#endif
Edouard@331
     9
#endif
krista@1005
    10
// 
vb@24
    11
vb@23
    12
#include <stdlib.h>
vb@23
    13
#include <memory.h>
vb@23
    14
#include <assert.h>
vb@23
    15
vb@259
    16
PEP_cryptotech_t cryptotech[PEP_crypt__count];
vb@259
    17
vb@62
    18
PEP_STATUS init_cryptotech(PEP_SESSION session, bool in_first)
vb@23
    19
{
vb@66
    20
    PEP_STATUS status = PEP_STATUS_OK;
vb@28
    21
vb@23
    22
    assert(PEP_crypt__count == 2);
vb@62
    23
vb@62
    24
    if (in_first) {
vb@62
    25
        memset(cryptotech, 0, sizeof(PEP_cryptotech_t) * PEP_crypt__count);
vb@23
    26
vb@62
    27
        cryptotech[PEP_crypt_none].id = PEP_crypt_none;
vb@62
    28
        cryptotech[PEP_crypt_none].unconfirmed_comm_type = PEP_ct_no_encryption;
vb@62
    29
        cryptotech[PEP_crypt_none].confirmed_comm_type = PEP_ct_no_encryption;
vb@28
    30
vb@62
    31
        cryptotech[PEP_crypt_OpenPGP].id = PEP_crypt_OpenPGP;
vb@62
    32
        cryptotech[PEP_crypt_OpenPGP].unconfirmed_comm_type = PEP_ct_OpenPGP_unconfirmed;
vb@62
    33
        cryptotech[PEP_crypt_OpenPGP].confirmed_comm_type = PEP_ct_OpenPGP;
vb@62
    34
        cryptotech[PEP_crypt_OpenPGP].decrypt_and_verify = pgp_decrypt_and_verify;
vb@62
    35
        cryptotech[PEP_crypt_OpenPGP].encrypt_and_sign = pgp_encrypt_and_sign;
vb@62
    36
        cryptotech[PEP_crypt_OpenPGP].verify_text = pgp_verify_text;
vb@62
    37
        cryptotech[PEP_crypt_OpenPGP].delete_keypair = pgp_delete_keypair;
Edouard@170
    38
        cryptotech[PEP_crypt_OpenPGP].export_key = pgp_export_keydata;
vb@62
    39
        cryptotech[PEP_crypt_OpenPGP].find_keys = pgp_find_keys;
vb@62
    40
        cryptotech[PEP_crypt_OpenPGP].generate_keypair = pgp_generate_keypair;
vb@62
    41
        cryptotech[PEP_crypt_OpenPGP].get_key_rating = pgp_get_key_rating;
Edouard@170
    42
        cryptotech[PEP_crypt_OpenPGP].import_key = pgp_import_keydata;
vb@62
    43
        cryptotech[PEP_crypt_OpenPGP].recv_key = pgp_recv_key;
vb@62
    44
        cryptotech[PEP_crypt_OpenPGP].send_key = pgp_send_key;
vb@200
    45
        cryptotech[PEP_crypt_OpenPGP].renew_key = pgp_renew_key;
vb@200
    46
        cryptotech[PEP_crypt_OpenPGP].revoke_key = pgp_revoke_key;
vb@214
    47
        cryptotech[PEP_crypt_OpenPGP].key_expired = pgp_key_expired;
Edouard@663
    48
        cryptotech[PEP_crypt_OpenPGP].key_revoked = pgp_key_revoked;
vb@958
    49
        cryptotech[PEP_crypt_OpenPGP].key_created = pgp_key_created;
vb@507
    50
#ifdef PGP_BINARY_PATH
vb@507
    51
        cryptotech[PEP_crypt_OpenPGP].binary_path = PGP_BINARY_PATH;
vb@507
    52
#endif
vb@28
    53
    }
vb@23
    54
vb@62
    55
    session->cryptotech = cryptotech;
vb@62
    56
vb@66
    57
    status = pgp_init(session, in_first);
vb@66
    58
    if (status != PEP_STATUS_OK)
vb@66
    59
        goto pep_error;
vb@23
    60
vb@23
    61
    return PEP_STATUS_OK;
vb@66
    62
vb@66
    63
pep_error:
vb@66
    64
    pgp_release(session, in_first);
vb@66
    65
    return status;
vb@23
    66
}
vb@28
    67
vb@62
    68
void release_cryptotech(PEP_SESSION session, bool out_last)
vb@28
    69
{
vb@62
    70
    pgp_release(session, out_last);
vb@28
    71
}