gmime r1345 - in trunk: . gmime tests
- From: fejj svn gnome org
- To: svn-commits-list gnome org
- Subject: gmime r1345 - in trunk: . gmime tests
- Date: Sat, 7 Jun 2008 22:27:24 +0000 (UTC)
Author: fejj
Date: Sat Jun 7 22:27:23 2008
New Revision: 1345
URL: http://svn.gnome.org/viewvc/gmime?rev=1345&view=rev
Log:
2008-06-07 Jeffrey Stedfast <fejj novell com>
* gmime/gmime-multipart-signed.c (g_mime_multipart_signed_sign):
Use the GMimeCipherHash returned from g_mime_cipher_context_sign()
to create the micalg parameter value - this way if the requested
hash was DEFAULT, we set the micalg to the proper value.
* gmime/gmime-gpg-context.c (gpg_ctx_parse_status): Parse which
hash algorithm was actually used by gpg.
(gpg_hash_str): Updated to return strings for the new SHA
algorithms added this past week.
(gpg_sign): Return the hash algorithm actually used.
* gmime/gmime-cipher-context.c (g_mime_cipher_context_sign): This
method now returns -1 on fail or the GMimeCipherHash on success.
Modified:
trunk/ChangeLog
trunk/gmime/gmime-cipher-context.c
trunk/gmime/gmime-gpg-context.c
trunk/gmime/gmime-multipart-signed.c
trunk/tests/test-pgp.c
Modified: trunk/gmime/gmime-cipher-context.c
==============================================================================
--- trunk/gmime/gmime-cipher-context.c (original)
+++ trunk/gmime/gmime-cipher-context.c Sat Jun 7 22:27:23 2008
@@ -207,7 +207,8 @@
*
* Signs the input stream and writes the resulting signature to the output stream.
*
- * Returns: %0 on success or %-1 on fail.
+ * Returns: the #GMimeCipherHash used on success (useful if @hash is
+ * specified as #GMIME_CIPHER_HASH_DEFAULT) or %-1 on fail.
**/
int
g_mime_cipher_context_sign (GMimeCipherContext *ctx, const char *userid, GMimeCipherHash hash,
Modified: trunk/gmime/gmime-gpg-context.c
==============================================================================
--- trunk/gmime/gmime-gpg-context.c (original)
+++ trunk/gmime/gmime-gpg-context.c Sat Jun 7 22:27:23 2008
@@ -284,7 +284,7 @@
unsigned int complete:1;
unsigned int seen_eof1:1;
unsigned int seen_eof2:1;
- unsigned int flushed:1; /* flushed the diagnostics stream (ie, what we read from stderr) */
+ unsigned int flushed:1; /* flushed the diagnostics stream (aka stderr) */
unsigned int always_trust:1;
unsigned int armor:1;
unsigned int need_passwd:1;
@@ -549,8 +549,18 @@
return "--digest-algo=MD5";
case GMIME_CIPHER_HASH_SHA1:
return "--digest-algo=SHA1";
+ case GMIME_CIPHER_HASH_SHA224:
+ return "--digest-algo=SHA224";
+ case GMIME_CIPHER_HASH_SHA256:
+ return "--digest-algo=SHA256";
+ case GMIME_CIPHER_HASH_SHA384:
+ return "--digest-algo=SHA384";
+ case GMIME_CIPHER_HASH_SHA512:
+ return "--digest-algo=SHA512";
case GMIME_CIPHER_HASH_RIPEMD160:
return "--digest-algo=RIPEMD160";
+ case GMIME_CIPHER_HASH_TIGER192:
+ return "--digest-algo=TIGER192";
default:
return NULL;
}
@@ -916,7 +926,7 @@
size_t nread, nwritten;
register char *inptr;
char *status, *tmp;
- int len;
+ int id, len;
parse:
@@ -1102,8 +1112,27 @@
} else {
switch (gpg->mode) {
case GPG_CTX_MODE_SIGN:
- if (!strncmp (status, "SIG_CREATED ", 12)) {
- /* FIXME: save this state? */
+ if (strncmp (status, "SIG_CREATED ", 12) != 0)
+ break;
+
+ status += 12;
+
+ /* skip the next single-char token ("D" for detached) */
+ status = next_token (status, NULL);
+
+ /* skip the public-key algo token */
+ status = next_token (status, NULL);
+
+ /* this token is the hash algorithm used */
+ switch (strtol (status, NULL, 10)) {
+ case 1: gpg->hash = GMIME_CIPHER_HASH_MD5; break;
+ case 2: gpg->hash = GMIME_CIPHER_HASH_SHA1; break;
+ case 3: gpg->hash = GMIME_CIPHER_HASH_RIPEMD160; break;
+ case 8: gpg->hash = GMIME_CIPHER_HASH_SHA256; break;
+ case 9: gpg->hash = GMIME_CIPHER_HASH_SHA384; break;
+ case 10: gpg->hash = GMIME_CIPHER_HASH_SHA512; break;
+ case 11: gpg->hash = GMIME_CIPHER_HASH_SHA224; break;
+ default: break;
}
break;
case GPG_CTX_MODE_VERIFY:
@@ -1539,9 +1568,12 @@
return -1;
}
+ /* save the hash used */
+ hash = gpg->hash;
+
gpg_ctx_free (gpg);
- return 0;
+ return hash;
}
Modified: trunk/gmime/gmime-multipart-signed.c
==============================================================================
--- trunk/gmime/gmime-multipart-signed.c (original)
+++ trunk/gmime/gmime-multipart-signed.c Sat Jun 7 22:27:23 2008
@@ -283,13 +283,13 @@
GMimeCipherContext *ctx, const char *userid,
GMimeCipherHash hash, GError **err)
{
- GMimeObject *signature;
- GMimeDataWrapper *wrapper;
- GMimeStream *filtered_stream;
- GMimeStream *stream, *sigstream;
- GMimeFilter *crlf_filter, *from_filter, *strip_filter;
+ GMimeStream *stream, *filtered, *sigstream;
GMimeContentType *content_type;
+ GMimeDataWrapper *wrapper;
+ GMimeObject *signature;
+ GMimeFilter *filter;
GMimeParser *parser;
+ int rv;
g_return_val_if_fail (GMIME_IS_MULTIPART_SIGNED (mps), -1);
g_return_val_if_fail (GMIME_IS_CIPHER_CONTEXT (ctx), -1);
@@ -301,41 +301,41 @@
/* get the cleartext */
stream = g_mime_stream_mem_new ();
- filtered_stream = g_mime_stream_filter_new (stream);
+ filtered = g_mime_stream_filter_new (stream);
/* Note: see rfc3156, section 3 - second note */
- from_filter = g_mime_filter_from_new (GMIME_FILTER_FROM_MODE_ARMOR);
- g_mime_stream_filter_add (GMIME_STREAM_FILTER (filtered_stream), from_filter);
- g_object_unref (from_filter);
+ filter = g_mime_filter_from_new (GMIME_FILTER_FROM_MODE_ARMOR);
+ g_mime_stream_filter_add (GMIME_STREAM_FILTER (filtered), filter);
+ g_object_unref (filter);
/* Note: see rfc3156, section 5.4 (this is the main difference between rfc2015 and rfc3156) */
- strip_filter = g_mime_filter_strip_new ();
- g_mime_stream_filter_add (GMIME_STREAM_FILTER (filtered_stream), strip_filter);
- g_object_unref (strip_filter);
-
- g_mime_object_write_to_stream (content, filtered_stream);
- g_mime_stream_flush (filtered_stream);
- g_object_unref (filtered_stream);
+ filter = g_mime_filter_strip_new ();
+ g_mime_stream_filter_add (GMIME_STREAM_FILTER (filtered), filter);
+ g_object_unref (filter);
+
+ g_mime_object_write_to_stream (content, filtered);
+ g_mime_stream_flush (filtered);
+ g_object_unref (filtered);
g_mime_stream_reset (stream);
/* Note: see rfc2015 or rfc3156, section 5.1 */
- filtered_stream = g_mime_stream_filter_new (stream);
- crlf_filter = g_mime_filter_crlf_new (TRUE, FALSE);
- g_mime_stream_filter_add (GMIME_STREAM_FILTER (filtered_stream), crlf_filter);
- g_object_unref (crlf_filter);
+ filtered = g_mime_stream_filter_new (stream);
+ filter = g_mime_filter_crlf_new (TRUE, FALSE);
+ g_mime_stream_filter_add (GMIME_STREAM_FILTER (filtered), filter);
+ g_object_unref (filter);
/* construct the signature stream */
sigstream = g_mime_stream_mem_new ();
/* sign the content stream */
- if (g_mime_cipher_context_sign (ctx, userid, hash, filtered_stream, sigstream, err) == -1) {
- g_object_unref (filtered_stream);
+ if ((rv = g_mime_cipher_context_sign (ctx, userid, hash, filtered, sigstream, err)) == -1) {
g_object_unref (sigstream);
+ g_object_unref (filtered);
g_object_unref (stream);
return -1;
}
- g_object_unref (filtered_stream);
+ g_object_unref (filtered);
g_mime_stream_reset (sigstream);
g_mime_stream_reset (stream);
@@ -354,7 +354,7 @@
g_object_unref (wrapper);
mps->protocol = g_strdup (ctx->sign_protocol);
- mps->micalg = g_strdup (g_mime_cipher_context_hash_name (ctx, hash));
+ mps->micalg = g_strdup (g_mime_cipher_context_hash_name (ctx, (GMimeCipherHash) rv));
/* set the content-type of the signature part */
content_type = g_mime_content_type_new_from_string (mps->protocol);
Modified: trunk/tests/test-pgp.c
==============================================================================
--- trunk/tests/test-pgp.c (original)
+++ trunk/tests/test-pgp.c Sat Jun 7 22:27:23 2008
@@ -108,18 +108,20 @@
{
GError *err = NULL;
Exception *ex;
+ int rv;
- g_mime_cipher_context_sign (ctx, "no user no domain",
- GMIME_CIPHER_HASH_DEFAULT,
- cleartext, ciphertext, &err);
+ rv = g_mime_cipher_context_sign (ctx, "no user no domain",
+ GMIME_CIPHER_HASH_SHA256,
+ cleartext, ciphertext, &err);
- if (err != NULL) {
+ if (rv == -1 || err != NULL) {
ex = exception_new ("%s", err->message);
g_error_free (err);
throw (ex);
}
- v(fprintf (stderr, "signature:\n%.*s\n",
+ v(fprintf (stderr, "signature (%s):\n%.*s\n",
+ g_mime_cipher_context_hash_name (ctx, rv),
GMIME_STREAM_MEM (ciphertext)->buffer->len,
GMIME_STREAM_MEM (ciphertext)->buffer->data));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]