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