aboutsummaryrefslogtreecommitdiffstats
path: root/mail/openpgp-utils.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2001-02-22 01:24:13 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2001-02-22 01:24:13 +0800
commit8738bf7afffc7d2696d6e422e08583d3207ef837 (patch)
tree0ae98fda61c372b0e7939b66de995f767d5f2f2c /mail/openpgp-utils.c
parent782a42ee7d5ee47607d742a3201715e4201f2e3a (diff)
downloadgsoc2013-evolution-8738bf7afffc7d2696d6e422e08583d3207ef837.tar
gsoc2013-evolution-8738bf7afffc7d2696d6e422e08583d3207ef837.tar.gz
gsoc2013-evolution-8738bf7afffc7d2696d6e422e08583d3207ef837.tar.bz2
gsoc2013-evolution-8738bf7afffc7d2696d6e422e08583d3207ef837.tar.lz
gsoc2013-evolution-8738bf7afffc7d2696d6e422e08583d3207ef837.tar.xz
gsoc2013-evolution-8738bf7afffc7d2696d6e422e08583d3207ef837.tar.zst
gsoc2013-evolution-8738bf7afffc7d2696d6e422e08583d3207ef837.zip
Changed to use PgpValidity.
2001-02-21 Jeffrey Stedfast <fejj@ximian.com> * mail-crypto.c (pgp_mime_part_verify): Changed to use PgpValidity. * openpgp-utils.c (openpgp_verify): Return a PgpValidity and set the description as UTF-8 for later use in mail-format.c when writing to GtkHTML. * mail-format.c (try_inline_pgp_sig): Updated to use the new PgpValidity code. (handle_multipart_signed): Updated. svn path=/trunk/; revision=8320
Diffstat (limited to 'mail/openpgp-utils.c')
-rw-r--r--mail/openpgp-utils.c119
1 files changed, 113 insertions, 6 deletions
diff --git a/mail/openpgp-utils.c b/mail/openpgp-utils.c
index 8046ddc782..278dac0cdf 100644
--- a/mail/openpgp-utils.c
+++ b/mail/openpgp-utils.c
@@ -48,8 +48,15 @@
#include <unistd.h>
#include <signal.h>
+#include <iconv.h>
+
#define d(x)
+struct _PgpValidity {
+ gboolean valid;
+ gchar *description;
+};
+
static const gchar *pgp_path = NULL;
static PgpType pgp_type = PGP_TYPE_NONE;
@@ -1026,7 +1033,7 @@ swrite (const char *data, int len)
return template;
}
-gboolean
+PgpValidity *
openpgp_verify (const gchar *in, gint inlen, const gchar *sigin, gint siglen, CamelException *ex)
{
char *argv[20];
@@ -1035,20 +1042,20 @@ openpgp_verify (const gchar *in, gint inlen, const gchar *sigin, gint siglen, Ca
int passwd_fds[2];
char *sigfile = NULL;
int retval, i, clearlen;
- gboolean valid = TRUE;
+ PgpValidity *valid = NULL;
if (pgp_type == PGP_TYPE_NONE) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
_("No GPG/PGP program available."));
- return FALSE;
+ return NULL;
}
if (pipe (passwd_fds) < 0) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
_("Couldn't create pipe to GPG/PGP: %s"),
g_strerror (errno));
- return FALSE;
+ return NULL;
}
if (sigin != NULL && siglen) {
@@ -1059,7 +1066,7 @@ openpgp_verify (const gchar *in, gint inlen, const gchar *sigin, gint siglen, Ca
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
_("Couldn't create temp file: %s"),
g_strerror (errno));
- return FALSE;
+ return NULL;
}
}
@@ -1119,10 +1126,40 @@ openpgp_verify (const gchar *in, gint inlen, const gchar *sigin, gint siglen, Ca
g_free (sigfile);
}
+ valid = openpgp_validity_new ();
+
if (retval != 0) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
"%s", diagnostics);
- valid = FALSE;
+
+ openpgp_validity_set_valid (valid, FALSE);
+ } else {
+ openpgp_validity_set_valid (valid, TRUE);
+ }
+
+ if (diagnostics) {
+ char *charset;
+ char *desc;
+ iconv_t cd;
+ size_t len, inlen;
+
+ charset = getenv ("CHARSET");
+ if (!charset)
+ charset = "US-ASCII";
+
+ cd = iconv_open ("UTF-8", charset);
+
+ inlen = strlen (diagnostics);
+ len = 2 * inlen;
+ desc = g_malloc0 (len);
+ if (iconv (cd, (const char **) &diagnostics, &inlen, &desc, &len) == -1) {
+ g_free (desc);
+ desc = g_strdup (diagnostics);
+ }
+ iconv_close (cd);
+
+ openpgp_validity_set_description (valid, desc);
+ g_free (desc);
}
g_free (diagnostics);
@@ -1130,3 +1167,73 @@ openpgp_verify (const gchar *in, gint inlen, const gchar *sigin, gint siglen, Ca
return valid;
}
+
+
+/* PGP Validity */
+
+PgpValidity *
+openpgp_validity_new (void)
+{
+ return g_new0 (PgpValidity, 1);
+}
+
+void
+openpgp_validity_init (PgpValidity *validity)
+{
+ g_return_if_fail (validity != NULL);
+
+ validity->valid = FALSE;
+ validity->description = NULL;
+}
+
+gboolean
+openpgp_validity_get_valid (PgpValidity *validity)
+{
+ g_return_val_if_fail (validity != NULL, FALSE);
+
+ return validity->valid;
+}
+
+void
+openpgp_validity_set_valid (PgpValidity *validity, gboolean valid)
+{
+ g_return_if_fail (validity != NULL);
+
+ validity->valid = valid;
+}
+
+gchar *
+openpgp_validity_get_description (PgpValidity *validity)
+{
+ g_return_val_if_fail (validity != NULL, NULL);
+
+ return validity->description;
+}
+
+void
+openpgp_validity_set_description (PgpValidity *validity, const gchar *description)
+{
+ g_return_if_fail (validity != NULL);
+
+ g_free (validity->description);
+ validity->description = g_strdup (description);
+}
+
+void
+openpgp_validity_clear (PgpValidity *validity)
+{
+ g_return_if_fail (validity != NULL);
+
+ validity->valid = FALSE;
+ g_free (validity->description);
+ validity->description = NULL;
+}
+
+void
+openpgp_validity_free (PgpValidity *validity)
+{
+ g_return_if_fail (validity != NULL);
+
+ g_free (validity->description);
+ g_free (validity);
+}