4 #include <cstring> // for strcmp()
7 #include "keymanagement.h"
8 #include "message_api.h"
10 #include "test_util.h"
14 int main(int argc, char** argv) {
15 cout << "\n*** least_color_group_test.cc ***\n\n";
17 const char* mailfile = "test_mails/color_test.eml";
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"
29 cout << "calling init()\n";
30 PEP_STATUS status1 = init(&session);
31 assert(status1 == PEP_STATUS_OK);
33 cout << "init() completed.\n";
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);
42 cout << "\t read keyfile mailfile \"" << mailfile << "\"..." << std::endl;
43 const string mailtext = slurp(mailfile);
44 cout << "\t All files read successfully." << std::endl;
46 pEp_identity * me1 = new_identity("pep.color.test.P@kgrothoff.org", NULL,
47 PEP_OWN_USERID, "Pep Color Test P (recip)");
49 PEP_STATUS status = update_identity(session, me1);
50 trust_personal_key(session, me1);
51 status = update_identity(session, me1);
53 pEp_identity * sender1 = new_identity("pep.color.test.V@kgrothoff.org",
54 NULL, "TOFU_pep.color.test.V@kgrothoff.org",
55 "Pep Color Test V (sender)");
58 status = update_identity(session, sender1);
59 trust_personal_key(session, sender1);
60 status = update_identity(session, sender1);
62 message* msg_ptr = nullptr;
63 message* dest_msg = nullptr;
64 message* final_ptr = nullptr;
65 stringlist_t* keylist = nullptr;
67 PEP_decrypt_flags_t flags;
69 status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
70 assert(status == PEP_STATUS_OK);
73 status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
74 final_ptr = dest_msg ? dest_msg : msg_ptr;
76 cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
77 cout << "longmsg: " << final_ptr->longmsg << endl << endl;
78 cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
79 cout << "rating: " << rating << endl << endl;
80 cout << "keys used: " << endl;
83 for (stringlist_t* k = keylist; k; k = k->next) {
85 cout << "\t Signer (key 0):\t" << k->value << endl;
87 cout << "\t #" << i << ":\t" << k->value << endl;
91 // free_identity(me1);
92 if (final_ptr == dest_msg)
93 free_message(dest_msg);
94 free_message(msg_ptr);
95 free_stringlist(keylist);
97 cout << "calling release()\n";