[gmime] Try and get pkcs7 ctx stuff working



commit 69b95a805ba1a0ca24d62b56e78162b761ba75c9
Author: Jeffrey Stedfast <fejj gnome org>
Date:   Thu Mar 3 10:23:10 2011 -0500

    Try and get pkcs7 ctx stuff working
    
    2011-03-03  Jeffrey Stedfast  <fejj novell com>
    
    	* gmime/gmime-pkcs7-context.c (pkcs7_stream_seek): Added.
    
    	* gmime/gmime.c (g_mime_init): Initialize gpgme.

 ChangeLog                   |    6 ++++++
 gmime/gmime-pkcs7-context.c |   20 +++++++++++++++++++-
 gmime/gmime.c               |    9 +++++++++
 tests/test-pkcs7.c          |   16 +++++++++-------
 tests/test-smime.c          |    6 +++---
 5 files changed, 46 insertions(+), 11 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2dadc69..37d898b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2011-03-03  Jeffrey Stedfast  <fejj novell com>
+
+	* gmime/gmime-pkcs7-context.c (pkcs7_stream_seek): Added.
+
+	* gmime/gmime.c (g_mime_init): Initialize gpgme.
+
 2011-02-08  Jeffrey Stedfast  <fejj novell com>
 
 	Implements feature request in bug #635663.
diff --git a/gmime/gmime-pkcs7-context.c b/gmime/gmime-pkcs7-context.c
index 22a02b5..932fc5a 100644
--- a/gmime/gmime-pkcs7-context.c
+++ b/gmime/gmime-pkcs7-context.c
@@ -271,25 +271,42 @@ pkcs7_passphrase_cb (void *hook, const char *uid_hint, const char *passphrase_in
 static ssize_t
 pkcs7_stream_read (void *stream, void *buffer, size_t size)
 {
+	//printf ("reading...\n"); fflush (stdout);
 	return g_mime_stream_read ((GMimeStream *) stream, (char *) buffer, size);
 }
 
 static ssize_t
 pkcs7_stream_write (void *stream, const void *buffer, size_t size)
 {
+	//printf ("writing...\n"); fflush (stdout);
 	return g_mime_stream_write ((GMimeStream *) stream, (const char *) buffer, size);
 }
 
+static off_t
+pkcs7_stream_seek (void *stream, off_t offset, int whence)
+{
+	//printf ("seeking...\n"); fflush (stdout);
+	switch (whence) {
+	case SEEK_SET:
+		return (off_t) g_mime_stream_seek ((GMimeStream *) stream, (gint64) offset, GMIME_STREAM_SEEK_SET);
+	case SEEK_CUR:
+		return (off_t) g_mime_stream_seek ((GMimeStream *) stream, (gint64) offset, GMIME_STREAM_SEEK_CUR);
+	case SEEK_END:
+		return (off_t) g_mime_stream_seek ((GMimeStream *) stream, (gint64) offset, GMIME_STREAM_SEEK_END);
+	}
+}
+
 static void
 pkcs7_stream_free (void *stream)
 {
 	/* no-op */
+	//printf ("releasing stream handle\n");
 }
 
 static struct gpgme_data_cbs pkcs7_stream_funcs = {
 	pkcs7_stream_read,
 	pkcs7_stream_write,
-	NULL,
+	pkcs7_stream_seek,
 	pkcs7_stream_free
 };
 
@@ -799,6 +816,7 @@ pkcs7_import_keys (GMimeCryptoContext *context, GMimeStream *istream, GError **e
 	
 	/* import the key(s) */
 	if ((error = gpgme_op_import (pkcs7->ctx, keydata)) != GPG_ERR_NO_ERROR) {
+		//printf ("import error (%d): %s\n", error & GPG_ERR_CODE_MASK, gpg_strerror (error));
 		g_set_error (err, GMIME_GPGME_ERROR, error, _("Could not import key data"));
 		gpgme_data_release (keydata);
 		return -1;
diff --git a/gmime/gmime.c b/gmime/gmime.c
index 29ca556..e0f23f6 100644
--- a/gmime/gmime.c
+++ b/gmime/gmime.c
@@ -25,6 +25,10 @@
 
 #include <time.h>
 
+#ifdef ENABLE_SMIME
+#include <gpgme.h>
+#endif
+
 #include "gmime.h"
 
 
@@ -107,6 +111,11 @@ g_mime_init (guint32 flags)
 	
 	g_mime_iconv_init ();
 	
+#ifdef ENABLE_SMIME
+	/* gpgme_check_version() initializes GpgMe */
+	gpgme_check_version (NULL);
+#endif /* ENABLE_SMIME */
+	
 	gmime_gpgme_error_quark = g_quark_from_static_string ("gmime-gpgme");
 	gmime_error_quark = g_quark_from_static_string ("gmime");
 	
diff --git a/tests/test-pkcs7.c b/tests/test-pkcs7.c
index 21fcb9a..8940564 100644
--- a/tests/test-pkcs7.c
+++ b/tests/test-pkcs7.c
@@ -71,7 +71,7 @@ test_sign (GMimeCryptoContext *ctx, GMimeStream *cleartext, GMimeStream *ciphert
 	Exception *ex;
 	int rv;
 	
-	rv = g_mime_crypto_context_sign (ctx, "no user no domain",
+	rv = g_mime_crypto_context_sign (ctx, "alice example net",
 					 GMIME_CRYPTO_HASH_SHA256,
 					 cleartext, ciphertext, &err);
 	
@@ -119,9 +119,9 @@ test_encrypt (GMimeCryptoContext *ctx, gboolean sign, GMimeStream *cleartext, GM
 	Exception *ex;
 	
 	recipients = g_ptr_array_new ();
-	g_ptr_array_add (recipients, "no user no domain");
+	g_ptr_array_add (recipients, "alice example net");
 	
-	g_mime_crypto_context_encrypt (ctx, sign, "no user no domain",
+	g_mime_crypto_context_encrypt (ctx, sign, "alice example net",
 				       GMIME_CRYPTO_HASH_SHA256, recipients,
 				       cleartext, ciphertext, &err);
 	
@@ -205,7 +205,7 @@ test_export (GMimeCryptoContext *ctx, const char *path)
 	g_object_unref (ostream);
 	
 	keys = g_ptr_array_new ();
-	g_ptr_array_add (keys, "no user no domain");
+	g_ptr_array_add (keys, "alice example net");
 	
 	ostream = g_mime_stream_mem_new ();
 	
@@ -306,11 +306,13 @@ int main (int argc, char **argv)
 	
 	testsuite_check ("GMimePkcs7Context::import");
 	try {
-		key = g_build_filename (datadir, "gmime-cert.p7", NULL);
+		key = g_build_filename (datadir, "alice.pem", NULL);
+		//printf ("importing key: %s\n", key);
 		import_key (ctx, key);
 		g_free (key);
 		
-		key = g_build_filename (datadir, "gmime-cert.p12", NULL);
+		key = g_build_filename (datadir, "alice.p12", NULL);
+		//printf ("importing key: %s\n", key);
 		import_key (ctx, key);
 		g_free (key);
 		
@@ -320,7 +322,7 @@ int main (int argc, char **argv)
 		return EXIT_FAILURE;
 	} finally;
 	
-	key = g_build_filename (datadir, "gmime-cert.p7", NULL);
+	key = g_build_filename (datadir, "alice.pem", NULL);
 	testsuite_check ("GMimePkcs7Context::export");
 	try {
 		test_export (ctx, key);
diff --git a/tests/test-smime.c b/tests/test-smime.c
index fedd7ce..b1a088f 100644
--- a/tests/test-smime.c
+++ b/tests/test-smime.c
@@ -200,7 +200,7 @@ test_multipart_signed (GMimeCryptoContext *ctx)
 	mps = g_mime_multipart_signed_new ();
 	
 	/* sign the part */
-	g_mime_multipart_signed_sign (mps, GMIME_OBJECT (part), ctx, "no user no domain",
+	g_mime_multipart_signed_sign (mps, GMIME_OBJECT (part), ctx, "alice example net",
 				      GMIME_CRYPTO_HASH_SHA1, &err);
 	g_object_unref (part);
 	
@@ -296,9 +296,9 @@ test_multipart_encrypted (GMimeCryptoContext *ctx, gboolean sign)
 	
 	/* encrypt the part */
 	recipients = g_ptr_array_new ();
-	g_ptr_array_add (recipients, "no user no domain");
+	g_ptr_array_add (recipients, "alice example net");
 	g_mime_multipart_encrypted_encrypt (mpe, GMIME_OBJECT (part), ctx, sign,
-					    "no user no domain", GMIME_CRYPTO_HASH_SHA256,
+					    "alice example net", GMIME_CRYPTO_HASH_SHA256,
 					    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]