test/pEpEngineTest.cc
changeset 748 967b0bae4f01
parent 728 80b966277620
child 750 56df4e0f3ab9
     1.1 --- a/test/pEpEngineTest.cc	Mon Jun 20 13:10:01 2016 +0200
     1.2 +++ b/test/pEpEngineTest.cc	Tue Jun 21 16:33:31 2016 +0200
     1.3 @@ -1,286 +1,286 @@
     1.4 -#include <iostream>
     1.5 -#include <fstream>
     1.6 -#include <string>
     1.7 -
     1.8 -#include <assert.h>
     1.9 -#include <string.h>
    1.10 -
    1.11 -#include "../src/pEpEngine.h"
    1.12 -#include "../src/keymanagement.h"
    1.13 -
    1.14 -using namespace std;
    1.15 -
    1.16 -void ReadFileIntoMem(const char *fname, char* &buffer, size_t &length){
    1.17 -    buffer = NULL;
    1.18 -    length = 0;
    1.19 -	cout << "opening " << fname << " for reading\n";
    1.20 -	ifstream txtFile (fname, ifstream::binary);
    1.21 -	assert(txtFile.is_open());
    1.22 -    if (txtFile) {
    1.23 -        // get length of file:
    1.24 -        txtFile.seekg (0, txtFile.end);
    1.25 -        length = txtFile.tellg();
    1.26 -        txtFile.seekg (0, txtFile.beg);
    1.27 -
    1.28 -        buffer = new char [length+1];
    1.29 -
    1.30 -        cout << "Reading " << length << " characters... ";
    1.31 -        txtFile.read (buffer,length);
    1.32 -        buffer[length]='\0';
    1.33 -
    1.34 -        if (txtFile)
    1.35 -          cout << "all characters read successfully.\n";
    1.36 -        else
    1.37 -          cout << "error: only " << txtFile.gcount() << " could be read\n";
    1.38 -        txtFile.close();
    1.39 -    }
    1.40 -
    1.41 -	txtFile.close();
    1.42 -    assert(buffer);
    1.43 -    assert(length);
    1.44 -}
    1.45 -
    1.46 -int main(int argc, char* argv[])
    1.47 -{
    1.48 -	PEP_SESSION session;
    1.49 -
    1.50 -	cout << "calling init()\n";
    1.51 -	PEP_STATUS init_result = init(&session);
    1.52 -	
    1.53 -    cout << "returning from init() with result == " << init_result << "\n";
    1.54 -	assert(init_result == PEP_STATUS_OK);
    1.55 -
    1.56 -    PEP_SESSION second_session;
    1.57 -    cout << "second session test\n";
    1.58 -    PEP_STATUS second_init_result = init(&second_session);
    1.59 -	cout << "returning from second init() with result == " << second_init_result << "\n";
    1.60 -    assert(second_init_result == PEP_STATUS_OK);
    1.61 -    assert(second_session);
    1.62 -    cout << "dropping second session\n";
    1.63 -	release(second_session);
    1.64 -
    1.65 -	cout << "logging test\n";
    1.66 -	log_event(session, "log test", "pEp Enginge Test", "This is a logging test sample.", "please ignore this line");
    1.67 -
    1.68 -    // Our test user :
    1.69 -    // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
    1.70 -    //         6FF00E97
    1.71 -    // A9411D176FF00E97
    1.72 -    // 
    1.73 -    // Other peers :
    1.74 -    // pEp Test Bob (test key, don't use) <pep.test.bob@pep-project.org> 
    1.75 -    //         C9C2EE39
    1.76 -    // 59BFF488C9C2EE39
    1.77 -    // 
    1.78 -    // pEp Test John (test key, don't use) <pep.test.john@pep-project.org>
    1.79 -    //         70DCF575
    1.80 -    // 135CD6D170DCF575
    1.81 -
    1.82 -    const char *kflist[] = {
    1.83 -        "0x6FF00E97.asc",
    1.84 -        "0xC9C2EE39.asc",
    1.85 -        "0x70DCF575.asc",
    1.86 -        NULL
    1.87 -    };
    1.88 -    const char** kf = kflist;
    1.89 -    while(*kf){
    1.90 -        char * k_user_buffer = NULL;
    1.91 -        size_t k_user_length = 0;
    1.92 -        ReadFileIntoMem(*kf, k_user_buffer, k_user_length);
    1.93 -        cout << "import_key(" << *kf << ")\n";
    1.94 -        PEP_STATUS import_status = import_key(session, k_user_buffer, k_user_length, NULL);
    1.95 -        assert(import_status == PEP_STATUS_OK);
    1.96 -        cout << "successfully imported key\n";
    1.97 -        delete[] k_user_buffer;
    1.98 -        kf++;
    1.99 -    }
   1.100 -
   1.101 -    char * cipher_buffer = NULL;
   1.102 -    size_t cipher_length = 0;
   1.103 -    ReadFileIntoMem("msg.asc", cipher_buffer, cipher_length);
   1.104 -
   1.105 -	cout << "\n" << cipher_buffer;
   1.106 -
   1.107 -	char *buf_text = NULL;
   1.108 -	size_t buf_size = 0;
   1.109 -	stringlist_t *keylist;
   1.110 -
   1.111 -    cout << "calling decrypt_and_verify()\n";
   1.112 -    PEP_STATUS decrypt_result = decrypt_and_verify(session, cipher_buffer, cipher_length, &buf_text, &buf_size, &keylist);
   1.113 -
   1.114 -    cout << "returning from decrypt_and_verify() with result == 0x" << std::hex << decrypt_result << "\n";
   1.115 -    assert(decrypt_result == PEP_DECRYPTED_AND_VERIFIED);
   1.116 -    assert(buf_text);
   1.117 -    assert(keylist);
   1.118 -
   1.119 -    for (stringlist_t *_keylist=keylist; _keylist!=NULL; _keylist=_keylist->next) {
   1.120 -        assert(_keylist->value);
   1.121 -        cout << "signed with " << _keylist->value << "\n";
   1.122 -    }
   1.123 -
   1.124 -    free_stringlist(keylist);
   1.125 -    buf_text[buf_size] = 0;
   1.126 -    string plain(buf_text);
   1.127 -    pEp_free(buf_text);
   1.128 -    cout << "\n" << plain;
   1.129 -
   1.130 -    char * t1_buffer = NULL;
   1.131 -    size_t t1_length = 0;
   1.132 -    ReadFileIntoMem("t1.txt", t1_buffer, t1_length);
   1.133 -
   1.134 -    char * sig_buffer = NULL;
   1.135 -    size_t sig_length = 0;
   1.136 -    ReadFileIntoMem("signature.asc", sig_buffer, sig_length);
   1.137 -
   1.138 -    cout << "\ncalling verify_text()\n";
   1.139 -    PEP_STATUS verify_result = verify_text(session, t1_buffer, t1_length, sig_buffer, sig_length, &keylist);
   1.140 -    cout << "returning from verify_text() with result == " << verify_result << "\n";
   1.141 -    assert(verify_result == PEP_VERIFIED || verify_result == PEP_VERIFIED_AND_TRUSTED);
   1.142 -    assert(keylist->value);
   1.143 -    cout << "signed with " << keylist->value << "\n";
   1.144 -    free_stringlist(keylist);
   1.145 -
   1.146 -    char * t2_buffer = NULL;
   1.147 -    size_t t2_length = 0;
   1.148 -    ReadFileIntoMem("t2.txt", t2_buffer, t2_length);
   1.149 -
   1.150 -    cout << "\ncalling verify_text()\n";
   1.151 -    verify_result = verify_text(session, t2_buffer, t2_length, sig_buffer, sig_length, &keylist);
   1.152 -    assert(verify_result == PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH);
   1.153 -    free_stringlist(keylist);
   1.154 -
   1.155 -    keylist = new_stringlist("A9411D176FF00E97");
   1.156 -    stringlist_add(keylist, "59BFF488C9C2EE39");
   1.157 -    stringlist_add(keylist, "135CD6D170DCF575");
   1.158 -
   1.159 -	buf_text = NULL;
   1.160 -	buf_size = 0;
   1.161 -
   1.162 -    cout << "\ncalling encrypt_and_sign()\n";
   1.163 -    PEP_STATUS encrypt_result = encrypt_and_sign(session, keylist, plain.c_str(), plain.length(), &buf_text, &buf_size);
   1.164 -    cout << "returning from encrypt_and_sign() with result == " << encrypt_result << "\n";
   1.165 -    assert(encrypt_result == PEP_STATUS_OK);
   1.166 -    free_stringlist(keylist);
   1.167 -
   1.168 -    buf_text[buf_size] = 0;
   1.169 -    string cipher2(buf_text);
   1.170 -    cout << "\n" << cipher2;
   1.171 -    pEp_free(buf_text);
   1.172 -
   1.173 -    delete[] cipher_buffer;
   1.174 -    delete[] t1_buffer;
   1.175 -    delete[] sig_buffer;
   1.176 -    delete[] t2_buffer;
   1.177 -
   1.178 -	cout << "\nfinding English trustword for 2342...\n";
   1.179 -	char * word;
   1.180 -	size_t wsize;
   1.181 -	trustword(session, 2342, "en", &word, &wsize);
   1.182 -	assert(word);
   1.183 -	cout << "the trustword for 2342 is " << word << "\n";
   1.184 -    pEp_free(word);
   1.185 -
   1.186 -    string fingerprint = "4942 2235 FC99 585B 891C  6653 0C7B 109B FA72 61F7";
   1.187 -    char * words;
   1.188 -
   1.189 -    cout << "\nfinding German trustwords for " << fingerprint << "...\n";
   1.190 -    trustwords(session, fingerprint.c_str(), "de", &words, &wsize, 5);
   1.191 -    assert(words);
   1.192 -    cout << words << "\n";
   1.193 -    pEp_free(words);
   1.194 -
   1.195 -	pEp_identity *identity;
   1.196 -
   1.197 -    identity = new_identity(
   1.198 -            "leon.schumacher@digitalekho.com",
   1.199 -            "8BD08954C74D830EEFFB5DEB2682A17F7C87F73D",
   1.200 -            "23",
   1.201 -            "Leon Schumacher"
   1.202 -        );
   1.203 -	identity->comm_type = PEP_ct_pEp;
   1.204 -
   1.205 -	cout << "\nsetting identity...\n";
   1.206 -	PEP_STATUS pep_set_result = set_identity(session, identity);
   1.207 -	assert(pep_set_result == PEP_STATUS_OK);
   1.208 -    free_identity(identity);
   1.209 -	get_identity(session, "leon.schumacher@digitalekho.com", "23", &identity);
   1.210 -	assert(identity);
   1.211 -	cout << "set: " << identity->address << ", " << identity->fpr << ", " << identity->user_id << ", " << identity->username << "\n";
   1.212 -
   1.213 -    PEP_STATUS get_trust_result = get_trust(session, identity);
   1.214 -    assert(get_trust_result == PEP_STATUS_OK);
   1.215 -    cout << "trust of " << identity->user_id << " is " << identity->comm_type << "\n";
   1.216 -
   1.217 -    free_identity(identity);
   1.218 -
   1.219 -    cout << "\ngenerating key for testuser\n";
   1.220 -    identity = new_identity(
   1.221 -            "testuser@pibit.ch",
   1.222 -            NULL,
   1.223 -            "423",
   1.224 -            "Alfred E. Neuman"
   1.225 -        );
   1.226 -    assert(identity);
   1.227 -    PEP_STATUS generate_status = generate_keypair(session, identity);
   1.228 -    cout << "generate_keypair() exits with " << generate_status << "\n";
   1.229 -    assert(generate_status == PEP_STATUS_OK);
   1.230 -    cout << "generated key is " << identity->fpr << "\n";
   1.231 -
   1.232 -    string key(identity->fpr);
   1.233 -    free_identity(identity);
   1.234 -
   1.235 -    char *key_data;
   1.236 -    size_t size;
   1.237 -
   1.238 -    cout << "export_key()\n\n";
   1.239 -    PEP_STATUS export_status = export_key(session, key.c_str(), &key_data, &size);
   1.240 -    cout << "export_key() exits with " << export_status << "\n";
   1.241 -    assert(export_status == PEP_STATUS_OK);
   1.242 -    cout << key_data << "\n\n";
   1.243 -
   1.244 -    cout << "deleting key pair " << key.c_str() << "\n";
   1.245 -    PEP_STATUS delete_status = delete_keypair(session, key.c_str());
   1.246 -    cout << "delete_keypair() exits with " << delete_status << "\n";
   1.247 -    assert(delete_status == PEP_STATUS_OK);
   1.248 -    
   1.249 -    cout << "import_key()\n";
   1.250 -    PEP_STATUS import_status = import_key(session, key_data, size, NULL);
   1.251 -    assert(import_status == PEP_STATUS_OK);
   1.252 -    cout << "successfully imported key\n";
   1.253 -
   1.254 -    pEp_free(key_data);
   1.255 -
   1.256 -    cout << "deleting key " << key.c_str() << " again\n";
   1.257 -    delete_status = delete_keypair(session, key.c_str());
   1.258 -    cout << "delete_keypair() exits with " << delete_status << "\n";
   1.259 -    assert(delete_status == PEP_STATUS_OK);
   1.260 -
   1.261 -    cout << "finding key for pep.test.john@pep-project.org\n";
   1.262 -    PEP_STATUS find_keys_status = find_keys(session, "pep.test.john@pep-project.org", &keylist);
   1.263 -    cout << "find_keys() exits with " << find_keys_status << "\n";
   1.264 -    assert(find_keys_status == PEP_STATUS_OK);
   1.265 -    assert(keylist);
   1.266 -    cout << "found: " << keylist->value << "\n";
   1.267 -    assert(keylist->next == NULL);
   1.268 -    free_stringlist(keylist);
   1.269 -
   1.270 -    cout << "searching for vb@ulm.ccc.de on keyserver\n";
   1.271 -    PEP_STATUS recv_key_status = recv_key(session, "vb@ulm.ccc.de");
   1.272 -    cout << "recv_key() exits with " << recv_key_status << "\n";
   1.273 -    assert(recv_key_status == PEP_STATUS_OK);
   1.274 -
   1.275 -    cout << "sending vb@ulm.ccc.de to keyserver\n";
   1.276 -    PEP_STATUS send_key_status = send_key(session, "vb@ulm.ccc.de");
   1.277 -    cout << "send_key() exits with " << send_key_status << "\n";
   1.278 -    assert(send_key_status == PEP_STATUS_OK);
   1.279 -
   1.280 -    PEP_comm_type tcomm_type;
   1.281 -    PEP_STATUS tstatus = get_key_rating(session, "59BFF488C9C2EE39", &tcomm_type);
   1.282 -    cout << "get_key_rating() exits with " << tstatus << "\n";
   1.283 -    assert(tstatus == PEP_STATUS_OK);
   1.284 -    assert(tcomm_type == PEP_ct_OpenPGP_unconfirmed);
   1.285 -    
   1.286 -	cout << "\ncalling release()\n";
   1.287 -	release(session);
   1.288 -	return 0;
   1.289 -}
   1.290 +#include <iostream>
   1.291 +#include <fstream>
   1.292 +#include <string>
   1.293 +
   1.294 +#include <assert.h>
   1.295 +#include <string.h>
   1.296 +
   1.297 +#include "../src/pEpEngine.h"
   1.298 +#include "../src/keymanagement.h"
   1.299 +
   1.300 +using namespace std;
   1.301 +
   1.302 +void ReadFileIntoMem(const char *fname, char* &buffer, size_t &length){
   1.303 +    buffer = NULL;
   1.304 +    length = 0;
   1.305 +	cout << "opening " << fname << " for reading\n";
   1.306 +	ifstream txtFile (fname, ifstream::binary);
   1.307 +	assert(txtFile.is_open());
   1.308 +    if (txtFile) {
   1.309 +        // get length of file:
   1.310 +        txtFile.seekg (0, txtFile.end);
   1.311 +        length = txtFile.tellg();
   1.312 +        txtFile.seekg (0, txtFile.beg);
   1.313 +
   1.314 +        buffer = new char [length+1];
   1.315 +
   1.316 +        cout << "Reading " << length << " characters... ";
   1.317 +        txtFile.read (buffer,length);
   1.318 +        buffer[length]='\0';
   1.319 +
   1.320 +        if (txtFile)
   1.321 +          cout << "all characters read successfully.\n";
   1.322 +        else
   1.323 +          cout << "error: only " << txtFile.gcount() << " could be read\n";
   1.324 +        txtFile.close();
   1.325 +    }
   1.326 +
   1.327 +	txtFile.close();
   1.328 +    assert(buffer);
   1.329 +    assert(length);
   1.330 +}
   1.331 +
   1.332 +int main(int argc, char* argv[])
   1.333 +{
   1.334 +	PEP_SESSION session;
   1.335 +
   1.336 +	cout << "calling init()\n";
   1.337 +	PEP_STATUS init_result = init(&session);
   1.338 +	
   1.339 +    cout << "returning from init() with result == " << init_result << "\n";
   1.340 +	assert(init_result == PEP_STATUS_OK);
   1.341 +
   1.342 +    PEP_SESSION second_session;
   1.343 +    cout << "second session test\n";
   1.344 +    PEP_STATUS second_init_result = init(&second_session);
   1.345 +	cout << "returning from second init() with result == " << second_init_result << "\n";
   1.346 +    assert(second_init_result == PEP_STATUS_OK);
   1.347 +    assert(second_session);
   1.348 +    cout << "dropping second session\n";
   1.349 +	release(second_session);
   1.350 +
   1.351 +	cout << "logging test\n";
   1.352 +	log_event(session, "log test", "pEp Enginge Test", "This is a logging test sample.", "please ignore this line");
   1.353 +
   1.354 +    // Our test user :
   1.355 +    // pEp Test Alice (test key don't use) <pep.test.alice@pep-project.org>
   1.356 +    //         6FF00E97
   1.357 +    // A9411D176FF00E97
   1.358 +    // 
   1.359 +    // Other peers :
   1.360 +    // pEp Test Bob (test key, don't use) <pep.test.bob@pep-project.org> 
   1.361 +    //         C9C2EE39
   1.362 +    // 59BFF488C9C2EE39
   1.363 +    // 
   1.364 +    // pEp Test John (test key, don't use) <pep.test.john@pep-project.org>
   1.365 +    //         70DCF575
   1.366 +    // 135CD6D170DCF575
   1.367 +
   1.368 +    const char *kflist[] = {
   1.369 +        "0x6FF00E97.asc",
   1.370 +        "0xC9C2EE39.asc",
   1.371 +        "0x70DCF575.asc",
   1.372 +        NULL
   1.373 +    };
   1.374 +    const char** kf = kflist;
   1.375 +    while(*kf){
   1.376 +        char * k_user_buffer = NULL;
   1.377 +        size_t k_user_length = 0;
   1.378 +        ReadFileIntoMem(*kf, k_user_buffer, k_user_length);
   1.379 +        cout << "import_key(" << *kf << ")\n";
   1.380 +        PEP_STATUS import_status = import_key(session, k_user_buffer, k_user_length, NULL);
   1.381 +        assert(import_status == PEP_STATUS_OK);
   1.382 +        cout << "successfully imported key\n";
   1.383 +        delete[] k_user_buffer;
   1.384 +        kf++;
   1.385 +    }
   1.386 +
   1.387 +    char * cipher_buffer = NULL;
   1.388 +    size_t cipher_length = 0;
   1.389 +    ReadFileIntoMem("msg.asc", cipher_buffer, cipher_length);
   1.390 +
   1.391 +	cout << "\n" << cipher_buffer;
   1.392 +
   1.393 +	char *buf_text = NULL;
   1.394 +	size_t buf_size = 0;
   1.395 +	stringlist_t *keylist;
   1.396 +
   1.397 +    cout << "calling decrypt_and_verify()\n";
   1.398 +    PEP_STATUS decrypt_result = decrypt_and_verify(session, cipher_buffer, cipher_length, &buf_text, &buf_size, &keylist);
   1.399 +
   1.400 +    cout << "returning from decrypt_and_verify() with result == 0x" << std::hex << decrypt_result << "\n";
   1.401 +    assert(decrypt_result == PEP_DECRYPTED_AND_VERIFIED);
   1.402 +    assert(buf_text);
   1.403 +    assert(keylist);
   1.404 +
   1.405 +    for (stringlist_t *_keylist=keylist; _keylist!=NULL; _keylist=_keylist->next) {
   1.406 +        assert(_keylist->value);
   1.407 +        cout << "signed with " << _keylist->value << "\n";
   1.408 +    }
   1.409 +
   1.410 +    free_stringlist(keylist);
   1.411 +    buf_text[buf_size] = 0;
   1.412 +    string plain(buf_text);
   1.413 +    pEp_free(buf_text);
   1.414 +    cout << "\n" << plain;
   1.415 +
   1.416 +    char * t1_buffer = NULL;
   1.417 +    size_t t1_length = 0;
   1.418 +    ReadFileIntoMem("t1.txt", t1_buffer, t1_length);
   1.419 +
   1.420 +    char * sig_buffer = NULL;
   1.421 +    size_t sig_length = 0;
   1.422 +    ReadFileIntoMem("signature.asc", sig_buffer, sig_length);
   1.423 +
   1.424 +    cout << "\ncalling verify_text()\n";
   1.425 +    PEP_STATUS verify_result = verify_text(session, t1_buffer, t1_length, sig_buffer, sig_length, &keylist);
   1.426 +    cout << "returning from verify_text() with result == " << verify_result << "\n";
   1.427 +    assert(verify_result == PEP_VERIFIED || verify_result == PEP_VERIFIED_AND_TRUSTED);
   1.428 +    assert(keylist->value);
   1.429 +    cout << "signed with " << keylist->value << "\n";
   1.430 +    free_stringlist(keylist);
   1.431 +
   1.432 +    char * t2_buffer = NULL;
   1.433 +    size_t t2_length = 0;
   1.434 +    ReadFileIntoMem("t2.txt", t2_buffer, t2_length);
   1.435 +
   1.436 +    cout << "\ncalling verify_text()\n";
   1.437 +    verify_result = verify_text(session, t2_buffer, t2_length, sig_buffer, sig_length, &keylist);
   1.438 +    assert(verify_result == PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH);
   1.439 +    free_stringlist(keylist);
   1.440 +
   1.441 +    keylist = new_stringlist("A9411D176FF00E97");
   1.442 +    stringlist_add(keylist, "59BFF488C9C2EE39");
   1.443 +    stringlist_add(keylist, "135CD6D170DCF575");
   1.444 +
   1.445 +	buf_text = NULL;
   1.446 +	buf_size = 0;
   1.447 +
   1.448 +    cout << "\ncalling encrypt_and_sign()\n";
   1.449 +    PEP_STATUS encrypt_result = encrypt_and_sign(session, keylist, plain.c_str(), plain.length(), &buf_text, &buf_size);
   1.450 +    cout << "returning from encrypt_and_sign() with result == " << encrypt_result << "\n";
   1.451 +    assert(encrypt_result == PEP_STATUS_OK);
   1.452 +    free_stringlist(keylist);
   1.453 +
   1.454 +    buf_text[buf_size] = 0;
   1.455 +    string cipher2(buf_text);
   1.456 +    cout << "\n" << cipher2;
   1.457 +    pEp_free(buf_text);
   1.458 +
   1.459 +    delete[] cipher_buffer;
   1.460 +    delete[] t1_buffer;
   1.461 +    delete[] sig_buffer;
   1.462 +    delete[] t2_buffer;
   1.463 +
   1.464 +	cout << "\nfinding English trustword for 2342...\n";
   1.465 +	char * word;
   1.466 +	size_t wsize;
   1.467 +	trustword(session, 2342, "en", &word, &wsize);
   1.468 +	assert(word);
   1.469 +	cout << "the trustword for 2342 is " << word << "\n";
   1.470 +    pEp_free(word);
   1.471 +
   1.472 +    string fingerprint = "4942 2235 FC99 585B 891C  6653 0C7B 109B FA72 61F7";
   1.473 +    char * words;
   1.474 +
   1.475 +    cout << "\nfinding German trustwords for " << fingerprint << "...\n";
   1.476 +    trustwords(session, fingerprint.c_str(), "de", &words, &wsize, 5);
   1.477 +    assert(words);
   1.478 +    cout << words << "\n";
   1.479 +    pEp_free(words);
   1.480 +
   1.481 +	pEp_identity *identity;
   1.482 +
   1.483 +    identity = new_identity(
   1.484 +            "leon.schumacher@digitalekho.com",
   1.485 +            "8BD08954C74D830EEFFB5DEB2682A17F7C87F73D",
   1.486 +            "23",
   1.487 +            "Leon Schumacher"
   1.488 +        );
   1.489 +	identity->comm_type = PEP_ct_pEp;
   1.490 +
   1.491 +	cout << "\nsetting identity...\n";
   1.492 +	PEP_STATUS pep_set_result = set_identity(session, identity);
   1.493 +	assert(pep_set_result == PEP_STATUS_OK);
   1.494 +    free_identity(identity);
   1.495 +	get_identity(session, "leon.schumacher@digitalekho.com", "23", &identity);
   1.496 +	assert(identity);
   1.497 +	cout << "set: " << identity->address << ", " << identity->fpr << ", " << identity->user_id << ", " << identity->username << "\n";
   1.498 +
   1.499 +    PEP_STATUS get_trust_result = get_trust(session, identity);
   1.500 +    assert(get_trust_result == PEP_STATUS_OK);
   1.501 +    cout << "trust of " << identity->user_id << " is " << identity->comm_type << "\n";
   1.502 +
   1.503 +    free_identity(identity);
   1.504 +
   1.505 +    cout << "\ngenerating key for testuser\n";
   1.506 +    identity = new_identity(
   1.507 +            "testuser@pibit.ch",
   1.508 +            NULL,
   1.509 +            "423",
   1.510 +            "Alfred E. Neuman"
   1.511 +        );
   1.512 +    assert(identity);
   1.513 +    PEP_STATUS generate_status = generate_keypair(session, identity);
   1.514 +    cout << "generate_keypair() exits with " << generate_status << "\n";
   1.515 +    assert(generate_status == PEP_STATUS_OK);
   1.516 +    cout << "generated key is " << identity->fpr << "\n";
   1.517 +
   1.518 +    string key(identity->fpr);
   1.519 +    free_identity(identity);
   1.520 +
   1.521 +    char *key_data;
   1.522 +    size_t size;
   1.523 +
   1.524 +    cout << "export_key()\n\n";
   1.525 +    PEP_STATUS export_status = export_key(session, key.c_str(), &key_data, &size);
   1.526 +    cout << "export_key() exits with " << export_status << "\n";
   1.527 +    assert(export_status == PEP_STATUS_OK);
   1.528 +    cout << key_data << "\n\n";
   1.529 +
   1.530 +    cout << "deleting key pair " << key.c_str() << "\n";
   1.531 +    PEP_STATUS delete_status = delete_keypair(session, key.c_str());
   1.532 +    cout << "delete_keypair() exits with " << delete_status << "\n";
   1.533 +    assert(delete_status == PEP_STATUS_OK);
   1.534 +    
   1.535 +    cout << "import_key()\n";
   1.536 +    PEP_STATUS import_status = import_key(session, key_data, size, NULL);
   1.537 +    assert(import_status == PEP_STATUS_OK);
   1.538 +    cout << "successfully imported key\n";
   1.539 +
   1.540 +    pEp_free(key_data);
   1.541 +
   1.542 +    cout << "deleting key " << key.c_str() << " again\n";
   1.543 +    delete_status = delete_keypair(session, key.c_str());
   1.544 +    cout << "delete_keypair() exits with " << delete_status << "\n";
   1.545 +    assert(delete_status == PEP_STATUS_OK);
   1.546 +
   1.547 +    cout << "finding key for pep.test.john@pep-project.org\n";
   1.548 +    PEP_STATUS find_keys_status = find_keys(session, "pep.test.john@pep-project.org", &keylist);
   1.549 +    cout << "find_keys() exits with " << find_keys_status << "\n";
   1.550 +    assert(find_keys_status == PEP_STATUS_OK);
   1.551 +    assert(keylist);
   1.552 +    cout << "found: " << keylist->value << "\n";
   1.553 +    assert(keylist->next == NULL);
   1.554 +    free_stringlist(keylist);
   1.555 +
   1.556 +    cout << "searching for vb@ulm.ccc.de on keyserver\n";
   1.557 +    PEP_STATUS recv_key_status = recv_key(session, "vb@ulm.ccc.de");
   1.558 +    cout << "recv_key() exits with " << recv_key_status << "\n";
   1.559 +    assert(recv_key_status == PEP_STATUS_OK);
   1.560 +
   1.561 +    cout << "sending vb@ulm.ccc.de to keyserver\n";
   1.562 +    PEP_STATUS send_key_status = send_key(session, "vb@ulm.ccc.de");
   1.563 +    cout << "send_key() exits with " << send_key_status << "\n";
   1.564 +    assert(send_key_status == PEP_STATUS_OK);
   1.565 +
   1.566 +    PEP_comm_type tcomm_type;
   1.567 +    PEP_STATUS tstatus = get_key_rating(session, "59BFF488C9C2EE39", &tcomm_type);
   1.568 +    cout << "get_key_rating() exits with " << tstatus << "\n";
   1.569 +    assert(tstatus == PEP_STATUS_OK);
   1.570 +    assert(tcomm_type == PEP_ct_OpenPGP_unconfirmed);
   1.571 +    
   1.572 +	cout << "\ncalling release()\n";
   1.573 +	release(session);
   1.574 +	return 0;
   1.575 +}