src/cryptotech.c
author Krista Bennett <krista@pep-project.org>
Fri, 01 Jun 2018 10:30:19 +0200
branchENGINE-233
changeset 2727 b8b0443804da
parent 1639 be84d676f3ef
child 1673 559931685411
child 2458 2dfe65bd3613
permissions -rw-r--r--
close branch
vb@1513
     1
// This file is under GNU General Public License 3.0
vb@1513
     2
// see LICENSE.txt
vb@1513
     3
vb@28
     4
#include "pEp_internal.h"
vb@23
     5
Edouard@168
     6
#ifdef USE_GPG
Edouard@168
     7
#include "pgp_gpg.h"
Edouard@331
     8
#else
Edouard@331
     9
#ifdef USE_NETPGP
vb@24
    10
#include "pgp_netpgp.h"
vb@24
    11
#endif
Edouard@331
    12
#endif
krista@1005
    13
// 
vb@24
    14
vb@23
    15
#include <stdlib.h>
vb@23
    16
#include <memory.h>
vb@23
    17
#include <assert.h>
vb@23
    18
vb@259
    19
PEP_cryptotech_t cryptotech[PEP_crypt__count];
vb@259
    20
vb@62
    21
PEP_STATUS init_cryptotech(PEP_SESSION session, bool in_first)
vb@23
    22
{
vb@66
    23
    PEP_STATUS status = PEP_STATUS_OK;
vb@28
    24
vb@23
    25
    assert(PEP_crypt__count == 2);
vb@23
    26
vb@62
    27
    if (in_first) {
vb@62
    28
        memset(cryptotech, 0, sizeof(PEP_cryptotech_t) * PEP_crypt__count);
vb@23
    29
vb@62
    30
        cryptotech[PEP_crypt_none].id = PEP_crypt_none;
vb@62
    31
        cryptotech[PEP_crypt_none].unconfirmed_comm_type = PEP_ct_no_encryption;
vb@62
    32
        cryptotech[PEP_crypt_none].confirmed_comm_type = PEP_ct_no_encryption;
vb@62
    33
vb@62
    34
        cryptotech[PEP_crypt_OpenPGP].id = PEP_crypt_OpenPGP;
vb@62
    35
        cryptotech[PEP_crypt_OpenPGP].unconfirmed_comm_type = PEP_ct_OpenPGP_unconfirmed;
vb@62
    36
        cryptotech[PEP_crypt_OpenPGP].confirmed_comm_type = PEP_ct_OpenPGP;
vb@62
    37
        cryptotech[PEP_crypt_OpenPGP].decrypt_and_verify = pgp_decrypt_and_verify;
vb@62
    38
        cryptotech[PEP_crypt_OpenPGP].encrypt_and_sign = pgp_encrypt_and_sign;
krista@1639
    39
        cryptotech[PEP_crypt_OpenPGP].encrypt_only = pgp_encrypt_only;
vb@62
    40
        cryptotech[PEP_crypt_OpenPGP].verify_text = pgp_verify_text;
vb@62
    41
        cryptotech[PEP_crypt_OpenPGP].delete_keypair = pgp_delete_keypair;
Edouard@170
    42
        cryptotech[PEP_crypt_OpenPGP].export_key = pgp_export_keydata;
vb@62
    43
        cryptotech[PEP_crypt_OpenPGP].find_keys = pgp_find_keys;
vb@62
    44
        cryptotech[PEP_crypt_OpenPGP].generate_keypair = pgp_generate_keypair;
vb@62
    45
        cryptotech[PEP_crypt_OpenPGP].get_key_rating = pgp_get_key_rating;
Edouard@170
    46
        cryptotech[PEP_crypt_OpenPGP].import_key = pgp_import_keydata;
vb@62
    47
        cryptotech[PEP_crypt_OpenPGP].recv_key = pgp_recv_key;
vb@62
    48
        cryptotech[PEP_crypt_OpenPGP].send_key = pgp_send_key;
vb@200
    49
        cryptotech[PEP_crypt_OpenPGP].renew_key = pgp_renew_key;
vb@200
    50
        cryptotech[PEP_crypt_OpenPGP].revoke_key = pgp_revoke_key;
vb@214
    51
        cryptotech[PEP_crypt_OpenPGP].key_expired = pgp_key_expired;
Edouard@539
    52
        cryptotech[PEP_crypt_OpenPGP].key_revoked = pgp_key_revoked;
vb@958
    53
        cryptotech[PEP_crypt_OpenPGP].key_created = pgp_key_created;
krista@1357
    54
        cryptotech[PEP_crypt_OpenPGP].contains_priv_key = pgp_contains_priv_key;
krista@1357
    55
        cryptotech[PEP_crypt_OpenPGP].find_private_keys = pgp_find_private_keys;
vb@507
    56
#ifdef PGP_BINARY_PATH
vb@507
    57
        cryptotech[PEP_crypt_OpenPGP].binary_path = PGP_BINARY_PATH;
vb@507
    58
#endif
vb@28
    59
    }
vb@28
    60
vb@62
    61
    session->cryptotech = cryptotech;
vb@62
    62
vb@66
    63
    status = pgp_init(session, in_first);
vb@66
    64
    if (status != PEP_STATUS_OK)
vb@66
    65
        goto pep_error;
vb@23
    66
vb@23
    67
    return PEP_STATUS_OK;
vb@66
    68
vb@66
    69
pep_error:
vb@66
    70
    pgp_release(session, in_first);
vb@66
    71
    return status;
vb@23
    72
}
vb@28
    73
vb@62
    74
void release_cryptotech(PEP_SESSION session, bool out_last)
vb@28
    75
{
vb@62
    76
    pgp_release(session, out_last);
vb@28
    77
}