[gmime] g_mime_crypto_context_import_keys() now returns # of keys imported



commit 8beaf935a444e7d144f313f79877797aceb3fdc0
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date:   Fri Mar 10 15:21:49 2017 -0500

    g_mime_crypto_context_import_keys() now returns # of keys imported

 gmime/gmime-crypto-context.c |    2 +-
 gmime/gmime-crypto-context.h |    4 +---
 gmime/gmime-gpgme-utils.c    |    5 ++++-
 tests/test-pgpmime.c         |   26 +++++++++++++-------------
 4 files changed, 19 insertions(+), 18 deletions(-)
---
diff --git a/gmime/gmime-crypto-context.c b/gmime/gmime-crypto-context.c
index add0592..08ad261 100644
--- a/gmime/gmime-crypto-context.c
+++ b/gmime/gmime-crypto-context.c
@@ -546,7 +546,7 @@ crypto_import_keys (GMimeCryptoContext *ctx, GMimeStream *istream, GError **err)
  * Imports a stream of keys/certificates contained within @istream
  * into the key/certificate database controlled by @ctx.
  *
- * Returns: %0 on success or %-1 on fail.
+ * Returns: the total number of keys imported on success or %-1 on fail.
  **/
 int
 g_mime_crypto_context_import_keys (GMimeCryptoContext *ctx, GMimeStream *istream, GError **err)
diff --git a/gmime/gmime-crypto-context.h b/gmime/gmime-crypto-context.h
index 1d48d58..2ff1d46 100644
--- a/gmime/gmime-crypto-context.h
+++ b/gmime/gmime-crypto-context.h
@@ -105,13 +105,11 @@ typedef enum {
 /**
  * GMimeVerifyFlags:
  * @GMIME_VERIFY_FLAGS_NONE: No flags specified.
- * @GMIME_VERIFY_FLAGS_AUTO_KEY_RETRIEVE: Automatically retrieve keys from a keyserver.
  *
  * Signature verification flags.
  **/
 typedef enum {
-       GMIME_VERIFY_FLAGS_NONE              = 0,
-       GMIME_VERIFY_FLAGS_AUTO_KEY_RETRIEVE = 1 << 0,
+       GMIME_VERIFY_FLAGS_NONE              = 0
 } GMimeVerifyFlags;
 
 
diff --git a/gmime/gmime-gpgme-utils.c b/gmime/gmime-gpgme-utils.c
index 964aea3..20f7005 100644
--- a/gmime/gmime-gpgme-utils.c
+++ b/gmime/gmime-gpgme-utils.c
@@ -574,6 +574,7 @@ g_mime_gpgme_decrypt (gpgme_ctx_t ctx, GMimeDecryptFlags flags, const char *sess
 int
 g_mime_gpgme_import (gpgme_ctx_t ctx, GMimeStream *istream, GError **err)
 {
+       gpgme_import_result_t result;
        gpgme_data_t keydata;
        gpgme_error_t error;
        
@@ -591,7 +592,9 @@ g_mime_gpgme_import (gpgme_ctx_t ctx, GMimeStream *istream, GError **err)
                return -1;
        }
        
-       return 0;
+       result = gpgme_op_import_result (ctx);
+       
+       return result->imported;
 }
 
 int
diff --git a/tests/test-pgpmime.c b/tests/test-pgpmime.c
index cfc7912..4adc982 100644
--- a/tests/test-pgpmime.c
+++ b/tests/test-pgpmime.c
@@ -74,6 +74,7 @@ print_verify_results (GMimeSignatureList *signatures)
        
        status = get_sig_status (signatures);
        
+       fputs ("Overall status: ", stdout);
        if ((status & GMIME_SIGNATURE_STATUS_RED) != 0)
                fputs ("BAD\n", stdout);
        else if ((status & GMIME_SIGNATURE_STATUS_GREEN) != 0)
@@ -135,6 +136,8 @@ print_verify_results (GMimeSignatureList *signatures)
                        fputs ("Key Expired, ", stdout);
                if (sig->status & GMIME_SIGNATURE_STATUS_KEY_REVOKED)
                        fputs ("Key Revoked", stdout);
+               if ((sig->status & ~(GMIME_SIGNATURE_STATUS_GREEN | GMIME_SIGNATURE_STATUS_RED)) == 0)
+                       fputs ("None", stdout);
                fputc ('\n', stdout);
                
                if (i + 1 < count)
@@ -359,6 +362,7 @@ test_multipart_encrypted (GMimeCryptoContext *ctx, gboolean sign,
                ex = exception_new ("No session key returned!");
                throw (ex);
        }
+       
        ret = g_strdup (result->session_key);
 #endif
        
@@ -492,8 +496,10 @@ int main (int argc, char *argv[])
        try {
                create_encrypted_message (ctx, FALSE, &cleartext, &stream);
                session_key = test_multipart_encrypted (ctx, FALSE, cleartext, stream, NULL);
+#if GPGME_VERSION_NUMBER >= 0x010800
                if (testsuite_can_safely_override_session_key (gpg))
                        g_free (test_multipart_encrypted (ctx, FALSE, cleartext, stream, session_key));
+#endif
                testsuite_check_passed ();
        } catch (ex) {
                testsuite_check_failed ("multipart/encrypted failed: %s", ex->message);
@@ -505,34 +511,28 @@ int main (int argc, char *argv[])
        if (stream)
                g_object_unref (stream);
        
-       cleartext = stream = NULL;
-       
-       if (session_key) {
-               memset (session_key, 0, strlen (session_key));
-               g_free (session_key);
-               session_key = NULL;
-       }
+       g_free (session_key);
        
        testsuite_check ("multipart/encrypted+sign");
        try {
                create_encrypted_message (ctx, TRUE, &cleartext, &stream);
                session_key = test_multipart_encrypted (ctx, TRUE, cleartext, stream, NULL);
+#if GPGME_VERSION_NUMBER >= 0x010800
                if (testsuite_can_safely_override_session_key (gpg))
                        g_free (test_multipart_encrypted (ctx, TRUE, cleartext, stream, session_key));
+#endif
                testsuite_check_passed ();
        } catch (ex) {
                testsuite_check_failed ("multipart/encrypted+sign failed: %s", ex->message);
        } finally;
+       
        if (cleartext)
                g_object_unref (cleartext);
+       
        if (stream)
                g_object_unref (stream);
-       cleartext = stream = NULL;
-       if (session_key) {
-               memset (session_key, 0, strlen (session_key));
-               g_free (session_key);
-               session_key = NULL;
-       }
+       
+       g_free (session_key);
        
        g_object_unref (ctx);
        g_free (gpg);


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