adding keylist parameter to decrypt_message
authorVolker Birk <vb@pep-project.org>
Tue, 05 May 2015 10:15:34 +0200
changeset 241176b70529dc3
parent 240 25e968e8e72b
child 242 6736f061c8f8
adding keylist parameter to decrypt_message
src/message_api.c
src/message_api.h
test/message_api_test.cc
     1.1 --- a/src/message_api.c	Tue May 05 08:42:50 2015 +0200
     1.2 +++ b/src/message_api.c	Tue May 05 10:15:34 2015 +0200
     1.3 @@ -358,12 +358,14 @@
     1.4          else {
     1.5              // decrypt and re-encrypt again
     1.6              message * _dst = NULL;
     1.7 +            stringlist_t *_keylist = NULL;
     1.8              PEP_MIME_format mime = (enc_format == PEP_enc_PEP) ? PEP_MIME :
     1.9                      PEP_MIME_fields_omitted;
    1.10  
    1.11 -            status = decrypt_message(session, src, mime, &_dst);
    1.12 +            status = decrypt_message(session, src, mime, &_dst, &_keylist);
    1.13              if (status != PEP_STATUS_OK)
    1.14                  goto pep_error;
    1.15 +            free_stringlist(_keylist);
    1.16  
    1.17              src = _dst;
    1.18              free_src = true;
    1.19 @@ -648,7 +650,8 @@
    1.20          PEP_SESSION session,
    1.21          message *src,
    1.22          PEP_MIME_format mime,
    1.23 -        message **dst
    1.24 +        message **dst,
    1.25 +        stringlist_t **keylist
    1.26      )
    1.27  {
    1.28      PEP_STATUS status = PEP_STATUS_OK;
    1.29 @@ -657,14 +660,15 @@
    1.30      size_t csize;
    1.31      char *ptext;
    1.32      size_t psize;
    1.33 -    stringlist_t *keylist;
    1.34 +    stringlist_t *_keylist = NULL;
    1.35      bool free_src = false;
    1.36  
    1.37      assert(session);
    1.38      assert(src);
    1.39      assert(dst);
    1.40 +    assert(keylist);
    1.41  
    1.42 -    if (!(session && src && dst))
    1.43 +    if (!(session && src && dst && keylist))
    1.44          return PEP_ILLEGAL_VALUE;
    1.45  
    1.46      *dst = NULL;
    1.47 @@ -701,7 +705,7 @@
    1.48      csize = strlen(src->longmsg);
    1.49  
    1.50      status = decrypt_and_verify(session, ctext, csize, &ptext, &psize,
    1.51 -            &keylist);
    1.52 +            &_keylist);
    1.53      if (ptext == NULL)
    1.54          goto pep_error;
    1.55  
    1.56 @@ -726,14 +730,16 @@
    1.57              bloblist_t *_s;
    1.58              for (_s = src->attachments; _s; _s = _s->next) {
    1.59                  if (is_encrypted_attachment(_s)) {
    1.60 +                    stringlist_t *_keylist = NULL;
    1.61                      ctext = _s->data;
    1.62                      csize = _s->size;
    1.63  
    1.64                      status = decrypt_and_verify(session, ctext, csize, &ptext,
    1.65 -                            &psize, &keylist);
    1.66 +                            &psize, &_keylist);
    1.67                      if (ptext == NULL)
    1.68                          goto pep_error;
    1.69 -                    
    1.70 +                    free_stringlist(_keylist);
    1.71 +
    1.72                      if (is_encrypted_html_attachment(_s)) {
    1.73                          msg->longmsg_formatted = strdup(ptext);
    1.74                          if (msg->longmsg_formatted == NULL)
    1.75 @@ -840,6 +846,8 @@
    1.76      import_attached_keys(session, msg);
    1.77  
    1.78      *dst = msg;
    1.79 +    *keylist = _keylist;
    1.80 +
    1.81      return PEP_STATUS_OK;
    1.82  
    1.83  enomem:
    1.84 @@ -847,6 +855,7 @@
    1.85  
    1.86  pep_error:
    1.87      free_message(msg);
    1.88 +    free_stringlist(_keylist);
    1.89      if (free_src)
    1.90          free_message(src);
    1.91  
     2.1 --- a/src/message_api.h	Tue May 05 08:42:50 2015 +0200
     2.2 +++ b/src/message_api.h	Tue May 05 10:15:34 2015 +0200
     2.3 @@ -51,6 +51,7 @@
     2.4  //      src (in)            message to decrypt
     2.5  //      mime (in)           MIME encoding wanted
     2.6  //      dst (out)           pointer to new decrypted message or NULL on failure
     2.7 +//      keylist (out)       stringlist with keyids
     2.8  //
     2.9  //  return value:
    2.10  //      error status or PEP_STATUS_OK on success
    2.11 @@ -62,7 +63,8 @@
    2.12          PEP_SESSION session,
    2.13          message *src,
    2.14          PEP_MIME_format mime,
    2.15 -        message **dst
    2.16 +        message **dst,
    2.17 +        stringlist_t **keylist
    2.18      );
    2.19  
    2.20  
     3.1 --- a/test/message_api_test.cc	Tue May 05 08:42:50 2015 +0200
     3.2 +++ b/test/message_api_test.cc	Tue May 05 10:15:34 2015 +0200
     3.3 @@ -65,9 +65,19 @@
     3.4      outFile3.close();
     3.5  
     3.6      message *msg4;
     3.7 -    PEP_STATUS status4 = decrypt_message(session, enc_msg2, PEP_MIME_none, &msg4);
     3.8 +    stringlist_t *keylist4;
     3.9 +    PEP_STATUS status4 = decrypt_message(session, enc_msg2, PEP_MIME_none, &msg4, &keylist4);
    3.10      assert(status4 == PEP_STATUS_OK);
    3.11      assert(msg4);
    3.12 +    assert(keylist4);
    3.13 +
    3.14 +    cout << "keys used:";
    3.15 +    stringlist_t *kl4;
    3.16 +    for (kl4 = keylist4; kl4 && kl4->value; kl4 = kl4->next)
    3.17 +        cout << " " << kl4->value;
    3.18 +    cout << "\n\n";
    3.19 +
    3.20 +    free_stringlist(keylist4);
    3.21  
    3.22      cout << "freeing messages…\n";
    3.23      free_message(msg4);