[gmime] Improved multipart/encrypted decrypt API



commit afc52c04102a2b04135cc780cca676a555ddb6b7
Author: Jeffrey Stedfast <fejj gnome org>
Date:   Tue Feb 8 09:03:02 2011 -0500

    Improved multipart/encrypted decrypt API
    
    2011-02-08  Jeffrey Stedfast  <fejj novell com>
    
    	* PORTING: Updated docs.
    
    	* mono/GMime.metadata: Fixed up for the new decrypt API.
    
    	* gmime/gmime-message.c (multipart_guess_body): Updated. We can
    	* no
    	longer descend into the decrypted part because it is no longer
    	cached.
    
    	* gmime/gmime-multipart-encrypted.c
    	* (g_mime_multipart_encrypted_decrypt):
    	Now takes a GMimeSignatureValidity argument and no longer caches
    	the decrypted mime part/validity.
    	(g_mime_multipart_encrypted_get_signature_validity): Removed.
    	(g_mime_multipart_encrypted_encrypt): Don't cache the input part
    	as the decrypted part.

 ChangeLog                         |   17 +++++++++++
 PORTING                           |   10 +++++-
 gmime/gmime-message.c             |   14 +--------
 gmime/gmime-multipart-encrypted.c |   54 +++++++------------------------------
 gmime/gmime-multipart-encrypted.h |    5 +---
 gmime/gmime-multipart-signed.c    |    2 +-
 mono/GMime.metadata               |   13 +++++----
 mono/gmime-api.raw                |   11 +++-----
 tests/test-pgpmime.c              |    8 +++--
 tests/test-smime.c                |    8 +++--
 10 files changed, 60 insertions(+), 82 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5e6cd01..eb83515 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2011-02-08  Jeffrey Stedfast  <fejj novell com>
+
+	* PORTING: Updated docs.
+
+	* mono/GMime.metadata: Fixed up for the new decrypt API.
+
+	* gmime/gmime-message.c (multipart_guess_body): Updated. We can no
+	longer descend into the decrypted part because it is no longer
+	cached.
+
+	* gmime/gmime-multipart-encrypted.c (g_mime_multipart_encrypted_decrypt):
+	Now takes a GMimeSignatureValidity argument and no longer caches
+	the decrypted mime part/validity.
+	(g_mime_multipart_encrypted_get_signature_validity): Removed.
+	(g_mime_multipart_encrypted_encrypt): Don't cache the input part
+	as the decrypted part.
+
 2011-01-22  Jeffrey Stedfast  <fejj novell com>
 
 	* gmime/gmime-gpg-context.c (gpg_ctx_parse_signer_info): Parse the
diff --git a/PORTING b/PORTING
index 86627ec..dd160b4 100644
--- a/PORTING
+++ b/PORTING
@@ -54,8 +54,14 @@ Other API changes include:
 - g_mime_crypto_context_encrypt() now takes a digest algorithm
   argument which is used when the 'sign' argument is TRUE.
 
-- g_mime_multipart_encrypted() also now takes a sigest algorithm
-  argument which it passes along to g_mime_crypto_context_encrypt().
+- g_mime_multipart_encrypted_encrypt() also now takes a digest
+  algorithm argument which it passes along to
+  g_mime_crypto_context_encrypt().
+
+- g_mime_multipart_encrypted_decrypt() no longer caches the decrypted
+  part and also now takes a GMimeSignatureValidity** output argument
+  which it sets in place of having to call
+  g_mime_multipart_encrypted_get_signature_validity() afterward.
 
 For convenience, GMime 2.6 source packages include a shell-script to
 aid in porting applications using GMime 2.4 to the 2.6 API. You can
diff --git a/gmime/gmime-message.c b/gmime/gmime-message.c
index 1d2a985..e69ae08 100644
--- a/gmime/gmime-message.c
+++ b/gmime/gmime-message.c
@@ -1523,18 +1523,8 @@ multipart_guess_body (GMimeMultipart *multipart)
 	int count, i;
 	
 	if (GMIME_IS_MULTIPART_ENCRYPTED (multipart)) {
-		/* check if this part has already been decrypted... */
-		if (!(mime_part = ((GMimeMultipartEncrypted *) multipart)->decrypted)) {
-			/* nothing more we can do */
-			return (GMimeObject *) multipart;
-		}
-		
-		if (GMIME_IS_MULTIPART (mime_part))
-			return multipart_guess_body ((GMimeMultipart *) mime_part);
-		else if (GMIME_IS_PART (mime_part) && part_is_textual (mime_part))
-			return mime_part;
-		else
-			return NULL;
+		/* nothing more we can do */
+		return (GMimeObject *) multipart;
 	}
 	
 	type = g_mime_object_get_content_type ((GMimeObject *) multipart);
diff --git a/gmime/gmime-multipart-encrypted.c b/gmime/gmime-multipart-encrypted.c
index 1158348..3b18556 100644
--- a/gmime/gmime-multipart-encrypted.c
+++ b/gmime/gmime-multipart-encrypted.c
@@ -42,7 +42,7 @@
 
 /**
  * SECTION: gmime-multipart-encrypted
- * @title: GMimeMultpartEncrypted
+ * @title: GMimeMultipartEncrypted
  * @short_description: Encrypted MIME multiparts
  * @see_also: #GMimeMultipart
  *
@@ -99,21 +99,12 @@ g_mime_multipart_encrypted_class_init (GMimeMultipartEncryptedClass *klass)
 static void
 g_mime_multipart_encrypted_init (GMimeMultipartEncrypted *mpe, GMimeMultipartEncryptedClass *klass)
 {
-	mpe->decrypted = NULL;
-	mpe->validity = NULL;
+	
 }
 
 static void
 g_mime_multipart_encrypted_finalize (GObject *object)
 {
-	GMimeMultipartEncrypted *mpe = (GMimeMultipartEncrypted *) object;
-	
-	if (mpe->decrypted)
-		g_object_unref (mpe->decrypted);
-	
-	if (mpe->validity)
-		g_mime_signature_validity_free (mpe->validity);
-	
 	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
@@ -145,7 +136,7 @@ g_mime_multipart_encrypted_new (void)
  * g_mime_multipart_encrypted_encrypt:
  * @mpe: multipart/encrypted object
  * @content: MIME part to encrypt
- * @ctx: encryption crypto context
+ * @ctx: encryption context
  * @sign: %TRUE if the content should also be signed or %FALSE otherwise
  * @userid: user id to use for signing (only used if @sign is %TRUE)
  * @hash: digest algorithm to use when signing
@@ -218,9 +209,6 @@ g_mime_multipart_encrypted_encrypt (GMimeMultipartEncrypted *mpe, GMimeObject *c
 	g_object_unref (wrapper);
 	g_object_unref (stream);
 	
-	mpe->decrypted = content;
-	g_object_ref (content);
-	
 	/* construct the encrypted mime part */
 	encrypted_part = g_mime_part_new_with_type ("application", "octet-stream");
 	g_mime_part_set_content_encoding (encrypted_part, GMIME_CONTENT_ENCODING_7BIT);
@@ -248,7 +236,8 @@ g_mime_multipart_encrypted_encrypt (GMimeMultipartEncrypted *mpe, GMimeObject *c
 /**
  * g_mime_multipart_encrypted_decrypt:
  * @mpe: multipart/encrypted object
- * @ctx: decryption crypto context
+ * @ctx: decryption context
+ * @validity: a #GMimeSignatureValidity
  * @err: a #GError
  *
  * Attempts to decrypt the encrypted MIME part contained within the
@@ -264,7 +253,7 @@ g_mime_multipart_encrypted_encrypt (GMimeMultipartEncrypted *mpe, GMimeObject *c
  **/
 GMimeObject *
 g_mime_multipart_encrypted_decrypt (GMimeMultipartEncrypted *mpe, GMimeCryptoContext *ctx,
-				    GError **err)
+				    GMimeSignatureValidity **validity, GError **err)
 {
 	GMimeObject *decrypted, *version, *encrypted;
 	GMimeStream *stream, *ciphertext;
@@ -281,10 +270,8 @@ g_mime_multipart_encrypted_decrypt (GMimeMultipartEncrypted *mpe, GMimeCryptoCon
 	g_return_val_if_fail (GMIME_IS_CRYPTO_CONTEXT (ctx), NULL);
 	g_return_val_if_fail (ctx->encrypt_protocol != NULL, NULL);
 	
-	if (mpe->decrypted) {
-		/* we seem to have already decrypted the part */
-		return mpe->decrypted;
-	}
+	if (validity)
+		*validity = NULL;
 	
 	protocol = g_mime_object_get_content_type_parameter (GMIME_OBJECT (mpe), "protocol");
 	
@@ -365,29 +352,8 @@ g_mime_multipart_encrypted_decrypt (GMimeMultipartEncrypted *mpe, GMimeCryptoCon
 		return NULL;
 	}
 	
-	/* cache the decrypted part */
-	mpe->decrypted = decrypted;
-	mpe->validity = sv;
+	if (validity)
+		*validity = sv;
 	
 	return decrypted;
 }
-
-
-/**
- * g_mime_multipart_encrypted_get_signature_validity:
- * @mpe: a #GMimeMultipartEncrypted
- *
- * Gets the signature validity of the encrypted MIME part.
- *
- * Note: This is only useful after calling
- * g_mime_multipart_encrypted_decrypt().
- *
- * Returns: a #GMimeSignatureValidity.
- **/
-const GMimeSignatureValidity *
-g_mime_multipart_encrypted_get_signature_validity (GMimeMultipartEncrypted *mpe)
-{
-	g_return_val_if_fail (GMIME_IS_MULTIPART_ENCRYPTED (mpe), NULL);
-	
-	return mpe->validity;
-}
diff --git a/gmime/gmime-multipart-encrypted.h b/gmime/gmime-multipart-encrypted.h
index 9960e44..824b706 100644
--- a/gmime/gmime-multipart-encrypted.h
+++ b/gmime/gmime-multipart-encrypted.h
@@ -54,8 +54,6 @@ enum {
 struct _GMimeMultipartEncrypted {
 	GMimeMultipart parent_object;
 	
-	GMimeSignatureValidity *validity;
-	GMimeObject *decrypted;
 };
 
 struct _GMimeMultipartEncryptedClass {
@@ -75,10 +73,9 @@ int g_mime_multipart_encrypted_encrypt (GMimeMultipartEncrypted *mpe, GMimeObjec
 
 GMimeObject *g_mime_multipart_encrypted_decrypt (GMimeMultipartEncrypted *mpe,
 						 GMimeCryptoContext *ctx,
+						 GMimeSignatureValidity **validity,
 						 GError **err);
 
-const GMimeSignatureValidity *g_mime_multipart_encrypted_get_signature_validity (GMimeMultipartEncrypted *mpe);
-
 G_END_DECLS
 
 #endif /* __GMIME_MULTIPART_ENCRYPTED_H__ */
diff --git a/gmime/gmime-multipart-signed.c b/gmime/gmime-multipart-signed.c
index 07f418b..4c9e286 100644
--- a/gmime/gmime-multipart-signed.c
+++ b/gmime/gmime-multipart-signed.c
@@ -42,7 +42,7 @@
 
 /**
  * SECTION: gmime-multipart-signed
- * @title: GMimeMultpartSigned
+ * @title: GMimeMultipartSigned
  * @short_description: Signed MIME multiparts
  * @see_also: #GMimeMultipart
  *
diff --git a/mono/GMime.metadata b/mono/GMime.metadata
index 8ea1487..4a97300 100644
--- a/mono/GMime.metadata
+++ b/mono/GMime.metadata
@@ -30,12 +30,6 @@
   <remove-node path="/api/namespace/struct[ name='Event']"/>
   <remove-node path="/api/namespace/callback[ name='EventCallback']"/>
 
-  <!-- CipherContext -->
-  <remove-node path="/api/namespace/struct[ cname='GMimeSignatureValidity']/field[ cname='signers']"/>
-  <remove-node path="/api/namespace/struct[ cname='GMimeSigner']/field[ cname='next']"/>
-  <remove-node path="/api/namespace/struct[ cname='GMimeSigner']/field[ cname='unused']"/>
-  <remove-node path="/api/namespace/struct[ cname='GMimeSigner']/field[ cname='keyid']"/>
-
   <!-- ContentDisposition -->
   <remove-node path="/api/namespace/object[ cname='GMimeContentDisposition']/field[ cname='param_hash']"/>
   <remove-node path="/api/namespace/object[ cname='GMimeContentDisposition']/field[ cname='params']"/>
@@ -53,6 +47,12 @@
   <remove-node path="/api/namespace/object[ cname='GMimeContentType']/field[ cname='subtype']"/>
   <remove-node path="/api/namespace/object[ cname='GMimeContentType']/field[ cname='type']"/>
 
+  <!-- CryptoContext -->
+  <remove-node path="/api/namespace/struct[ cname='GMimeSignatureValidity']/field[ cname='signers']"/>
+  <remove-node path="/api/namespace/struct[ cname='GMimeSigner']/field[ cname='next']"/>
+  <remove-node path="/api/namespace/struct[ cname='GMimeSigner']/field[ cname='unused']"/>
+  <remove-node path="/api/namespace/struct[ cname='GMimeSigner']/field[ cname='keyid']"/>
+
   <!-- DataWrapper -->
   <attr path="/api/namespace/object[ cname='GMimeDataWrapper']/method[ name='GetStream']" name="name">GetGMimeStream</attr>
   <attr path="/api/namespace/object[ cname='GMimeDataWrapper']/method[ name='SetStream']" name="name">SetGMimeStream</attr>
@@ -223,6 +223,7 @@
   <remove-node path="/api/namespace/object[ cname='GMimeMultipart']/method[ name='GetPart']"/>
 
   <!-- MultipartEncrypted -->
+  <attr path="/api/namespace/object[ cname='GMimeMultipartEncrypted']/method[ name='Decrypt']/*/parameter[ name='validity']" name="pass_as">out</attr>
   
   <!-- MultipartSigned -->
   
diff --git a/mono/gmime-api.raw b/mono/gmime-api.raw
index f7596aa..e082937 100644
--- a/mono/gmime-api.raw
+++ b/mono/gmime-api.raw
@@ -73,6 +73,7 @@
       <member cname="GMIME_SIGNER_ERROR_NO_PUBKEY" name="NoPubkey" value="1 &lt;&lt; 1" />
       <member cname="GMIME_SIGNER_ERROR_EXPKEYSIG" name="Expkeysig" value="1 &lt;&lt; 2" />
       <member cname="GMIME_SIGNER_ERROR_REVKEYSIG" name="Revkeysig" value="1 &lt;&lt; 3" />
+      <member cname="GMIME_SIGNER_ERROR_UNSUPP_ALGO" name="UnsuppAlgo" value="1 &lt;&lt; 4" />
     </enum>
     <enum name="SignerStatus" cname="GMimeSignerStatus" type="enum">
       <member cname="GMIME_SIGNER_STATUS_GOOD" name="Good" />
@@ -1010,12 +1011,11 @@
       </method>
     </object>
     <object name="MultipartEncrypted" cname="GMimeMultipartEncrypted" parent="GMimeMultipart">
-      <field name="Validity" cname="validity" type="GMimeSignatureValidity*" />
-      <field name="Decrypted" cname="decrypted" type="GMimeObject*" />
       <method name="Decrypt" cname="g_mime_multipart_encrypted_decrypt">
         <return-type type="GMimeObject*" />
         <parameters>
           <parameter type="GMimeCryptoContext*" name="ctx" />
+          <parameter type="GMimeSignatureValidity**" name="validity" />
           <parameter type="GError**" name="err" />
         </parameters>
       </method>
@@ -1031,9 +1031,6 @@
           <parameter type="GError**" name="err" />
         </parameters>
       </method>
-      <method name="GetSignatureValidity" cname="g_mime_multipart_encrypted_get_signature_validity">
-        <return-type type="const-GMimeSignatureValidity*" />
-      </method>
       <method name="GetType" cname="g_mime_multipart_encrypted_get_type" shared="true">
         <return-type type="GType" />
       </method>
@@ -2604,9 +2601,9 @@
     <struct name="Signer" cname="GMimeSigner" opaque="true">
       <field name="Next" cname="next" type="GMimeSigner*" access="public" writeable="true" />
       <field name="Status" cname="status" bits="2" type="unsigned int" access="public" writeable="true" />
-      <field name="Errors" cname="errors" bits="4" type="unsigned int" access="public" writeable="true" />
+      <field name="Errors" cname="errors" bits="5" type="unsigned int" access="public" writeable="true" />
       <field name="Trust" cname="trust" bits="3" type="unsigned int" access="public" writeable="true" />
-      <field name="Unused" cname="unused" bits="21" type="unsigned int" access="public" writeable="true" />
+      <field name="Unused" cname="unused" bits="20" type="unsigned int" access="public" writeable="true" />
       <field name="PubkeyAlgo" cname="pubkey_algo" type="GMimeCryptoPubKeyAlgo" access="public" writeable="true" />
       <field name="HashAlgo" cname="hash_algo" type="GMimeCryptoHash" access="public" writeable="true" />
       <field name="IssuerSerial" cname="issuer_serial" type="char*" access="public" writeable="true" />
diff --git a/tests/test-pgpmime.c b/tests/test-pgpmime.c
index cb00547..881043b 100644
--- a/tests/test-pgpmime.c
+++ b/tests/test-pgpmime.c
@@ -260,9 +260,9 @@ test_multipart_signed (GMimeCryptoContext *ctx)
 static void
 test_multipart_encrypted (GMimeCryptoContext *ctx, gboolean sign)
 {
-	const GMimeSignatureValidity *sv;
 	GMimeStream *cleartext, *stream;
 	GMimeMultipartEncrypted *mpe;
+	GMimeSignatureValidity *sv;
 	GMimeDataWrapper *content;
 	GMimeObject *decrypted;
 	GPtrArray *recipients;
@@ -342,15 +342,15 @@ 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, ctx, &err);
+	decrypted = g_mime_multipart_encrypted_decrypt (mpe, ctx, &sv, &err);
 	if (!decrypted || err != NULL) {
 		ex = exception_new ("decryption failed: %s", err->message);
+		g_mime_signature_validity_free (sv);
 		g_object_unref (cleartext);
 		g_error_free (err);
 		throw (ex);
 	}
 	
-	sv = g_mime_multipart_encrypted_get_signature_validity (mpe);
 	v(print_verify_results (sv));
 	
 	if (sign) {
@@ -361,6 +361,8 @@ test_multipart_encrypted (GMimeCryptoContext *ctx, gboolean sign)
 			ex = exception_new ("signature status expected to be NONE");
 	}
 	
+	g_mime_signature_validity_free (sv);
+	
 	if (ex != NULL) {
 		g_object_unref (cleartext);
 		throw (ex);
diff --git a/tests/test-smime.c b/tests/test-smime.c
index 2cb2a0c..fedd7ce 100644
--- a/tests/test-smime.c
+++ b/tests/test-smime.c
@@ -261,9 +261,9 @@ test_multipart_signed (GMimeCryptoContext *ctx)
 static void
 test_multipart_encrypted (GMimeCryptoContext *ctx, gboolean sign)
 {
-	const GMimeSignatureValidity *sv;
 	GMimeStream *cleartext, *stream;
 	GMimeMultipartEncrypted *mpe;
+	GMimeSignatureValidity *sv;
 	GMimeDataWrapper *content;
 	GMimeObject *decrypted;
 	GPtrArray *recipients;
@@ -343,15 +343,15 @@ 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, ctx, &err);
+	decrypted = g_mime_multipart_encrypted_decrypt (mpe, ctx, &sv, &err);
 	if (!decrypted || err != NULL) {
 		ex = exception_new ("decryption failed: %s", err->message);
+		g_mime_signature_validity_free (sv);
 		g_object_unref (cleartext);
 		g_error_free (err);
 		throw (ex);
 	}
 	
-	sv = g_mime_multipart_encrypted_get_signature_validity (mpe);
 	v(print_verify_results (sv));
 	
 	if (sign) {
@@ -362,6 +362,8 @@ test_multipart_encrypted (GMimeCryptoContext *ctx, gboolean sign)
 			ex = exception_new ("signature status expected to be NONE");
 	}
 	
+	g_mime_signature_validity_free (sv);
+	
 	if (ex != NULL) {
 		g_object_unref (cleartext);
 		throw (ex);



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