test/least_color_group_test.cc
author Roker <roker@pep-project.org>
Mon, 13 Mar 2017 19:32:19 +0100
changeset 1654 60778ef1e780
parent 1618 0fefbfbae9e1
child 1657 8b06f5627683
permissions -rw-r--r--
add more log output to see what's going on there...
     1 #include <iostream>
     2 #include <iostream>
     3 #include <fstream>
     4 #include <string>
     5 #include <cstring> // for strcmp()
     6 #include <assert.h>
     7 #include "blacklist.h"
     8 #include "keymanagement.h"
     9 #include "message_api.h"
    10 #include "mime.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 char* keynames[] = {"test_keys/priv/pep.color.test.P-0x3EBE215C_priv.asc",
    20                               "test_keys/pub/pep.color.test.H-0xD17E598E_pub.asc",
    21                               "test_keys/pub/pep.color.test.L-0xE9CDB4CE_pub.asc",
    22                               "test_keys/pub/pep.color.test.P-0x3EBE215C_pub.asc",
    23                               "test_keys/pub/pep.color.test.V-0x71FC6D28_pub.asc"
    24                           };
    25     
    26     const int num_keyfiles = 5;
    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     int i = 0;
    37     
    38     for ( ; i < num_keyfiles; i++) {
    39         cout << "\t read keyfile #" << i << ": \"" << keynames[i] << "\"..." << std::endl;
    40         ifstream infilekey(keynames[i]);
    41         string keytextkey;
    42         while (!infilekey.eof()) {
    43             static string line;
    44             getline(infilekey, line);
    45             keytextkey += line + "\n";
    46         }
    47         infilekey.close(); 
    48         PEP_STATUS statuskey = import_key(session, keytextkey.c_str(), keytextkey.length(), NULL);
    49         assert(statuskey == PEP_STATUS_OK);
    50     }
    51     
    52     cout << "\t read keyfile mailfile \"" << mailfile << "\"..." << std::endl;
    53     ifstream infile(mailfile);
    54     string mailtext;
    55     while (!infile.eof()) {
    56         static string line;
    57         getline(infile, line);
    58         mailtext += line + "\n";
    59     }
    60     infile.close(); 
    61     cout << "\t All files read successfully." << std::endl;
    62 
    63     pEp_identity * me1 = new_identity("pep.color.test.P@kgrothoff.org", NULL, 
    64                                       PEP_OWN_USERID, "Pep Color Test P (recip)");
    65     me1->me = true;    
    66     PEP_STATUS status = update_identity(session, me1);
    67     trust_personal_key(session, me1);
    68     status = update_identity(session, me1);
    69     
    70     pEp_identity * sender1 = new_identity("pep.color.test.V@kgrothoff.org",
    71                                           NULL, "TOFU_pep.color.test.V@kgrothoff.org",
    72                                           "Pep Color Test V (sender)");
    73     
    74     sender1->me = false;
    75     status = update_identity(session, sender1);
    76     trust_personal_key(session, sender1);
    77     status = update_identity(session, sender1);    
    78     
    79     message* msg_ptr = nullptr;
    80     message* dest_msg = nullptr;
    81     message* final_ptr = nullptr;
    82     stringlist_t* keylist = nullptr;
    83     PEP_rating rating;
    84     PEP_decrypt_flags_t flags;
    85     
    86     status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
    87     assert(status == PEP_STATUS_OK);
    88     assert(msg_ptr);
    89     final_ptr = msg_ptr;
    90     status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
    91     final_ptr = dest_msg ? dest_msg : msg_ptr;
    92   
    93     cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
    94     cout << "longmsg: " << final_ptr->longmsg << endl << endl;
    95     cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
    96     cout << "rating: " << rating << endl << endl;
    97     cout << "keys used: " << endl;
    98     i = 0;
    99     for (stringlist_t* k = keylist; k; k = k->next) {
   100         if (i == 0)
   101        	    cout << "\t Signer (key 0):\t" << k->value << endl;
   102         else
   103             cout << "\t #" << i << ":\t" << k->value << endl;
   104         i++;
   105     }
   106     
   107 //    free_identity(me1);
   108     if (final_ptr == dest_msg)
   109     	free_message(dest_msg);
   110     free_message(msg_ptr);
   111     free_stringlist(keylist);
   112     
   113     cout << "calling release()\n";
   114     release(session);
   115     return 0;
   116 }