[gmime] Gather info about mdc/cipher algorithms used



commit d30d514ed9ead4d450b11ecd8073d6655a35d5ed
Author: Jeffrey Stedfast <fejj gnome org>
Date:   Fri Mar 4 20:53:18 2011 -0500

    Gather info about mdc/cipher algorithms used
    
    2011-03-04  Jeffrey Stedfast  <fejj novell com>
    
    	Implements features requested in bug #641841 and #641320.
    
    	* gmime/gmime-crypto-context.h (GMimeCryptoHash): Reordered to
    	* be
    	identical to gnupg's listing.
    	(GMimeCryptoPubKeyAlgo): Same.
    
    	* gmime/gmime-crypto-context.c
    	* (g_mime_decryption_result_[g,s]et_cipher):
    	New functions to get/set the cipher algorithm used.
    	(g_mime_decryption_result_[g,s]et_mdc): New functions to get/set
    	the mdc digest algorithm used.
    
    	* gmime/gmime-gpg-context.c (gpg_hash_algo): Removed, no longer
    	needed.
    	(gpg_pubkey_algo): Same.
    	(gpg_ctx_parse_status) :Parse the DECRYPTION_INFO status to get
    	the cipher and mdc algorithms used.
    	(gpg_decrypt): Set the cipher and mdc values on the
    	GMimeDecryptionResult.
    
    	* gmime/gmime-pkcs7-context.c (pkcs7_pubkey_algo): Removed, no
    	longer needed.
    	(pkcs7_hash_algo): Same.

 ChangeLog                         |   25 +++++++++
 docs/reference/gmime-sections.txt |    5 ++
 gmime/gmime-crypto-context.c      |   68 +++++++++++++++++++++++++
 gmime/gmime-crypto-context.h      |   98 ++++++++++++++++++++++++++-----------
 gmime/gmime-gpg-context.c         |   70 ++++++++++++---------------
 gmime/gmime-pkcs7-context.c       |   39 +-------------
 mono/gmime-api.raw                |   68 +++++++++++++++++++------
 7 files changed, 253 insertions(+), 120 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index fa94992..6ae59ac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,30 @@
 2011-03-04  Jeffrey Stedfast  <fejj novell com>
 
+	Implements features requested in bug #641841 and #641320.
+
+	* gmime/gmime-crypto-context.h (GMimeCryptoHash): Reordered to be
+	identical to gnupg's listing.
+	(GMimeCryptoPubKeyAlgo): Same.
+
+	* gmime/gmime-crypto-context.c (g_mime_decryption_result_[g,s]et_cipher):
+	New functions to get/set the cipher algorithm used.
+	(g_mime_decryption_result_[g,s]et_mdc): New functions to get/set
+	the mdc digest algorithm used.
+
+	* gmime/gmime-gpg-context.c (gpg_hash_algo): Removed, no longer
+	needed.
+	(gpg_pubkey_algo): Same.
+	(gpg_ctx_parse_status) :Parse the DECRYPTION_INFO status to get
+	the cipher and mdc algorithms used.
+	(gpg_decrypt): Set the cipher and mdc values on the
+	GMimeDecryptionResult.
+
+	* gmime/gmime-pkcs7-context.c (pkcs7_pubkey_algo): Removed, no
+	longer needed.
+	(pkcs7_hash_algo): Same.
+
+2011-03-04  Jeffrey Stedfast  <fejj novell com>
+
 	* gmime/gmime-gpg-context.c (gpg_ctx_parse_signer_info): Make sure
 	to extract the pubkey_algo, hash_algo, sig_class, sig_expires, and
 	return-code values for ERRSIG.
diff --git a/docs/reference/gmime-sections.txt b/docs/reference/gmime-sections.txt
index b1e3073..43a743b 100644
--- a/docs/reference/gmime-sections.txt
+++ b/docs/reference/gmime-sections.txt
@@ -1212,6 +1212,7 @@ g_mime_crypto_recipient_get_key_id
 g_mime_crypto_recipient_set_pubkey_algo
 g_mime_crypto_recipient_get_pubkey_algo
 <SUBSECTION>
+GMimeCryptoCipherAlgo
 GMimeDecryptionResult
 g_mime_decryption_result_new
 g_mime_decryption_result_free
@@ -1219,6 +1220,10 @@ g_mime_decryption_result_set_validity
 g_mime_decryption_result_get_validity
 g_mime_decryption_result_add_recipient
 g_mime_decryption_result_get_recipients
+g_mime_decryption_result_set_cipher
+g_mime_decryption_result_get_cipher
+g_mime_decryption_result_set_mdc
+g_mime_decryption_result_get_mdc
 <SUBSECTION Private>
 g_mime_crypto_context_get_type
 
diff --git a/gmime/gmime-crypto-context.c b/gmime/gmime-crypto-context.c
index 0733821..64e155d 100644
--- a/gmime/gmime-crypto-context.c
+++ b/gmime/gmime-crypto-context.c
@@ -1432,6 +1432,8 @@ g_mime_decryption_result_new (void)
 	GMimeDecryptionResult *result;
 	
 	result = g_slice_new (GMimeDecryptionResult);
+	result->cipher = GMIME_CRYPTO_CIPHER_ALGO_DEFAULT;
+	result->mdc = GMIME_CRYPTO_HASH_DEFAULT;
 	result->recipients = NULL;
 	result->validity = NULL;
 	
@@ -1545,3 +1547,69 @@ g_mime_decryption_result_add_recipient (GMimeDecryptionResult *result, GMimeCryp
 		r->next = recipient;
 	}
 }
+
+
+/**
+ * g_mime_decryption_result_set_cipher:
+ * @result: a #GMimeDecryptionResult
+ * @cipher: a #GMimeCryptoCipherAlgo
+ *
+ * Set the cipher algorithm used.
+ **/
+void
+g_mime_decryption_result_set_cipher (GMimeDecryptionResult *result, GMimeCryptoCipherAlgo cipher)
+{
+	g_return_if_fail (result != NULL);
+	
+	result->cipher = cipher;
+}
+
+
+/**
+ * g_mime_decryption_result_get_cipher:
+ * @result: a #GMimeDecryptionResult
+ *
+ * Get the cipher algorithm used.
+ *
+ * Returns: the cipher algorithm used.
+ **/
+GMimeCryptoCipherAlgo
+g_mime_decryption_result_get_cipher (const GMimeDecryptionResult *result)
+{
+	g_return_val_if_fail (result != NULL, GMIME_CRYPTO_CIPHER_ALGO_DEFAULT);
+	
+	return result->cipher;
+}
+
+
+/**
+ * g_mime_decryption_result_set_mdc:
+ * @result: a #GMimeDecryptionResult
+ * @mdc: a #GMimeCryptoHash
+ *
+ * Set the mdc digest algorithm used.
+ **/
+void
+g_mime_decryption_result_set_mdc (GMimeDecryptionResult *result, GMimeCryptoHash mdc)
+{
+	g_return_if_fail (result != NULL);
+	
+	result->mdc = mdc;
+}
+
+
+/**
+ * g_mime_decryption_result_get_mdc:
+ * @result: a #GMimeDecryptionResult
+ *
+ * Get the mdc digest algorithm used.
+ *
+ * Returns: the mdc digest algorithm used.
+ **/
+GMimeCryptoHash
+g_mime_decryption_result_get_mdc (const GMimeDecryptionResult *result)
+{
+	g_return_val_if_fail (result != NULL, GMIME_CRYPTO_HASH_DEFAULT);
+	
+	return result->mdc;
+}
diff --git a/gmime/gmime-crypto-context.h b/gmime/gmime-crypto-context.h
index f71eb68..b51118f 100644
--- a/gmime/gmime-crypto-context.h
+++ b/gmime/gmime-crypto-context.h
@@ -68,33 +68,33 @@ typedef gboolean (* GMimePasswordRequestFunc) (GMimeCryptoContext *ctx, const ch
 /**
  * GMimeCryptoHash:
  * @GMIME_CRYPTO_HASH_DEFAULT: The default hash algorithm.
- * @GMIME_CRYPTO_HASH_MD2: The MD2 hash algorithm.
  * @GMIME_CRYPTO_HASH_MD5: The MD5 hash algorithm.
  * @GMIME_CRYPTO_HASH_SHA1: The SHA-1 hash algorithm.
- * @GMIME_CRYPTO_HASH_SHA224: The SHA-224 hash algorithm.
- * @GMIME_CRYPTO_HASH_SHA256: The SHA-256 hash algorithm.
- * @GMIME_CRYPTO_HASH_SHA384: The SHA-384 hash algorithm.
- * @GMIME_CRYPTO_HASH_SHA512: The SHA-512 hash algorithm.
  * @GMIME_CRYPTO_HASH_RIPEMD160: The RIPEMD-160 hash algorithm.
+ * @GMIME_CRYPTO_HASH_MD2: The MD2 hash algorithm.
  * @GMIME_CRYPTO_HASH_TIGER192: The TIGER-192 hash algorithm.
  * @GMIME_CRYPTO_HASH_HAVAL5160: The HAVAL-5-160 hash algorithm.
+ * @GMIME_CRYPTO_HASH_SHA256: The SHA-256 hash algorithm.
+ * @GMIME_CRYPTO_HASH_SHA384: The SHA-384 hash algorithm.
+ * @GMIME_CRYPTO_HASH_SHA512: The SHA-512 hash algorithm.
+ * @GMIME_CRYPTO_HASH_SHA224: The SHA-224 hash algorithm.
  * @GMIME_CRYPTO_HASH_MD4: The MD4 hash algorithm.
  *
  * A hash algorithm.
  **/
 typedef enum {
-	GMIME_CRYPTO_HASH_DEFAULT,
-	GMIME_CRYPTO_HASH_MD2,
-	GMIME_CRYPTO_HASH_MD5,
-	GMIME_CRYPTO_HASH_SHA1,
-	GMIME_CRYPTO_HASH_SHA224,
-	GMIME_CRYPTO_HASH_SHA256,
-	GMIME_CRYPTO_HASH_SHA384,
-	GMIME_CRYPTO_HASH_SHA512,
-	GMIME_CRYPTO_HASH_RIPEMD160,
-	GMIME_CRYPTO_HASH_TIGER192,
-	GMIME_CRYPTO_HASH_HAVAL5160,
-	GMIME_CRYPTO_HASH_MD4
+	GMIME_CRYPTO_HASH_DEFAULT     = 0,
+	GMIME_CRYPTO_HASH_MD5         = 1,
+	GMIME_CRYPTO_HASH_SHA1        = 2,
+	GMIME_CRYPTO_HASH_RIPEMD160   = 3,
+	GMIME_CRYPTO_HASH_MD2         = 5,
+	GMIME_CRYPTO_HASH_TIGER192    = 6,
+	GMIME_CRYPTO_HASH_HAVAL5160   = 7,
+	GMIME_CRYPTO_HASH_SHA256      = 8,
+	GMIME_CRYPTO_HASH_SHA384      = 9,
+	GMIME_CRYPTO_HASH_SHA512      = 10,
+	GMIME_CRYPTO_HASH_SHA224      = 11,
+	GMIME_CRYPTO_HASH_MD4         = 301,
 } GMimeCryptoHash;
 
 
@@ -196,20 +196,20 @@ int g_mime_crypto_context_export_keys (GMimeCryptoContext *ctx, GPtrArray *keys,
  * @GMIME_CRYPTO_PUBKEY_ALGO_RSA: The RSA algorithm.
  * @GMIME_CRYPTO_PUBKEY_ALGO_RSA_E: An encryption-only RSA algorithm.
  * @GMIME_CRYPTO_PUBKEY_ALGO_RSA_S: A signature-only RSA algorithm.
- * @GMIME_CRYPTO_PUBKEY_ALGO_ELG: The ElGamal algorithm.
  * @GMIME_CRYPTO_PUBKEY_ALGO_ELG_E: An encryption-only ElGamal algorithm.
  * @GMIME_CRYPTO_PUBKEY_ALGO_DSA: The DSA algorithm.
+ * @GMIME_CRYPTO_PUBKEY_ALGO_ELG: The ElGamal algorithm.
  *
  * A public-key algorithm.
  **/
 typedef enum {
-	GMIME_CRYPTO_PUBKEY_ALGO_DEFAULT,
-	GMIME_CRYPTO_PUBKEY_ALGO_RSA,
-	GMIME_CRYPTO_PUBKEY_ALGO_RSA_E,
-	GMIME_CRYPTO_PUBKEY_ALGO_RSA_S,
-	GMIME_CRYPTO_PUBKEY_ALGO_ELG,
-	GMIME_CRYPTO_PUBKEY_ALGO_ELG_E,
-	GMIME_CRYPTO_PUBKEY_ALGO_DSA
+	GMIME_CRYPTO_PUBKEY_ALGO_DEFAULT  = 0,
+	GMIME_CRYPTO_PUBKEY_ALGO_RSA      = 1,
+	GMIME_CRYPTO_PUBKEY_ALGO_RSA_E    = 2,
+	GMIME_CRYPTO_PUBKEY_ALGO_RSA_S    = 3,
+	GMIME_CRYPTO_PUBKEY_ALGO_ELG_E    = 16,
+	GMIME_CRYPTO_PUBKEY_ALGO_DSA      = 17,
+	GMIME_CRYPTO_PUBKEY_ALGO_ELG      = 20
 } GMimeCryptoPubKeyAlgo;
 
 
@@ -392,8 +392,8 @@ struct _GMimeSignatureValidity {
 GMimeSignatureValidity *g_mime_signature_validity_new (void);
 void g_mime_signature_validity_free (GMimeSignatureValidity *validity);
 
-const char *g_mime_signature_validity_get_details (const GMimeSignatureValidity *validity);
 void g_mime_signature_validity_set_details (GMimeSignatureValidity *validity, const char *details);
+const char *g_mime_signature_validity_get_details (const GMimeSignatureValidity *validity);
 
 const GMimeSigner *g_mime_signature_validity_get_signers (const GMimeSignatureValidity *validity);
 void g_mime_signature_validity_add_signer (GMimeSignatureValidity *validity, GMimeSigner *signer);
@@ -428,26 +428,68 @@ const char *g_mime_crypto_recipient_get_key_id (const GMimeCryptoRecipient *reci
 
 
 /**
+ * GMimeCryptoCipherAlgo:
+ * @GMIME_CRYPTO_CIPHER_ALGO_DEFAULT: The default (or unknown) cipher.
+ * @GMIME_CRYPTO_CIPHER_ALGO_IDEA: The IDEA cipher.
+ * @GMIME_CRYPTO_CIPHER_ALGO_3DES: The 3DES cipher.
+ * @GMIME_CRYPTO_CIPHER_ALGO_CAST5: The CAST5 cipher.
+ * @GMIME_CRYPTO_CIPHER_ALGO_BLOWFISH: The Blowfish cipher.
+ * @GMIME_CRYPTO_CIPHER_ALGO_AES: The AES (aka RIJANDALE) cipher.
+ * @GMIME_CRYPTO_CIPHER_ALGO_AES192: The AES-192 cipher.
+ * @GMIME_CRYPTO_CIPHER_ALGO_AES256: The AES-256 cipher.
+ * @GMIME_CRYPTO_CIPHER_ALGO_TWOFISH: The Twofish cipher.
+ * @GMIME_CRYPTO_CIPHER_ALGO_CAMELLIA128: The Camellia-128 cipher.
+ * @GMIME_CRYPTO_CIPHER_ALGO_CAMELLIA196: The Camellia-196 cipher.
+ * @GMIME_CRYPTO_CIPHER_ALGO_CAMELLIA256: The Camellia-256 cipher.
+ *
+ * A cipher algorithm.
+ **/
+typedef enum {
+	GMIME_CRYPTO_CIPHER_ALGO_DEFAULT     = 0,
+	GMIME_CRYPTO_CIPHER_ALGO_IDEA        = 1,
+	GMIME_CRYPTO_CIPHER_ALGO_3DES        = 2,
+	GMIME_CRYPTO_CIPHER_ALGO_CAST5       = 3,
+	GMIME_CRYPTO_CIPHER_ALGO_BLOWFISH    = 4,
+	GMIME_CRYPTO_CIPHER_ALGO_AES         = 7,
+	GMIME_CRYPTO_CIPHER_ALGO_AES192      = 8,
+	GMIME_CRYPTO_CIPHER_ALGO_AES256      = 9,
+	GMIME_CRYPTO_CIPHER_ALGO_TWOFISH     = 10,
+	GMIME_CRYPTO_CIPHER_ALGO_CAMELLIA128 = 11,
+	GMIME_CRYPTO_CIPHER_ALGO_CAMELLIA196 = 12,
+	GMIME_CRYPTO_CIPHER_ALGO_CAMELLIA256 = 13
+} GMimeCryptoCipherAlgo;
+
+/**
  * GMimeDecryptionResult:
  * @validity: A #GMimeSignatureValidity if signed or %NULL otherwise.
  * @recipients: A list of #GMimeCryptoRecipient structures.
+ * @cipher: The cipher algorithm used to encrypt the stream.
+ * @mdc: The MDC digest algorithm used, if any.
  *
  * A structure containing the results from decrypting an encrypted stream.
  **/
 struct _GMimeDecryptionResult {
 	GMimeSignatureValidity *validity;
 	GMimeCryptoRecipient *recipients;
+	GMimeCryptoCipherAlgo cipher;
+	GMimeCryptoHash mdc;
 };
 
 
 GMimeDecryptionResult *g_mime_decryption_result_new (void);
 void g_mime_decryption_result_free (GMimeDecryptionResult *result);
 
-const GMimeSignatureValidity *g_mime_decryption_result_get_validity (const GMimeDecryptionResult *result);
 void g_mime_decryption_result_set_validity (GMimeDecryptionResult *result, GMimeSignatureValidity *validity);
+const GMimeSignatureValidity *g_mime_decryption_result_get_validity (const GMimeDecryptionResult *result);
 
-const GMimeCryptoRecipient *g_mime_decryption_result_get_recipients (const GMimeDecryptionResult *result);
 void g_mime_decryption_result_add_recipient (GMimeDecryptionResult *result, GMimeCryptoRecipient *recipient);
+const GMimeCryptoRecipient *g_mime_decryption_result_get_recipients (const GMimeDecryptionResult *result);
+
+void g_mime_decryption_result_set_cipher (GMimeDecryptionResult *result, GMimeCryptoCipherAlgo cipher);
+GMimeCryptoCipherAlgo g_mime_decryption_result_get_cipher (const GMimeDecryptionResult *result);
+
+void g_mime_decryption_result_set_mdc (GMimeDecryptionResult *result, GMimeCryptoHash mdc);
+GMimeCryptoHash g_mime_decryption_result_get_mdc (const GMimeDecryptionResult *result);
 
 G_END_DECLS
 
diff --git a/gmime/gmime-gpg-context.c b/gmime/gmime-gpg-context.c
index be39d2a..2d52478 100644
--- a/gmime/gmime-gpg-context.c
+++ b/gmime/gmime-gpg-context.c
@@ -279,6 +279,7 @@ struct _GpgCtx {
 	
 	char *userid;
 	GPtrArray *recipients;
+	GMimeCryptoCipherAlgo cipher;
 	GMimeCryptoHash hash;
 	
 	int stdin_fd;
@@ -344,6 +345,7 @@ gpg_ctx_new (GMimeGpgContext *ctx)
 	
 	gpg->userid = NULL;
 	gpg->recipients = NULL;
+	gpg->cipher = GMIME_CRYPTO_CIPHER_ALGO_DEFAULT;
 	gpg->hash = GMIME_CRYPTO_HASH_DEFAULT;
 	gpg->always_trust = FALSE;
 	gpg->armor = FALSE;
@@ -574,39 +576,6 @@ gpg_hash_str (GMimeCryptoHash hash)
 	}
 }
 
-static GMimeCryptoPubKeyAlgo
-gpg_pubkey_algo (unsigned long id)
-{
-	switch (id) {
-	case 1: return GMIME_CRYPTO_PUBKEY_ALGO_RSA;
-	case 2: return GMIME_CRYPTO_PUBKEY_ALGO_RSA_E;
-	case 3: return GMIME_CRYPTO_PUBKEY_ALGO_RSA_S;
-	case 16: return GMIME_CRYPTO_PUBKEY_ALGO_ELG_E;
-	case 17: return GMIME_CRYPTO_PUBKEY_ALGO_DSA;
-	case 20: return GMIME_CRYPTO_PUBKEY_ALGO_ELG;
-	default: return GMIME_CRYPTO_PUBKEY_ALGO_DEFAULT;
-	}
-}
-
-static GMimeCryptoHash
-gpg_hash_algo (unsigned long id)
-{
-	switch (id) {
-	case 1: return GMIME_CRYPTO_HASH_MD5;
-	case 2: return GMIME_CRYPTO_HASH_SHA1;
-	case 3:	return GMIME_CRYPTO_HASH_RIPEMD160;
-	case 5: return GMIME_CRYPTO_HASH_MD2;
-	case 6: return GMIME_CRYPTO_HASH_TIGER192;
-	case 7: return GMIME_CRYPTO_HASH_HAVAL5160;
-	case 8: return GMIME_CRYPTO_HASH_SHA256;
-	case 9: return GMIME_CRYPTO_HASH_SHA384;
-	case 10: return GMIME_CRYPTO_HASH_SHA512;
-	case 11: return GMIME_CRYPTO_HASH_SHA224;
-	case 301: return GMIME_CRYPTO_HASH_MD4;
-	default: return GMIME_CRYPTO_HASH_DEFAULT;
-	}
-}
-
 static char **
 gpg_ctx_get_argv (struct _GpgCtx *gpg, int status_fd, int secret_fd, char ***strv)
 {
@@ -904,14 +873,14 @@ gpg_ctx_parse_signer_info (struct _GpgCtx *gpg, char *status)
 		status = next_token (status, &signer->keyid);
 		
 		/* the second token is the public-key algorithm id */
-		signer->pubkey_algo = gpg_pubkey_algo (strtoul (status, &inend, 10));
+		signer->pubkey_algo = strtoul (status, &inend, 10);
 		if (inend == status || *inend != ' ')
 			return;
 		
 		status = inend + 1;
 		
 		/* the third token is the hash algorithm id */
-		signer->hash_algo = gpg_hash_algo (strtoul (status, &inend, 10));
+		signer->hash_algo = strtoul (status, &inend, 10);
 		if (inend == status || *inend != ' ')
 			return;
 		
@@ -992,14 +961,14 @@ gpg_ctx_parse_signer_info (struct _GpgCtx *gpg, char *status)
 		status = next_token (status, NULL);
 		
 		/* the seventh token is the public-key algorithm id */
-		signer->pubkey_algo = gpg_pubkey_algo (strtoul (status, &inend, 10));
+		signer->pubkey_algo = strtoul (status, &inend, 10);
 		if (inend == status || *inend != ' ')
 			return;
 		
 		status = inend + 1;
 		
 		/* the eighth token is the hash algorithm id */
-		signer->hash_algo = gpg_hash_algo (strtoul (status, &inend, 10));
+		signer->hash_algo = strtoul (status, &inend, 10);
 		if (inend == status || *inend != ' ')
 			return;
 		
@@ -1248,7 +1217,7 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, GError **err)
 			status = next_token (status, NULL);
 			
 			/* this token is the hash algorithm used */
-			gpg->hash = gpg_hash_algo (strtoul (status, NULL, 10));
+			gpg->hash = strtoul (status, NULL, 10);
 			break;
 		case GPG_CTX_MODE_VERIFY:
 			gpg_ctx_parse_signer_info (gpg, status);
@@ -1268,6 +1237,23 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, GError **err)
 		case GPG_CTX_MODE_DECRYPT:
 			if (!strncmp (status, "BEGIN_DECRYPTION", 16)) {
 				/* nothing to do... but we know to expect data on stdout soon */
+			} else if (!strncmp (status, "DECRYPTION_INFO ", 16)) {
+				/* new feature added in gnupg-2.1.x which gives mdc and cipher algorithms used */
+				status += 16;
+				
+				/* first token is the mdc algorithm (or 0 if not used) */
+				gpg->hash = strtoul (status, &inend, 10);
+				if (inend == status || *inend != ' ')
+					return;
+				
+				status = inend + 1;
+				
+				/* second token is the cipher algorithm */
+				gpg->cipher = strtoul (status, &inend, 10);
+			} else if (!strncmp (status, "DECRYPTION_OKAY", 15)) {
+				/* nothing to do... but good to know gpg decrypted the data successfully */
+			} else if (!strncmp (status, "DECRYPTION_FAILED", 17)) {
+				/* nothing to do... but we know gpg failed to decrypt :-( */
 			} else if (!strncmp (status, "END_DECRYPTION", 14)) {
 				/* nothing to do, but we know we're done */
 			} else if (!strncmp (status, "ENC_TO ", 7)) {
@@ -1282,13 +1268,17 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, GError **err)
 				status = next_token (status, &recipient->keyid);
 				
 				/* second token is the recipient's pubkey algo */
-				recipient->pubkey_algo = gpg_pubkey_algo (strtoul (status, &inend, 10));
+				recipient->pubkey_algo = strtoul (status, &inend, 10);
 				if (inend == status || *inend != ' ')
 					return;
 				
 				status = inend + 1;
 				
 				/* third token is a dummy value which is always '0' */
+			} else if (!strncmp (status, "GOODMDC", 7)) {
+				/* nothing to do... we'll grab the MDC used in DECRYPTION_INFO */
+			} else if (!strncmp (status, "BADMDC", 6)) {
+				/* nothing to do, this will only be sent after DECRYPTION_FAILED */
 			} else {
 				gpg_ctx_parse_signer_info (gpg, status);
 			}
@@ -1988,6 +1978,8 @@ gpg_decrypt (GMimeCryptoContext *context, GMimeStream *istream,
 	g_mime_signature_validity_set_details (result->validity, diagnostics);
 	result->validity->signers = gpg->signers;
 	result->recipients = gpg->encrypted_to;
+	result->cipher = gpg->cipher;
+	result->mdc = gpg->hash;
 	gpg->encrypted_to = NULL;
 	gpg->signers = NULL;
 	
diff --git a/gmime/gmime-pkcs7-context.c b/gmime/gmime-pkcs7-context.c
index c45dc0a..e0d7850 100644
--- a/gmime/gmime-pkcs7-context.c
+++ b/gmime/gmime-pkcs7-context.c
@@ -503,39 +503,6 @@ pkcs7_trust (gpgme_validity_t trust)
 	}
 }
 
-static GMimeCryptoPubKeyAlgo
-pkcs7_pubkey_algo (id)
-{
-	switch (id) {
-	case GPGME_PK_RSA: return GMIME_CRYPTO_PUBKEY_ALGO_RSA;
-	case GPGME_PK_RSA_E: return GMIME_CRYPTO_PUBKEY_ALGO_RSA_E;
-	case GPGME_PK_RSA_S: return GMIME_CRYPTO_PUBKEY_ALGO_RSA_S;
-	case GPGME_PK_ELG_E: return GMIME_CRYPTO_PUBKEY_ALGO_ELG_E;
-	case GPGME_PK_DSA: return GMIME_CRYPTO_PUBKEY_ALGO_DSA;
-	case GPGME_PK_ELG: return GMIME_CRYPTO_PUBKEY_ALGO_ELG;
-	default: return GMIME_CRYPTO_PUBKEY_ALGO_DEFAULT;
-	}
-}
-
-static GMimeCryptoHash
-pkcs7_hash_algo (gpgme_hash_algo_t id)
-{
-	switch (id) {
-	case GPGME_MD_NONE: return GMIME_CRYPTO_HASH_DEFAULT;
-	case GPGME_MD_MD5: return GMIME_CRYPTO_HASH_MD5;
-	case GPGME_MD_SHA1: return GMIME_CRYPTO_HASH_SHA1;
-	case GPGME_MD_RMD160: return GMIME_CRYPTO_HASH_RIPEMD160;
-	case GPGME_MD_MD2: return GMIME_CRYPTO_HASH_MD2;
-	case GPGME_MD_TIGER: return GMIME_CRYPTO_HASH_TIGER192;
-	case GPGME_MD_HAVAL: return GMIME_CRYPTO_HASH_HAVAL5160;
-	case GPGME_MD_SHA256: return GMIME_CRYPTO_HASH_SHA256;
-	case GPGME_MD_SHA384: return GMIME_CRYPTO_HASH_SHA384;
-	case GPGME_MD_SHA512: return GMIME_CRYPTO_HASH_SHA512;
-	case GPGME_MD_MD4: return GMIME_CRYPTO_HASH_MD4;
-	default: return GMIME_CRYPTO_HASH_DEFAULT;
-	}
-}
-
 static GMimeSignatureValidity *
 pkcs7_get_validity (Pkcs7Ctx *pkcs7, gboolean verify)
 {
@@ -566,8 +533,8 @@ pkcs7_get_validity (Pkcs7Ctx *pkcs7, gboolean verify)
 		signers->next = signer;
 		signers = signer;
 		
-		g_mime_signer_set_pubkey_algo (signer, pkcs7_pubkey_algo (sig->pubkey_algo));
-		g_mime_signer_set_hash_algo (signer, pkcs7_hash_algo (sig->hash_algo));
+		g_mime_signer_set_pubkey_algo (signer, sig->pubkey_algo);
+		g_mime_signer_set_hash_algo (signer, sig->hash_algo);
 		g_mime_signer_set_sig_expires (signer, sig->exp_timestamp);
 		g_mime_signer_set_sig_created (signer, sig->timestamp);
 		g_mime_signer_set_fingerprint (signer, sig->fpr);
@@ -800,7 +767,7 @@ pkcs7_get_decrypt_result (Pkcs7Ctx *pkcs7)
 		recipients->next = recipient;
 		recipients = recipient;
 		
-		g_mime_crypto_recipient_set_pubkey_algo (recipient, pkcs7_pubkey_algo (recip->pubkey_algo));
+		g_mime_crypto_recipient_set_pubkey_algo (recipient, recip->pubkey_algo);
 		g_mime_crypto_recipient_set_key_id (recipient, recip->keyid);
 		
 		recip = recip->next;
diff --git a/mono/gmime-api.raw b/mono/gmime-api.raw
index ef4e918..97055f3 100644
--- a/mono/gmime-api.raw
+++ b/mono/gmime-api.raw
@@ -16,28 +16,42 @@
       <member cname="GMIME_CONTENT_ENCODING_QUOTEDPRINTABLE" name="Quotedprintable" />
       <member cname="GMIME_CONTENT_ENCODING_UUENCODE" name="Uuencode" />
     </enum>
+    <enum name="CryptoCipherAlgo" cname="GMimeCryptoCipherAlgo" type="enum">
+      <member cname="GMIME_CRYPTO_CIPHER_ALGO_DEFAULT" name="Default" />
+      <member cname="GMIME_CRYPTO_CIPHER_ALGO_IDEA" name="Idea" value="1" />
+      <member cname="GMIME_CRYPTO_CIPHER_ALGO_3DES" name="ThreeDes" value="2" />
+      <member cname="GMIME_CRYPTO_CIPHER_ALGO_CAST5" name="Cast5" value="3" />
+      <member cname="GMIME_CRYPTO_CIPHER_ALGO_BLOWFISH" name="Blowfish" value="4" />
+      <member cname="GMIME_CRYPTO_CIPHER_ALGO_AES" name="Aes" value="7" />
+      <member cname="GMIME_CRYPTO_CIPHER_ALGO_AES192" name="Aes192" value="8" />
+      <member cname="GMIME_CRYPTO_CIPHER_ALGO_AES256" name="Aes256" value="9" />
+      <member cname="GMIME_CRYPTO_CIPHER_ALGO_TWOFISH" name="Twofish" value="10" />
+      <member cname="GMIME_CRYPTO_CIPHER_ALGO_CAMELLIA128" name="Camellia128" value="11" />
+      <member cname="GMIME_CRYPTO_CIPHER_ALGO_CAMELLIA196" name="Camellia196" value="12" />
+      <member cname="GMIME_CRYPTO_CIPHER_ALGO_CAMELLIA256" name="Camellia256" value="13" />
+    </enum>
     <enum name="CryptoHash" cname="GMimeCryptoHash" type="enum">
       <member cname="GMIME_CRYPTO_HASH_DEFAULT" name="Default" />
-      <member cname="GMIME_CRYPTO_HASH_MD2" name="Md2" />
-      <member cname="GMIME_CRYPTO_HASH_MD5" name="Md5" />
-      <member cname="GMIME_CRYPTO_HASH_SHA1" name="Sha1" />
-      <member cname="GMIME_CRYPTO_HASH_SHA224" name="Sha224" />
-      <member cname="GMIME_CRYPTO_HASH_SHA256" name="Sha256" />
-      <member cname="GMIME_CRYPTO_HASH_SHA384" name="Sha384" />
-      <member cname="GMIME_CRYPTO_HASH_SHA512" name="Sha512" />
-      <member cname="GMIME_CRYPTO_HASH_RIPEMD160" name="Ripemd160" />
-      <member cname="GMIME_CRYPTO_HASH_TIGER192" name="Tiger192" />
-      <member cname="GMIME_CRYPTO_HASH_HAVAL5160" name="Haval5160" />
-      <member cname="GMIME_CRYPTO_HASH_MD4" name="Md4" />
+      <member cname="GMIME_CRYPTO_HASH_MD5" name="Md5" value="1" />
+      <member cname="GMIME_CRYPTO_HASH_SHA1" name="Sha1" value="2" />
+      <member cname="GMIME_CRYPTO_HASH_RIPEMD160" name="Ripemd160" value="3" />
+      <member cname="GMIME_CRYPTO_HASH_MD2" name="Md2" value="5" />
+      <member cname="GMIME_CRYPTO_HASH_TIGER192" name="Tiger192" value="6" />
+      <member cname="GMIME_CRYPTO_HASH_HAVAL5160" name="Haval5160" value="7" />
+      <member cname="GMIME_CRYPTO_HASH_SHA256" name="Sha256" value="8" />
+      <member cname="GMIME_CRYPTO_HASH_SHA384" name="Sha384" value="9" />
+      <member cname="GMIME_CRYPTO_HASH_SHA512" name="Sha512" value="10" />
+      <member cname="GMIME_CRYPTO_HASH_SHA224" name="Sha224" value="11" />
+      <member cname="GMIME_CRYPTO_HASH_MD4" name="Md4" value="301" />
     </enum>
     <enum name="CryptoPubKeyAlgo" cname="GMimeCryptoPubKeyAlgo" type="enum">
       <member cname="GMIME_CRYPTO_PUBKEY_ALGO_DEFAULT" name="Default" />
-      <member cname="GMIME_CRYPTO_PUBKEY_ALGO_RSA" name="Rsa" />
-      <member cname="GMIME_CRYPTO_PUBKEY_ALGO_RSA_E" name="RsaE" />
-      <member cname="GMIME_CRYPTO_PUBKEY_ALGO_RSA_S" name="RsaS" />
-      <member cname="GMIME_CRYPTO_PUBKEY_ALGO_ELG" name="Elg" />
-      <member cname="GMIME_CRYPTO_PUBKEY_ALGO_ELG_E" name="ElgE" />
-      <member cname="GMIME_CRYPTO_PUBKEY_ALGO_DSA" name="Dsa" />
+      <member cname="GMIME_CRYPTO_PUBKEY_ALGO_RSA" name="Rsa" value="1" />
+      <member cname="GMIME_CRYPTO_PUBKEY_ALGO_RSA_E" name="RsaE" value="2" />
+      <member cname="GMIME_CRYPTO_PUBKEY_ALGO_RSA_S" name="RsaS" value="3" />
+      <member cname="GMIME_CRYPTO_PUBKEY_ALGO_ELG_E" name="ElgE" value="16" />
+      <member cname="GMIME_CRYPTO_PUBKEY_ALGO_DSA" name="Dsa" value="17" />
+      <member cname="GMIME_CRYPTO_PUBKEY_ALGO_ELG" name="Elg" value="20" />
     </enum>
     <enum name="EncodingConstraint" cname="GMimeEncodingConstraint" type="enum">
       <member cname="GMIME_ENCODING_CONSTRAINT_7BIT" name="7Bit" />
@@ -2271,6 +2285,8 @@
     <struct name="DecryptionResult" cname="GMimeDecryptionResult" opaque="true">
       <field name="Validity" cname="validity" type="GMimeSignatureValidity*" access="public" writeable="true" />
       <field name="Recipients" cname="recipients" type="GMimeCryptoRecipient*" access="public" writeable="true" />
+      <field name="Cipher" cname="cipher" type="GMimeCryptoCipherAlgo" access="public" writeable="true" />
+      <field name="Mdc" cname="mdc" type="GMimeCryptoHash" access="public" writeable="true" />
       <method name="AddRecipient" cname="g_mime_decryption_result_add_recipient">
         <return-type type="void" />
         <parameters>
@@ -2280,6 +2296,12 @@
       <method name="Free" cname="g_mime_decryption_result_free">
         <return-type type="void" />
       </method>
+      <method name="GetCipher" cname="g_mime_decryption_result_get_cipher">
+        <return-type type="GMimeCryptoCipherAlgo" />
+      </method>
+      <method name="GetMdc" cname="g_mime_decryption_result_get_mdc">
+        <return-type type="GMimeCryptoHash" />
+      </method>
       <method name="GetRecipients" cname="g_mime_decryption_result_get_recipients">
         <return-type type="const-GMimeCryptoRecipient*" />
       </method>
@@ -2287,6 +2309,18 @@
         <return-type type="const-GMimeSignatureValidity*" />
       </method>
       <constructor cname="g_mime_decryption_result_new" />
+      <method name="SetCipher" cname="g_mime_decryption_result_set_cipher">
+        <return-type type="void" />
+        <parameters>
+          <parameter type="GMimeCryptoCipherAlgo" name="cipher" />
+        </parameters>
+      </method>
+      <method name="SetMdc" cname="g_mime_decryption_result_set_mdc">
+        <return-type type="void" />
+        <parameters>
+          <parameter type="GMimeCryptoHash" name="mdc" />
+        </parameters>
+      </method>
       <method name="SetValidity" cname="g_mime_decryption_result_set_validity">
         <return-type type="void" />
         <parameters>



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