[gmime] Added NO_COMPRESS and SYMMETRIC options for GMimeEncryptFlags



commit ff7a3be1e4b6a01e4db29c528becffbbc7704420
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date:   Tue Mar 14 20:49:43 2017 -0400

    Added NO_COMPRESS and SYMMETRIC options for GMimeEncryptFlags

 PORTING                         |    4 ++--
 docs/reference/changes-3.0.sgml |    4 ++--
 examples/basic-example.c        |    2 +-
 gmime/gmime-crypto-context.h    |   24 ++++++++++++++----------
 gmime/gmime-gpgme-utils.c       |    9 +++------
 tests/test-pgp.c                |    2 +-
 tests/test-pgpmime.c            |    6 +++---
 tests/test-pkcs7.c              |    2 +-
 tests/test-smime.c              |    2 +-
 9 files changed, 28 insertions(+), 27 deletions(-)
---
diff --git a/PORTING b/PORTING
index ec87014..943fb1f 100644
--- a/PORTING
+++ b/PORTING
@@ -74,14 +74,14 @@ Porting from GMime 2.6 to GMime 3.0
   to GMIME_TRUST_UNKNOWN.
 
 - Removed g_mime_gpg_context_[get,set]_always_trust(). This can now be accomplished
-  by passing GMIME_ENCRYPT_FLAGS_ALWAYS_TRUST to g_mime_crypto_context_encrypt().
+  by passing GMIME_ENCRYPT_ALWAYS_TRUST to g_mime_crypto_context_encrypt().
 
 - Removed g_mime_gpg_context_[get,set]_use_agent(). This should no longer be needed.
 
 - Removed g_mime_gpg_context_[get,set]_auto_key_retrieve().
 
 - Removed g_mime_crypto_context_[get,set]_retrieve_session_key(). This is now handled by
-  passing GMIME_DECRYPT_FLAGS_EXPORT_SESSION_KEY to the g_mime_crypto_context_decrypt()
+  passing GMIME_DECRYPT_EXPORT_SESSION_KEY to the g_mime_crypto_context_decrypt()
   method.
 
 - GMimeCryptoContext's encrypt, decrypt, and verify methods now all take a flags argument
diff --git a/docs/reference/changes-3.0.sgml b/docs/reference/changes-3.0.sgml
index 6a24117..d77a473 100644
--- a/docs/reference/changes-3.0.sgml
+++ b/docs/reference/changes-3.0.sgml
@@ -23,10 +23,10 @@
     <para>Cryptography related API changes:</para>
     <itemizedlist>
       <listitem><para>Renamed GMimeCertificateTrust to GMimeTrust and GMIME_CERTIFICATE_TRUST_NONE to 
GMIME_TRUST_UNKNOWN.</para></listitem>
-      <listitem><para>Removed <function>g_mime_gpg_context_get_always_trust()</function> and 
<function>g_mime_gpg_context_set_always_trust()</function>. This can now be accomplished by passing 
GMIME_ENCRYPT_FLAGS_ALWAYS_TRUST to <function>g_mime_crypto_context_encrypt()</function>.</para></listitem>
+      <listitem><para>Removed <function>g_mime_gpg_context_get_always_trust()</function> and 
<function>g_mime_gpg_context_set_always_trust()</function>. This can now be accomplished by passing 
GMIME_ENCRYPT_ALWAYS_TRUST to <function>g_mime_crypto_context_encrypt()</function>.</para></listitem>
       <listitem><para>Removed <function>g_mime_gpg_context_get_use_agent()</function> and 
<function>g_mime_gpg_context_set_use_agent()</function>. This should no longer be needed.</para></listitem>
       <listitem><para>Removed <function>g_mime_gpg_context_get_auto_key_retrieve()</function> and 
<function>g_mime_gpg_context_set_auto_key_retrieve()</function>.</para></listitem>
-      <listitem><para>Removed <function>g_mime_crypto_context_get_retrieve_session_key()</function> and 
<function>g_mime_crypto_context_set_retrieve_session_key()</function>. This is now handled by passing 
GMIME_DECRYPT_FLAGS_EXPORT_SESSION_KEY to the <function>g_mime_crypto_context_decrypt()</function> 
method.</para></listitem>
+      <listitem><para>Removed <function>g_mime_crypto_context_get_retrieve_session_key()</function> and 
<function>g_mime_crypto_context_set_retrieve_session_key()</function>. This is now handled by passing 
GMIME_DECRYPT_EXPORT_SESSION_KEY to the <function>g_mime_crypto_context_decrypt()</function> 
method.</para></listitem>
       <listitem><para>GMimeCryptoContext's encrypt, decrypt, and verify methods now all take a flags 
argument that can enable additional features (see above examples).</para></listitem>
       <listitem><para><function>g_mime_crypto_context_sign()</function> now takes a boolean 'detach' 
argument that specifies whether or not to generate a detached signature. To get the old behavior, pass TRUE 
as the detach argument.</para></listitem>
       <listitem><para><function>g_mime_crypto_context_decrypt_session()<function> has been merged with 
<function>g_mime_crypto_context_decrypt()</function> and so the decryot method now takes a session_key 
argument that is allowed to be NULL.</para></listitem>
diff --git a/examples/basic-example.c b/examples/basic-example.c
index c5ad1b3..58926d9 100644
--- a/examples/basic-example.c
+++ b/examples/basic-example.c
@@ -148,7 +148,7 @@ verify_foreach_callback (GMimeObject *parent, GMimeObject *part, gpointer user_d
                const char *str;
                int i;
                
-               if (!(signatures = g_mime_multipart_signed_verify (mps, GMIME_VERIFY_FLAGS_NONE, &err))) {
+               if (!(signatures = g_mime_multipart_signed_verify (mps, GMIME_VERIFY_NONE, &err))) {
                        /* an error occured - probably couldn't start gpg? */
                        
                        /* for more information about GError, see:
diff --git a/gmime/gmime-crypto-context.h b/gmime/gmime-crypto-context.h
index de1fa8b..23a3807 100644
--- a/gmime/gmime-crypto-context.h
+++ b/gmime/gmime-crypto-context.h
@@ -78,38 +78,42 @@ typedef GMimeCryptoContext * (* GMimeCryptoContextNewFunc) (void);
 
 /**
  * GMimeDecryptFlags:
- * @GMIME_DECRYPT_FLAGS_NONE: No flags specified.
- * @GMIME_DECRYPT_FLAGS_EXPORT_SESSION_KEY: Export the decryption session-key
+ * @GMIME_DECRYPT_NONE: No flags specified.
+ * @GMIME_DECRYPT_EXPORT_SESSION_KEY: Export the decryption session-key
  *
  * Decryption flags.
  **/
 typedef enum {
-       GMIME_DECRYPT_FLAGS_NONE               = 0,
-       GMIME_DECRYPT_FLAGS_EXPORT_SESSION_KEY = 1 << 0,
+       GMIME_DECRYPT_NONE               = 0,
+       GMIME_DECRYPT_EXPORT_SESSION_KEY = 1 << 0,
 } GMimeDecryptFlags;
 
 
 /**
  * GMimeEncryptFlags:
- * @GMIME_ENCRYPT_FLAGS_NONE: No flags specified.
- * @GMIME_ENCRYPT_FLAGS_ALWAYS_TRUST: Always trust the specified keys.
+ * @GMIME_ENCRYPT_NONE: No flags specified.
+ * @GMIME_ENCRYPT_ALWAYS_TRUST: Always trust the specified keys.
+ * @GMIME_ENCRYPT_NO_COMPRESS: Don't compress the plaintext before encrypting.
+ * @GMIME_ENCRYPT_SYMMETRIC: Encrypt symmetrically.
  *
  * Encryption flags.
  **/
 typedef enum {
-       GMIME_ENCRYPT_FLAGS_NONE         = 0,
-       GMIME_ENCRYPT_FLAGS_ALWAYS_TRUST = 1 << 0,
+       GMIME_ENCRYPT_NONE          = 0,
+       GMIME_ENCRYPT_ALWAYS_TRUST  = 1,
+       GMIME_ENCRYPT_NO_COMPRESS   = 16,
+       GMIME_ENCRYPT_SYMMETRIC     = 32
 } GMimeEncryptFlags;
 
 
 /**
  * GMimeVerifyFlags:
- * @GMIME_VERIFY_FLAGS_NONE: No flags specified.
+ * @GMIME_VERIFY_NONE: No flags specified.
  *
  * Signature verification flags.
  **/
 typedef enum {
-       GMIME_VERIFY_FLAGS_NONE              = 0
+       GMIME_VERIFY_NONE           = 0
 } GMimeVerifyFlags;
 
 
diff --git a/gmime/gmime-gpgme-utils.c b/gmime/gmime-gpgme-utils.c
index 4875f86..dcd8384 100644
--- a/gmime/gmime-gpgme-utils.c
+++ b/gmime/gmime-gpgme-utils.c
@@ -419,16 +419,13 @@ g_mime_gpgme_encrypt (gpgme_ctx_t ctx, gboolean sign, const char *userid,
                      GMimeStream *istream, GMimeStream *ostream,
                      GError **err)
 {
-       gpgme_encrypt_flags_t encrypt_flags = 0;
+       gpgme_encrypt_flags_t encrypt_flags = (gpgme_encrypt_flags_t) flags;
        gpgme_data_t input, output;
        gpgme_error_t error;
        gpgme_key_t *rcpts;
        gpgme_key_t key;
        guint i;
        
-       if (flags & GMIME_ENCRYPT_FLAGS_ALWAYS_TRUST)
-               encrypt_flags |= GPGME_ENCRYPT_ALWAYS_TRUST;
-       
        /* create an array of recipient keys for GpgMe */
        rcpts = g_new0 (gpgme_key_t, recipients->len + 1);
        for (i = 0; i < recipients->len; i++) {
@@ -542,7 +539,7 @@ g_mime_gpgme_decrypt (gpgme_ctx_t ctx, GMimeDecryptFlags flags, const char *sess
        }
        
 #if GPGME_VERSION_NUMBER >= 0x010800
-       if (flags & GMIME_DECRYPT_FLAGS_EXPORT_SESSION_KEY)
+       if (flags & GMIME_DECRYPT_EXPORT_SESSION_KEY)
                gpgme_set_ctx_flag (ctx, "export-session-key", "1");
        
        if (session_key)
@@ -556,7 +553,7 @@ g_mime_gpgme_decrypt (gpgme_ctx_t ctx, GMimeDecryptFlags flags, const char *sess
                error = gpgme_op_decrypt (ctx, input, output);
        
 #if GPGME_VERSION_NUMBER >= 0x010800
-       if (flags & GMIME_DECRYPT_FLAGS_EXPORT_SESSION_KEY)
+       if (flags & GMIME_DECRYPT_EXPORT_SESSION_KEY)
                gpgme_set_ctx_flag (ctx, "export-session-key", "0");
        
        if (session_key)
diff --git a/tests/test-pgp.c b/tests/test-pgp.c
index 5eadc41..c4225da 100644
--- a/tests/test-pgp.c
+++ b/tests/test-pgp.c
@@ -166,7 +166,7 @@ test_encrypt (GMimeCryptoContext *ctx, gboolean sign, GMimeStream *cleartext, GM
        g_ptr_array_add (recipients, "no.user@no.domain");
        
        g_mime_crypto_context_encrypt (ctx, sign, "no.user@no.domain",
-                                      GMIME_ENCRYPT_FLAGS_ALWAYS_TRUST,
+                                      GMIME_ENCRYPT_ALWAYS_TRUST,
                                       recipients, cleartext, ciphertext,
                                       &err);
        
diff --git a/tests/test-pgpmime.c b/tests/test-pgpmime.c
index f71879a..0f9acb5 100644
--- a/tests/test-pgpmime.c
+++ b/tests/test-pgpmime.c
@@ -291,7 +291,7 @@ create_encrypted_message (GMimeCryptoContext *ctx, gboolean sign,
        recipients = g_ptr_array_new ();
        g_ptr_array_add (recipients, "no.user@no.domain");
        mpe = g_mime_multipart_encrypted_encrypt (ctx, (GMimeObject *) part, sign, "no.user@no.domain",
-                                                 GMIME_ENCRYPT_FLAGS_ALWAYS_TRUST, recipients, &err);
+                                                 GMIME_ENCRYPT_ALWAYS_TRUST, recipients, &err);
        g_ptr_array_free (recipients, TRUE);
        g_object_unref (part);
        
@@ -369,7 +369,7 @@ test_multipart_encrypted (GMimeCryptoContext *ctx, gboolean sign,
        mpe = (GMimeMultipartEncrypted *) message->mime_part;
        
        /* okay, now to test our decrypt function... */
-       decrypted = g_mime_multipart_encrypted_decrypt (mpe, GMIME_DECRYPT_FLAGS_EXPORT_SESSION_KEY, 
session_key, &result, &err);
+       decrypted = g_mime_multipart_encrypted_decrypt (mpe, GMIME_DECRYPT_EXPORT_SESSION_KEY, session_key, 
&result, &err);
        if (!decrypted || err != NULL) {
                ex = exception_new ("decryption failed: %s", err->message);
                g_error_free (err);
@@ -540,7 +540,7 @@ test_openpgp_encrypt (gboolean sign)
        original = mime_part->content->stream;
        g_object_ref (original);
        
-       if (!g_mime_part_openpgp_encrypt (mime_part, sign, "no.user@no.domain", 
GMIME_ENCRYPT_FLAGS_ALWAYS_TRUST, rcpts, &err)) {
+       if (!g_mime_part_openpgp_encrypt (mime_part, sign, "no.user@no.domain", GMIME_ENCRYPT_ALWAYS_TRUST, 
rcpts, &err)) {
                ex = exception_new ("encrypting failed: %s", err->message);
                g_ptr_array_free (rcpts, TRUE);
                g_object_unref (mime_part);
diff --git a/tests/test-pkcs7.c b/tests/test-pkcs7.c
index a360a3f..231c959 100644
--- a/tests/test-pkcs7.c
+++ b/tests/test-pkcs7.c
@@ -166,7 +166,7 @@ test_encrypt (GMimeCryptoContext *ctx, GMimeStream *cleartext, GMimeStream *ciph
        recipients = g_ptr_array_new ();
        g_ptr_array_add (recipients, "mimekit example com");
        
-       g_mime_crypto_context_encrypt (ctx, FALSE, NULL, GMIME_ENCRYPT_FLAGS_NONE,
+       g_mime_crypto_context_encrypt (ctx, FALSE, NULL, GMIME_ENCRYPT_NONE,
                                       recipients, cleartext, ciphertext, &err);
        
        g_ptr_array_free (recipients, TRUE);
diff --git a/tests/test-smime.c b/tests/test-smime.c
index 22cd3ee..f59f7d4 100644
--- a/tests/test-smime.c
+++ b/tests/test-smime.c
@@ -351,7 +351,7 @@ test_pkcs7_mime_encrypt (void)
        recipients = g_ptr_array_new ();
        g_ptr_array_add (recipients, "mimekit example com");
        
-       pkcs7_mime = g_mime_application_pkcs7_mime_encrypt ((GMimeObject *) part, 
GMIME_ENCRYPT_FLAGS_ALWAYS_TRUST, recipients, &err);
+       pkcs7_mime = g_mime_application_pkcs7_mime_encrypt ((GMimeObject *) part, GMIME_ENCRYPT_ALWAYS_TRUST, 
recipients, &err);
        g_ptr_array_free (recipients, TRUE);
        g_object_unref (part);
        


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]