test/keyedit_test.cc
author Krista Bennett <krista@pep-project.org>
Fri, 19 Jan 2018 14:12:02 +0100
changeset 2418 05678e77bc6a
parent 1513 e7f7e42385b5
permissions -rw-r--r--
fixed update_identity call that could be called on a myself value in outgoing_message_rating
vb@1513
     1
// This file is under GNU General Public License 3.0
vb@1513
     2
// see LICENSE.txt
vb@1513
     3
vb@205
     4
#include "platform.h"
vb@205
     5
vb@205
     6
#include <iostream>
vb@205
     7
#include <fstream>
vb@205
     8
#include <string>
vb@205
     9
#include <assert.h>
vb@205
    10
vb@205
    11
#include "pEpEngine.h"
vb@205
    12
vb@205
    13
using namespace std;
vb@205
    14
vb@205
    15
int main() {
vb@205
    16
    cout << "\n*** keyedit_test ***\n\n";
vb@205
    17
vb@205
    18
    PEP_SESSION session;
vb@205
    19
    
vb@205
    20
    cout << "calling init()\n";
vb@205
    21
    PEP_STATUS status1 = init(&session);   
vb@205
    22
    assert(status1 == PEP_STATUS_OK);
vb@205
    23
    assert(session);
vb@205
    24
    cout << "init() completed.\n";
vb@205
    25
vb@205
    26
    // generate test key
vb@205
    27
vb@211
    28
    cout << "\ngenerating key for keyedit test\n";
vb@205
    29
    pEp_identity *identity = new_identity(
vb@205
    30
            "expire@dingens.org",
vb@205
    31
            NULL,
vb@205
    32
            "423",
vb@205
    33
            "expire test key"
vb@205
    34
        );
vb@205
    35
    assert(identity);
vb@205
    36
    PEP_STATUS generate_status = generate_keypair(session, identity);
vb@205
    37
    cout << "generate_keypair() exits with " << generate_status << "\n";
vb@205
    38
    assert(generate_status == PEP_STATUS_OK);
vb@205
    39
    cout << "generated key is " << identity->fpr << "\n";
vb@205
    40
vb@205
    41
    string key(identity->fpr);
vb@205
    42
    free_identity(identity);
vb@205
    43
vb@205
    44
    // keyedit test code
vb@205
    45
vb@205
    46
    timestamp *ts = new_timestamp(time(0));
vb@205
    47
    ts->tm_year += 2;
vb@205
    48
vb@205
    49
    cout << "key shell expire on " << asctime(ts) << "\n";
vb@205
    50
vb@205
    51
    PEP_STATUS status2 = renew_key(session, key.c_str(), ts);
vb@205
    52
    cout << "renew_key() exited with " << status2 << "\n";
vb@205
    53
    assert(status2 == PEP_STATUS_OK);
vb@205
    54
    free_timestamp(ts);
vb@205
    55
vb@205
    56
    cout << "key renewed.\n";
vb@205
    57
vb@211
    58
    cout << "key will be revoked\n";
vb@211
    59
    PEP_STATUS status3 = revoke_key(session, key.c_str(), "revoke test");
vb@211
    60
    cout << "revoke_key() exited with " << status3 << "\n";
vb@211
    61
    assert(status3 == PEP_STATUS_OK);
vb@211
    62
    
vb@211
    63
    cout << "key revoked.\n";
vb@211
    64
vb@205
    65
    cout << "deleting key pair " << key.c_str() << "\n";
vb@205
    66
    PEP_STATUS delete_status = delete_keypair(session, key.c_str());
vb@205
    67
    cout << "delete_keypair() exits with " << delete_status << "\n";
vb@205
    68
    assert(delete_status == PEP_STATUS_OK);
vb@205
    69
vb@205
    70
    cout << "calling release()\n";
vb@205
    71
    release(session);
vb@205
    72
    return 0;
vb@205
    73
}
vb@205
    74