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