test/pgp_list_keys_test.cc
author Volker Birk <vb@pep.foundation>
Tue, 27 Dec 2016 21:13:41 +0100
changeset 1513 e7f7e42385b5
parent 1050 a73bf9737993
permissions -rw-r--r--
adding license info to each file
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #include <iostream>
     5 #include <string>
     6 #include <assert.h>
     7 #include "pEpEngine.h"
     8 #include "stringpair.h"
     9 #include "openpgp_compat.h"
    10 
    11 using namespace std;
    12 
    13 void print_stringpair_list(stringpair_list_t* spl) {
    14     for ( ; spl != NULL; spl = spl->next) {
    15         if (spl->value) {
    16             cout << "Key:" << endl;
    17             if (spl->value->key)
    18                 cout << "\tFPR: " << spl->value->key << endl;
    19             if (spl->value->value)
    20                 cout << "\tUID: " << spl->value->value << endl;
    21         }
    22     }
    23 }
    24 
    25 int main() {
    26     cout << "\n*** openpgp_compat test ***\n\n";
    27 
    28     PEP_SESSION session;
    29     
    30     cout << "calling init()\n";
    31     PEP_STATUS status1 = init(&session);   
    32     assert(status1 == PEP_STATUS_OK);
    33     assert(session);
    34     cout << "init() completed.\n";
    35 
    36     cout << "Listing all the keys:" << endl;
    37     stringpair_list_t* all_the_ids = NULL;
    38     OpenPGP_list_keyinfo(session, "", &all_the_ids);
    39     print_stringpair_list(all_the_ids);
    40     free_stringpair_list(all_the_ids);
    41     
    42     cout << "**********************" << endl << endl << "Checking on Alice, Bob and John" << endl;
    43     all_the_ids = NULL;
    44     OpenPGP_list_keyinfo(session, "pEp Test", &all_the_ids);
    45     print_stringpair_list(all_the_ids);
    46     free_stringpair_list(all_the_ids);
    47 
    48     cout << "**********************" << endl << endl << "Compare to find_keys for Alice, Bob and John" << endl;
    49     stringlist_t* all_the_keys;
    50     find_keys(session, "pEp Test", &all_the_keys);
    51     stringlist_t* i;
    52     for (i = all_the_keys; i; i = i->next) {
    53         cout << i->value << endl;
    54     }
    55     free_stringlist(all_the_keys);
    56 
    57     
    58     cout << "**********************" << endl << endl << "Checking FPR" << endl;
    59     all_the_ids = NULL;
    60     OpenPGP_list_keyinfo(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39", &all_the_ids);
    61     print_stringpair_list(all_the_ids);
    62     free_stringpair_list(all_the_ids);
    63 
    64     cout << "**********************" << endl << endl << "Checking on nothing" << endl;
    65     all_the_ids = NULL;
    66     OpenPGP_list_keyinfo(session, "ekhwr89234uh4rknfjsklejfnlskjflselkflkserjs", &all_the_ids);
    67     print_stringpair_list(all_the_ids);
    68     free_stringpair_list(all_the_ids);
    69 
    70     cout << "calling release()\n";
    71     release(session);
    72     return 0;
    73 }
    74