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