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",
47 "7EE6C60C68851954E1797F81EA59715E3EBE215C",
48 PEP_OWN_USERID, "Pep Color Test P (recip)");
50 PEP_STATUS status = update_identity(session, me1);
51 trust_personal_key(session, me1);
52 status = update_identity(session, me1);
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)");
59 status = update_identity(session, sender1);
60 trust_personal_key(session, sender1);
61 status = update_identity(session, sender1);
63 message* msg_ptr = nullptr;
64 message* dest_msg = nullptr;
65 message* final_ptr = nullptr;
66 stringlist_t* keylist = nullptr;
68 PEP_decrypt_flags_t flags;
70 status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
71 assert(status == PEP_STATUS_OK);
74 status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
75 final_ptr = dest_msg ? dest_msg : msg_ptr;
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;
84 for (stringlist_t* k = keylist; k; k = k->next) {
86 cout << "\t Signer (key 0):\t" << k->value << endl;
88 cout << "\t #" << i << ":\t" << k->value << endl;
92 // free_identity(me1);
93 if (final_ptr == dest_msg)
94 free_message(dest_msg);
95 free_message(msg_ptr);
96 free_stringlist(keylist);
98 cout << "calling release()\n";