src/cryptotech.c
author Neal H. Walfield <neal@pep.foundation>
Wed, 08 May 2019 12:20:37 +0200
branchemail_comparison
changeset 3649 1dd837adc30b
parent 3191 53dcb2892c3f
child 3689 6ea4a0524c38
permissions -rw-r--r--
Fix public key.
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"
neal@3191
    11
#else
neal@3191
    12
#ifdef USE_SEQUOIA
neal@3191
    13
#include "pgp_sequoia.h"
neal@3191
    14
#endif
vb@24
    15
#endif
Edouard@331
    16
#endif
krista@1005
    17
// 
vb@24
    18
vb@23
    19
#include <stdlib.h>
vb@23
    20
#include <memory.h>
vb@23
    21
#include <assert.h>
vb@23
    22
vb@259
    23
PEP_cryptotech_t cryptotech[PEP_crypt__count];
vb@259
    24
vb@62
    25
PEP_STATUS init_cryptotech(PEP_SESSION session, bool in_first)
vb@23
    26
{
vb@66
    27
    PEP_STATUS status = PEP_STATUS_OK;
vb@28
    28
vb@23
    29
    assert(PEP_crypt__count == 2);
vb@23
    30
vb@62
    31
    if (in_first) {
vb@62
    32
        memset(cryptotech, 0, sizeof(PEP_cryptotech_t) * PEP_crypt__count);
vb@23
    33
vb@62
    34
        cryptotech[PEP_crypt_none].id = PEP_crypt_none;
vb@62
    35
        cryptotech[PEP_crypt_none].unconfirmed_comm_type = PEP_ct_no_encryption;
vb@62
    36
        cryptotech[PEP_crypt_none].confirmed_comm_type = PEP_ct_no_encryption;
vb@62
    37
vb@62
    38
        cryptotech[PEP_crypt_OpenPGP].id = PEP_crypt_OpenPGP;
vb@62
    39
        cryptotech[PEP_crypt_OpenPGP].unconfirmed_comm_type = PEP_ct_OpenPGP_unconfirmed;
vb@62
    40
        cryptotech[PEP_crypt_OpenPGP].confirmed_comm_type = PEP_ct_OpenPGP;
vb@62
    41
        cryptotech[PEP_crypt_OpenPGP].decrypt_and_verify = pgp_decrypt_and_verify;
vb@62
    42
        cryptotech[PEP_crypt_OpenPGP].encrypt_and_sign = pgp_encrypt_and_sign;
krista@1639
    43
        cryptotech[PEP_crypt_OpenPGP].encrypt_only = pgp_encrypt_only;
krista@3133
    44
        cryptotech[PEP_crypt_OpenPGP].sign_only = pgp_sign_only;        
vb@62
    45
        cryptotech[PEP_crypt_OpenPGP].verify_text = pgp_verify_text;
vb@62
    46
        cryptotech[PEP_crypt_OpenPGP].delete_keypair = pgp_delete_keypair;
Edouard@170
    47
        cryptotech[PEP_crypt_OpenPGP].export_key = pgp_export_keydata;
vb@62
    48
        cryptotech[PEP_crypt_OpenPGP].find_keys = pgp_find_keys;
vb@62
    49
        cryptotech[PEP_crypt_OpenPGP].generate_keypair = pgp_generate_keypair;
vb@62
    50
        cryptotech[PEP_crypt_OpenPGP].get_key_rating = pgp_get_key_rating;
Edouard@170
    51
        cryptotech[PEP_crypt_OpenPGP].import_key = pgp_import_keydata;
vb@62
    52
        cryptotech[PEP_crypt_OpenPGP].recv_key = pgp_recv_key;
vb@62
    53
        cryptotech[PEP_crypt_OpenPGP].send_key = pgp_send_key;
vb@200
    54
        cryptotech[PEP_crypt_OpenPGP].renew_key = pgp_renew_key;
vb@200
    55
        cryptotech[PEP_crypt_OpenPGP].revoke_key = pgp_revoke_key;
vb@214
    56
        cryptotech[PEP_crypt_OpenPGP].key_expired = pgp_key_expired;
Edouard@539
    57
        cryptotech[PEP_crypt_OpenPGP].key_revoked = pgp_key_revoked;
vb@958
    58
        cryptotech[PEP_crypt_OpenPGP].key_created = pgp_key_created;
krista@1357
    59
        cryptotech[PEP_crypt_OpenPGP].contains_priv_key = pgp_contains_priv_key;
krista@1357
    60
        cryptotech[PEP_crypt_OpenPGP].find_private_keys = pgp_find_private_keys;
vb@507
    61
#ifdef PGP_BINARY_PATH
vb@507
    62
        cryptotech[PEP_crypt_OpenPGP].binary_path = PGP_BINARY_PATH;
vb@507
    63
#endif
vb@28
    64
    }
vb@28
    65
vb@62
    66
    session->cryptotech = cryptotech;
vb@62
    67
vb@66
    68
    status = pgp_init(session, in_first);
vb@66
    69
    if (status != PEP_STATUS_OK)
vb@2834
    70
        goto pEp_error;
vb@23
    71
vb@23
    72
    return PEP_STATUS_OK;
vb@66
    73
vb@2834
    74
pEp_error:
vb@66
    75
    pgp_release(session, in_first);
vb@66
    76
    return status;
vb@23
    77
}
vb@28
    78
vb@62
    79
void release_cryptotech(PEP_SESSION session, bool out_last)
vb@28
    80
{
vb@62
    81
    pgp_release(session, out_last);
vb@28
    82
}