adding of extra key information to internal header for future feature

extra_keys_add
parent e66bc6e305
commit 735cc2339f

@ -838,7 +838,9 @@ enomem:
}
static message* wrap_message_as_attachment(message* envelope,
message* attachment, message_wrap_type wrap_type, bool keep_orig_subject, unsigned int max_major, unsigned int max_minor) {
message* attachment, message_wrap_type wrap_type,
bool keep_orig_subject, stringlist_t* extra_keys,
unsigned int max_major, unsigned int max_minor) {
if (!attachment)
return NULL;
@ -848,7 +850,13 @@ static message* wrap_message_as_attachment(message* envelope,
PEP_STATUS status = PEP_STATUS_OK;
replace_opt_field(attachment, "X-pEp-Version", PEP_VERSION, true);
if (extra_keys) {
char* ex_keystr = stringlist_to_string(extra_keys);
if (ex_keystr)
add_opt_field(attachment, "X-pEp-extra-keys", ex_keystr);
}
if (!_envelope && (wrap_type != PEP_message_transport)) {
_envelope = extract_minimal_envelope(attachment, PEP_dir_outgoing);
status = generate_message_id(_envelope);
@ -1944,7 +1952,7 @@ DYNAMIC_API PEP_STATUS encrypt_message(
message_wrap_type wrap_type = PEP_message_unwrapped;
if ((enc_format != PEP_enc_inline) && (!force_v_1) && ((max_comm_type | PEP_ct_confirmed) == PEP_ct_pEp)) {
wrap_type = ((flags & PEP_encrypt_flag_key_reset_only) ? PEP_message_key_reset : PEP_message_default);
_src = wrap_message_as_attachment(NULL, src, wrap_type, false, max_version_major, max_version_minor);
_src = wrap_message_as_attachment(NULL, src, wrap_type, false, extra, max_version_major, max_version_minor);
if (!_src)
goto pEp_error;
}
@ -2014,6 +2022,7 @@ DYNAMIC_API PEP_STATUS encrypt_message(
if (_src && _src != src)
free_message(_src);
// Do similar for extra key list...
_cleanup_src(src, added_key_to_real_src);
return status;
@ -2292,7 +2301,7 @@ DYNAMIC_API PEP_STATUS encrypt_message_for_self(
unsigned int major_ver, minor_ver;
pEp_version_major_minor(PEP_VERSION, &major_ver, &minor_ver);
_src = wrap_message_as_attachment(NULL, src, PEP_message_default, false, major_ver, minor_ver);
_src = wrap_message_as_attachment(NULL, src, PEP_message_default, false, extra, major_ver, minor_ver);
if (!_src)
goto pEp_error;

@ -285,3 +285,60 @@ DYNAMIC_API void free_stringlist(stringlist_t *stringlist)
curr = next;
}
}
char* stringlist_to_string(stringlist_t* list) {
if (!list)
return NULL;
unsigned int size = 0;
unsigned int count = 0;
stringlist_t* curr;
// calc size
for (curr = list; curr; curr = curr->next) {
if (!curr->value)
return NULL;
size += strlen(curr->value);
count++;
}
size += (count - 1) + 1;
char* retval = calloc(size, 1);
int i;
strlcpy(retval, list->value, size);
for (i = 1, curr = list->next; curr && (i < count); i++, curr = curr->next) {
strlcat(retval, ",", size);
strlcat(retval, curr->value, size);
}
return retval;
}
stringlist_t* string_to_stringlist(const char* str) {
if (!str || str[0] == '\0')
return NULL;
// Because of strtok, we do this
char* workstr = strdup(str);
if (!workstr)
return NULL;
char* token = strtok(workstr, ",");
stringlist_t* retval = new_stringlist(NULL);
while (token) {
if (token && token[0] != '\0')
stringlist_add(retval, token);
token = strtok(NULL, ",");
}
free(workstr);
if (!retval->value) {
free_stringlist(retval);
retval = NULL;
}
return retval;
}

@ -135,6 +135,10 @@ DYNAMIC_API void free_stringlist(stringlist_t *stringlist);
stringlist_t* stringlist_search(stringlist_t* head, const char* value);
// create comma-separated string
char* stringlist_to_string(stringlist_t* list);
stringlist_t* string_to_stringlist(const char* str);
void dedup_stringlist(stringlist_t* stringlist);
#ifdef __cplusplus

@ -236,3 +236,132 @@ TEST_F(StringlistTest, check_dedup_stringlist) {
ASSERT_NE(s_list->next->next->next->value, nullptr);
ASSERT_STREQ(s_list->next->next->next->value, str4);
}
TEST_F(StringlistTest, check_stringlist_to_string_null) {
stringlist_t* sl = NULL;
char* stringy = stringlist_to_string(sl);
ASSERT_EQ(stringy, nullptr);
}
TEST_F(StringlistTest, check_string_to_stringlist_null) {
const char* cl = NULL;
stringlist_t* sl = string_to_stringlist(cl);
ASSERT_EQ(sl, nullptr);
}
TEST_F(StringlistTest, check_stringlist_to_string_empty) {
stringlist_t* sl = new_stringlist(NULL);
char* stringy = stringlist_to_string(sl);
ASSERT_EQ(stringy, nullptr);
}
TEST_F(StringlistTest, check_string_to_stringlist_empty) {
const char* cl = "";
stringlist_t* sl = string_to_stringlist(cl);
ASSERT_EQ(sl, nullptr);
}
TEST_F(StringlistTest, check_stringlist_to_string_single) {
const char* str0 = "Eat my shorts";
stringlist_t* sl = new_stringlist(str0);
char* stringy = stringlist_to_string(sl);
ASSERT_STREQ(str0, stringy);
}
TEST_F(StringlistTest, check_string_to_stringlist_single) {
const char* cl = "Eat my shorts";
stringlist_t* sl = string_to_stringlist(cl);
ASSERT_NE(sl, nullptr);
ASSERT_NE(sl->value, nullptr);
ASSERT_EQ(sl->next, nullptr);
ASSERT_STREQ(sl->value, cl);
}
TEST_F(StringlistTest, check_stringlist_to_string_two) {
const char* str0 = "Non";
const char* str1 = "je ne regrette rien";
stringlist_t* sl = new_stringlist(str0);
stringlist_add(sl, str1);
char* stringy = stringlist_to_string(sl);
ASSERT_STREQ(stringy, "Non,je ne regrette rien");
}
TEST_F(StringlistTest, check_string_to_stringlist_two) {
const char* cl = "Non,je ne regrette rien";
const char* str0 = "Non";
const char* str1 = "je ne regrette rien";
stringlist_t* sl = string_to_stringlist(cl);
ASSERT_NE(sl, nullptr);
ASSERT_NE(sl->value, nullptr);
ASSERT_NE(sl->next, nullptr);
ASSERT_NE(sl->next->value, nullptr);
ASSERT_EQ(sl->next->next, nullptr);
ASSERT_STREQ(sl->value, str0);
ASSERT_STREQ(sl->next->value, str1);
}
TEST_F(StringlistTest, check_stringlist_to_string_five) {
const char* str0 = "I am so tired";
const char* str1 = " of doing stuff";
const char* str2 = "Bob";
const char* str3 = "Fix your crypto and your comma key";
const char* str4 = "Alice";
stringlist_t* sl = new_stringlist(str0);
stringlist_add(sl, str1);
stringlist_add(sl, str2);
stringlist_add(sl, str3);
stringlist_add(sl, str4);
const char* result = "I am so tired, of doing stuff,Bob,Fix your crypto and your comma key,Alice";
char* stringy = stringlist_to_string(sl);
ASSERT_STREQ(stringy, result);
}
TEST_F(StringlistTest, check_string_to_stringlist_five) {
const char* cl = "I am so tired, of doing stuff,Bob,Fix your crypto and your comma key,Alice";
const char* str0 = "I am so tired";
const char* str1 = " of doing stuff";
const char* str2 = "Bob";
const char* str3 = "Fix your crypto and your comma key";
const char* str4 = "Alice";
stringlist_t* sl = string_to_stringlist(cl);
ASSERT_NE(sl, nullptr);
ASSERT_NE(sl->value, nullptr);
ASSERT_NE(sl->next, nullptr);
ASSERT_NE(sl->next->value, nullptr);
ASSERT_NE(sl->next->next, nullptr);
ASSERT_NE(sl->next->next->value, nullptr);
ASSERT_NE(sl->next->next->next, nullptr);
ASSERT_NE(sl->next->next->next->value, nullptr);
ASSERT_NE(sl->next->next->next->next, nullptr);
ASSERT_NE(sl->next->next->next->next->value, nullptr);
ASSERT_EQ(sl->next->next->next->next->next, nullptr);
ASSERT_STREQ(sl->value, str0);
ASSERT_STREQ(sl->next->value, str1);
ASSERT_STREQ(sl->next->next->value, str2);
ASSERT_STREQ(sl->next->next->next->value, str3);
ASSERT_STREQ(sl->next->next->next->next->value, str4);
}
TEST_F(StringlistTest, check_string_to_stringlist_commas) {
const char* cl = ",,,,";
stringlist_t* sl = string_to_stringlist(cl);
ASSERT_EQ(sl, nullptr);
}
TEST_F(StringlistTest, check_string_to_stringlist_commas_to_two) {
const char* cl = ",Non,,je ne regrette rien,";
const char* str0 = "Non";
const char* str1 = "je ne regrette rien";
stringlist_t* sl = string_to_stringlist(cl);
ASSERT_NE(sl, nullptr);
ASSERT_NE(sl->value, nullptr);
ASSERT_NE(sl->next, nullptr);
ASSERT_NE(sl->next->value, nullptr);
ASSERT_EQ(sl->next->next, nullptr);
ASSERT_STREQ(sl->value, str0);
ASSERT_STREQ(sl->next->value, str1);
}

Loading…
Cancel
Save