test/least_color_group_test.cc
author Krista Bennett <krista@pep-project.org>
Mon, 05 Feb 2018 10:58:03 +0100
branchENGINE-250
changeset 2477 45e8ed722fec
parent 2462 48b526a0daac
child 2615 5cd3625e0d91
permissions -rw-r--r--
Intermittent commit
     1 #include <iostream>
     2 #include <iostream>
     3 #include <vector>
     4 #include <cstring> // for strcmp()
     5 #include <assert.h>
     6 #include "blacklist.h"
     7 #include "keymanagement.h"
     8 #include "message_api.h"
     9 #include "mime.h"
    10 #include "test_util.h"
    11 
    12 using namespace std;
    13 
    14 int main(int argc, char** argv) {
    15     cout << "\n*** least_color_group_test.cc ***\n\n";
    16     
    17     const char* mailfile = "test_mails/color_test.eml";
    18     
    19     const std::vector<const char*> keynames = {
    20                               "test_keys/priv/pep.color.test.P-0x3EBE215C_priv.asc",
    21                               "test_keys/pub/pep.color.test.H-0xD17E598E_pub.asc",
    22                               "test_keys/pub/pep.color.test.L-0xE9CDB4CE_pub.asc",
    23                               "test_keys/pub/pep.color.test.P-0x3EBE215C_pub.asc",
    24                               "test_keys/pub/pep.color.test.V-0x71FC6D28_pub.asc"
    25                           };
    26     
    27     PEP_SESSION session;
    28     
    29     cout << "calling init()\n";
    30     PEP_STATUS status1 = init(&session);   
    31     assert(status1 == PEP_STATUS_OK);
    32     assert(session);
    33     cout << "init() completed.\n";
    34     
    35     for (auto name : keynames) {
    36         cout << "\t read keyfile \"" << name << "\"..." << std::endl;
    37         const string keytextkey = slurp(name);
    38         PEP_STATUS statuskey = import_key(session, keytextkey.c_str(), keytextkey.length(), NULL);
    39         assert(statuskey == PEP_STATUS_OK);
    40     }
    41     
    42     cout << "\t read keyfile mailfile \"" << mailfile << "\"..." << std::endl;
    43     const string mailtext = slurp(mailfile);
    44     cout << "\t All files read successfully." << std::endl;
    45 
    46     pEp_identity * me1 = new_identity("pep.color.test.P@kgrothoff.org", 
    47                                       "7EE6C60C68851954E1797F81EA59715E3EBE215C", 
    48                                       PEP_OWN_USERID, "Pep Color Test P (recip)");
    49     me1->me = true;
    50     PEP_STATUS status = myself(session, me1);
    51     
    52     pEp_identity * sender1 = new_identity("pep.color.test.V@kgrothoff.org",
    53                                           NULL, "TOFU_pep.color.test.V@kgrothoff.org",
    54                                           "Pep Color Test V (sender)");
    55     
    56     status = update_identity(session, sender1);
    57     trust_personal_key(session, sender1);
    58     status = update_identity(session, sender1);
    59     
    60     message* msg_ptr = nullptr;
    61     message* dest_msg = nullptr;
    62     message* final_ptr = nullptr;
    63     stringlist_t* keylist = nullptr;
    64     PEP_rating rating;
    65     PEP_decrypt_flags_t flags;
    66     
    67     status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
    68     assert(status == PEP_STATUS_OK);
    69     assert(msg_ptr);
    70     final_ptr = msg_ptr;
    71     status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
    72     final_ptr = dest_msg ? dest_msg : msg_ptr;
    73   
    74     cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
    75     cout << "longmsg: " << final_ptr->longmsg << endl << endl;
    76     cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
    77     cout << "rating: " << rating << endl << endl;
    78     cout << "keys used: " << endl;
    79     
    80     int i = 0;
    81     for (stringlist_t* k = keylist; k; k = k->next) {
    82         if (i == 0)
    83             cout << "\t Signer (key 0):\t" << k->value << endl;
    84         else
    85             cout << "\t #" << i << ":\t" << k->value << endl;
    86         i++;
    87     }
    88     
    89 //    free_identity(me1);
    90     if (final_ptr == dest_msg)
    91     	free_message(dest_msg);
    92     free_message(msg_ptr);
    93     free_stringlist(keylist);
    94     
    95     cout << "calling release()\n";
    96     release(session);
    97     return 0;
    98 }