test/keyedit_test.cc
author Volker Birk <vb@pep-project.org>
Tue, 21 Apr 2015 08:37:01 +0200
changeset 211 a022e853f81e
parent 205 69abe9ef3be2
child 1513 e7f7e42385b5
permissions -rw-r--r--
revoke_key() fixed
vb@205
     1
#include "platform.h"
vb@205
     2
vb@205
     3
#include <iostream>
vb@205
     4
#include <fstream>
vb@205
     5
#include <string>
vb@205
     6
#include <assert.h>
vb@205
     7
vb@205
     8
#include "pEpEngine.h"
vb@205
     9
vb@205
    10
using namespace std;
vb@205
    11
vb@205
    12
int main() {
vb@205
    13
    cout << "\n*** keyedit_test ***\n\n";
vb@205
    14
vb@205
    15
    PEP_SESSION session;
vb@205
    16
    
vb@205
    17
    cout << "calling init()\n";
vb@205
    18
    PEP_STATUS status1 = init(&session);   
vb@205
    19
    assert(status1 == PEP_STATUS_OK);
vb@205
    20
    assert(session);
vb@205
    21
    cout << "init() completed.\n";
vb@205
    22
vb@205
    23
    // generate test key
vb@205
    24
vb@211
    25
    cout << "\ngenerating key for keyedit test\n";
vb@205
    26
    pEp_identity *identity = new_identity(
vb@205
    27
            "expire@dingens.org",
vb@205
    28
            NULL,
vb@205
    29
            "423",
vb@205
    30
            "expire test key"
vb@205
    31
        );
vb@205
    32
    assert(identity);
vb@205
    33
    PEP_STATUS generate_status = generate_keypair(session, identity);
vb@205
    34
    cout << "generate_keypair() exits with " << generate_status << "\n";
vb@205
    35
    assert(generate_status == PEP_STATUS_OK);
vb@205
    36
    cout << "generated key is " << identity->fpr << "\n";
vb@205
    37
vb@205
    38
    string key(identity->fpr);
vb@205
    39
    free_identity(identity);
vb@205
    40
vb@205
    41
    // keyedit test code
vb@205
    42
vb@205
    43
    timestamp *ts = new_timestamp(time(0));
vb@205
    44
    ts->tm_year += 2;
vb@205
    45
vb@205
    46
    cout << "key shell expire on " << asctime(ts) << "\n";
vb@205
    47
vb@205
    48
    PEP_STATUS status2 = renew_key(session, key.c_str(), ts);
vb@205
    49
    cout << "renew_key() exited with " << status2 << "\n";
vb@205
    50
    assert(status2 == PEP_STATUS_OK);
vb@205
    51
    free_timestamp(ts);
vb@205
    52
vb@205
    53
    cout << "key renewed.\n";
vb@205
    54
vb@211
    55
    cout << "key will be revoked\n";
vb@211
    56
    PEP_STATUS status3 = revoke_key(session, key.c_str(), "revoke test");
vb@211
    57
    cout << "revoke_key() exited with " << status3 << "\n";
vb@211
    58
    assert(status3 == PEP_STATUS_OK);
vb@211
    59
    
vb@211
    60
    cout << "key revoked.\n";
vb@211
    61
vb@205
    62
    cout << "deleting key pair " << key.c_str() << "\n";
vb@205
    63
    PEP_STATUS delete_status = delete_keypair(session, key.c_str());
vb@205
    64
    cout << "delete_keypair() exits with " << delete_status << "\n";
vb@205
    65
    assert(delete_status == PEP_STATUS_OK);
vb@205
    66
vb@205
    67
    cout << "calling release()\n";
vb@205
    68
    release(session);
vb@205
    69
    return 0;
vb@205
    70
}
vb@205
    71