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