ENGINE-180: not tested, but MIME_encrypt_message_for_self is in with flags ENGINE-180
authorKrista Grothoff <krista@pep-project.org>
Mon, 13 Mar 2017 08:43:04 +0100
branchENGINE-180
changeset 16411c9358f42ce0
parent 1640 52e90165ad0f
child 1642 af07ab39e430
child 1643 ad1320f6c299
ENGINE-180: not tested, but MIME_encrypt_message_for_self is in with flags
src/message_api.c
src/message_api.h
     1.1 --- a/src/message_api.c	Fri Mar 10 17:53:48 2017 +0100
     1.2 +++ b/src/message_api.c	Mon Mar 13 08:43:04 2017 +0100
     1.3 @@ -1334,8 +1334,8 @@
     1.4              break;
     1.5  
     1.6          /* case PEP_enc_PEP:
     1.7 +            NOT_IMPLEMENTED */
     1.8              // TODO: implement
     1.9 -            NOT_IMPLEMENTED */
    1.10  
    1.11          default:
    1.12              assert(0);
    1.13 @@ -2544,6 +2544,7 @@
    1.14      return status;
    1.15  }
    1.16  
    1.17 +
    1.18  DYNAMIC_API PEP_STATUS MIME_encrypt_message(
    1.19      PEP_SESSION session,
    1.20      const char *mimetext,
    1.21 @@ -2582,3 +2583,42 @@
    1.22      return status;
    1.23  
    1.24  }
    1.25 +
    1.26 +DYNAMIC_API PEP_STATUS MIME_encrypt_message_for_self(
    1.27 +    PEP_SESSION session,
    1.28 +    pEp_identity* target_id,
    1.29 +    const char *mimetext,
    1.30 +    size_t size,
    1.31 +    stringlist_t* extra,
    1.32 +    char** mime_ciphertext,
    1.33 +    PEP_enc_format enc_format,
    1.34 +    PEP_encrypt_flags_t flags
    1.35 +)
    1.36 +{
    1.37 +    PEP_STATUS status = PEP_STATUS_OK;
    1.38 +    message* tmp_msg = NULL;
    1.39 +    message* enc_msg = NULL;
    1.40 +
    1.41 +    status = mime_decode_message(mimetext, size, &tmp_msg);
    1.42 +    if (status != PEP_STATUS_OK)
    1.43 +        goto pep_error;
    1.44 +
    1.45 +    // This isn't incoming, though... so we need to reverse the direction
    1.46 +    tmp_msg->dir = PEP_dir_outgoing;
    1.47 +    status = encrypt_message_for_self(session,
    1.48 +                                      target_id,
    1.49 +                                      tmp_msg,
    1.50 +                                      &enc_msg,
    1.51 +                                      enc_format,
    1.52 +                                      flags);
    1.53 +    if (status != PEP_STATUS_OK)
    1.54 +        goto pep_error;
    1.55 +
    1.56 +    status = mime_encode_message(enc_msg, false, mime_ciphertext);
    1.57 +
    1.58 +pep_error:
    1.59 +    free_message(tmp_msg);
    1.60 +    free_message(enc_msg);
    1.61 +
    1.62 +    return status;
    1.63 +}
     2.1 --- a/src/message_api.h	Fri Mar 10 17:53:48 2017 +0100
     2.2 +++ b/src/message_api.h	Mon Mar 13 08:43:04 2017 +0100
     2.3 @@ -135,6 +135,44 @@
     2.4      PEP_encrypt_flags_t flags
     2.5  );
     2.6  
     2.7 +// MIME_encrypt_message_for_self() - encrypt MIME message for user's identity only,
     2.8 +//                              ignoring recipients and other identities from
     2.9 +//                              the message, with MIME output
    2.10 +//  parameters:
    2.11 +//      session (in)            session handle
    2.12 +//      mimetext (in)           MIME encoded text to encrypt
    2.13 +//      size (in)               size of input mime text
    2.14 +//      extra (in)              extra keys for encryption
    2.15 +//      mime_ciphertext (out)   encrypted, encoded message
    2.16 +//      enc_format (in)         encrypted format
    2.17 +//      flags (in)              flags to set special encryption features
    2.18 +//
    2.19 +//  return value:
    2.20 +//      PEP_STATUS_OK           if everything worked
    2.21 +//      PEP_BUFFER_TOO_SMALL    if encoded message size is too big to handle
    2.22 +//      PEP_CANNOT_CREATE_TEMP_FILE
    2.23 +//                              if there are issues with temp files; in
    2.24 +//                              this case errno will contain the underlying
    2.25 +//                              error
    2.26 +//      PEP_OUT_OF_MEMORY       if not enough memory could be allocated
    2.27 +//
    2.28 +//  caveat:
    2.29 +//      the encrypted, encoded mime text will go to the ownership of the caller; mimetext
    2.30 +//      will remain in the ownership of the caller
    2.31 +
    2.32 +DYNAMIC_API PEP_STATUS MIME_encrypt_message_for_self(
    2.33 +    PEP_SESSION session,
    2.34 +    pEp_identity* target_id,
    2.35 +    const char *mimetext,
    2.36 +    size_t size,
    2.37 +    stringlist_t* extra,
    2.38 +    char** mime_ciphertext,
    2.39 +    PEP_enc_format enc_format,
    2.40 +    PEP_encrypt_flags_t flags
    2.41 +);
    2.42 +
    2.43 +
    2.44 +
    2.45  typedef enum _PEP_rating {
    2.46      PEP_rating_undefined = 0,
    2.47      PEP_rating_cannot_decrypt,