test/least_color_group_test.cc
author Krista Bennett <krista@pep-project.org>
Fri, 01 Jun 2018 10:30:21 +0200
branchENGINE-217
changeset 2732 2d177ec3804b
parent 1847 050f0e83c3f7
child 1945 9503c962f746
permissions -rw-r--r--
close branch
     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 = update_identity(session, me1);
    51     trust_personal_key(session, me1);
    52     status = update_identity(session, me1);
    53     
    54     pEp_identity * sender1 = new_identity("pep.color.test.V@kgrothoff.org",
    55                                           NULL, "TOFU_pep.color.test.V@kgrothoff.org",
    56                                           "Pep Color Test V (sender)");
    57     
    58     sender1->me = false;
    59     status = update_identity(session, sender1);
    60     trust_personal_key(session, sender1);
    61     status = update_identity(session, sender1);
    62     
    63     message* msg_ptr = nullptr;
    64     message* dest_msg = nullptr;
    65     message* final_ptr = nullptr;
    66     stringlist_t* keylist = nullptr;
    67     PEP_rating rating;
    68     PEP_decrypt_flags_t flags;
    69     
    70     status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
    71     assert(status == PEP_STATUS_OK);
    72     assert(msg_ptr);
    73     final_ptr = msg_ptr;
    74     status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
    75     final_ptr = dest_msg ? dest_msg : msg_ptr;
    76   
    77     cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
    78     cout << "longmsg: " << final_ptr->longmsg << endl << endl;
    79     cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
    80     cout << "rating: " << rating << endl << endl;
    81     cout << "keys used: " << endl;
    82     
    83     int i = 0;
    84     for (stringlist_t* k = keylist; k; k = k->next) {
    85         if (i == 0)
    86             cout << "\t Signer (key 0):\t" << k->value << endl;
    87         else
    88             cout << "\t #" << i << ":\t" << k->value << endl;
    89         i++;
    90     }
    91     
    92 //    free_identity(me1);
    93     if (final_ptr == dest_msg)
    94     	free_message(dest_msg);
    95     free_message(msg_ptr);
    96     free_stringlist(keylist);
    97     
    98     cout << "calling release()\n";
    99     release(session);
   100     return 0;
   101 }