[gmime] Added new files to implement certificate and signature classes



commit e90487d89789fb378cfdc8ebe1ec87437d858c30
Author: Jeffrey Stedfast <fejj gnome org>
Date:   Thu Mar 17 17:21:07 2011 -0400

    Added new files to implement certificate and signature classes
    
    2011-03-17  Jeffrey Stedfast  <fejj novell com>
    
    	* gmime/gmime-certificate.[c,h]: New source files implementing
    	Certificate and CertificateList classes.
    
    	* gmime/gmime-signature.[c,h]: New source files implementing
    	Signature and SignatureList classes.

 ChangeLog                 |    8 +
 gmime/gmime-certificate.c |  838 +++++++++++++++++++++++++++++++++++++++++++++
 gmime/gmime-certificate.h |  241 +++++++++++++
 gmime/gmime-signature.c   |  634 ++++++++++++++++++++++++++++++++++
 gmime/gmime-signature.h   |  172 +++++++++
 5 files changed, 1893 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 83a47c6..95543f5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-03-17  Jeffrey Stedfast  <fejj novell com>
+
+	* gmime/gmime-certificate.[c,h]: New source files implementing
+	Certificate and CertificateList classes.
+
+	* gmime/gmime-signature.[c,h]: New source files implementing
+	Signature and SignatureList classes.
+
 2011-03-16  Jeffrey Stedfast  <fejj novell com>
 
 	* mono/StreamWrapper.cs (Write): Implemented.
diff --git a/gmime/gmime-certificate.c b/gmime/gmime-certificate.c
new file mode 100644
index 0000000..0865fa9
--- /dev/null
+++ b/gmime/gmime-certificate.c
@@ -0,0 +1,838 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*  GMime
+ *  Copyright (C) 2000-2011 Jeffrey Stedfast
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1
+ *  of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+ *  02110-1301, USA.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "gmime-certificate.h"
+
+
+/**
+ * SECTION: gmime-certificate
+ * @title: GMimeCertificate
+ * @short_description: Digital certificates
+ * @see_also:
+ *
+ * A #GMimeCertificate is an object containing useful information about a
+ * digital certificate as used in signing and encrypting data.
+ **/
+
+
+static void g_mime_certificate_class_init (GMimeCertificateClass *klass);
+static void g_mime_certificate_init (GMimeCertificate *cert, GMimeCertificateClass *klass);
+static void g_mime_certificate_finalize (GObject *object);
+
+static GObjectClass *parent_class = NULL;
+
+
+GType
+g_mime_certificate_get_type (void)
+{
+	static GType type = 0;
+	
+	if (!type) {
+		static const GTypeInfo info = {
+			sizeof (GMimeCertificateClass),
+			NULL, /* base_class_init */
+			NULL, /* base_class_finalize */
+			(GClassInitFunc) g_mime_certificate_class_init,
+			NULL, /* class_finalize */
+			NULL, /* class_data */
+			sizeof (GMimeCertificate),
+			0,    /* n_preallocs */
+			(GInstanceInitFunc) g_mime_certificate_init,
+		};
+		
+		type = g_type_register_static (G_TYPE_OBJECT, "GMimeCertificate", &info, 0);
+	}
+	
+	return type;
+}
+
+static void
+g_mime_certificate_class_init (GMimeCertificateClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	
+	parent_class = g_type_class_ref (G_TYPE_OBJECT);
+	
+	object_class->finalize = g_mime_certificate_finalize;
+}
+
+static void
+g_mime_certificate_init (GMimeCertificate *cert, GMimeCertificateClass *klass)
+{
+	cert->pubkey_algo = GMIME_PUBKEY_ALGO_DEFAULT;
+	cert->digest_algo = GMIME_DIGEST_ALGO_DEFAULT;
+	cert->trust = GMIME_CERTIFICATE_TRUST_NONE;
+	cert->issuer_serial = NULL;
+	cert->issuer_name = NULL;
+	cert->fingerprint = NULL;
+	cert->created = (time_t) -1;
+	cert->expires = (time_t) -1;
+	cert->keyid = NULL;
+	cert->email = NULL;
+	cert->name = NULL;
+}
+
+static void
+g_mime_certificate_finalize (GObject *object)
+{
+	GMimeCertificate *cert = (GMimeCertificate *) object;
+	
+	g_free (cert->issuer_serial);
+	g_free (cert->issuer_name);
+	g_free (cert->fingerprint);
+	g_free (cert->keyid);
+	g_free (cert->email);
+	g_free (cert->name);
+	
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+
+/**
+ * g_mime_certificate_new:
+ *
+ * Creates a new #GMimeCertificate object.
+ * 
+ * Returns: a new #GMimeCertificate object.
+ **/
+GMimeCertificate *
+g_mime_certificate_new (void)
+{
+	return g_object_newv (GMIME_TYPE_CERTIFICATE, 0, NULL);
+}
+
+
+/**
+ * g_mime_certificate_set_trust:
+ * @cert: a #GMimeCertificate
+ * @trust: a #GMimeCertificateTrust value
+ *
+ * Set the certificate trust.
+ **/
+void
+g_mime_certificate_set_trust (GMimeCertificate *cert, GMimeCertificateTrust trust)
+{
+	g_return_if_fail (certificate != NULL);
+	
+	cert->trust = trust;
+}
+
+
+/**
+ * g_mime_certificate_get_trust:
+ * @cert: a #GMimeCertificate
+ *
+ * Get the certificate trust.
+ *
+ * Returns: the certificate trust.
+ **/
+GMimeCertificateTrust
+g_mime_certificate_get_trust (GMimeCertificate *cert)
+{
+	g_return_val_if_fail (GMIME_IS_CERTIFICATE (cert), GMIME_CERTIFICATE_TRUST_NONE);
+	
+	return cert->trust;
+}
+
+
+/**
+ * g_mime_certificate_set_pubkey_algo:
+ * @cert: a #GMimeCertificate
+ * @algo: a #GMimePubKeyAlgo
+ *
+ * Set the public-key algorithm used by the certificate.
+ **/
+void
+g_mime_certificate_set_pubkey_algo (GMimeCertificate *cert, GMimePubKeyAlgo algo)
+{
+	g_return_if_fail (GMIME_IS_CERTIFICATE (cert));
+	
+	cert->pubkey_algo = algo;
+}
+
+
+/**
+ * g_mime_certificate_get_pubkey_algo:
+ * @cert: a #GMimeCertificate
+ *
+ * Get the public-key algorithm used by the certificate.
+ *
+ * Returns: the public-key algorithm used by the certificate or
+ * #GMIME_PUBKEY_ALGO_DEFAULT if unspecified.
+ **/
+GMimePubKeyAlgo
+g_mime_certificate_get_pubkey_algo (GMimeCertificate *cert)
+{
+	g_return_val_if_fail (GMIME_IS_CERTIFICATE (cert), GMIME_PUBKEY_ALGO_DEFAULT);
+	
+	return cert->pubkey_algo;
+}
+
+
+/**
+ * g_mime_certificate_set_digest_algo:
+ * @cert: a #GMimeCertificate
+ * @algo: a #GMimeDigestAlgo
+ *
+ * Set the digest algorithm used by the certificate.
+ **/
+void
+g_mime_certificate_set_digest_algo (GMimeCertificate *cert, GMimeDigestAlgo algo)
+{
+	g_return_if_fail (GMIME_IS_CERTIFICATE (cert));
+	
+	cert->digest_algo = algo;
+}
+
+
+/**
+ * g_mime_certificate_get_digest_algo:
+ * @cert: a #GMimeCertificate
+ *
+ * Get the digest algorithm used by the certificate.
+ *
+ * Returns: the digest algorithm used by the certificate or
+ * #GMIME_DIGEST_ALGO_DEFAULT if unspecified.
+ **/
+GMimeDigestAlgo
+g_mime_certificate_get_digest_algo (GMimeCertificate *cert)
+{
+	g_return_val_if_fail (GMIME_IS_CERTIFICATE (cert), GMIME_DIGEST_ALGO_DEFAULT);
+	
+	return cert->digest_algo;
+}
+
+
+/**
+ * g_mime_certificate_set_issuer_serial:
+ * @cert: a #GMimeCertificate
+ * @issuer_serial: certificate's issuer serial
+ *
+ * Set the certificate's issuer serial.
+ **/
+void
+g_mime_certificate_set_issuer_serial (GMimeCertificate *cert, const char *issuer_serial)
+{
+	g_return_if_fail (GMIME_IS_CERTIFICATE (cert));
+	
+	g_free (cert->issuer_serial);
+	cert->issuer_serial = g_strdup (issuer_serial);
+}
+
+
+/**
+ * g_mime_certificate_get_issuer_serial:
+ * @cert: a #GMimeCertificate
+ *
+ * Get the certificate's issuer serial.
+ *
+ * Returns: the certificate's issuer serial or %NULL if unspecified.
+ **/
+const char *
+g_mime_certificate_get_issuer_serial (GMimeCertificate *cert)
+{
+	g_return_val_if_fail (GMIME_IS_CERTIFICATE (cert), NULL);
+	
+	return cert->issuer_serial;
+}
+
+
+/**
+ * g_mime_certificate_set_issuer_name:
+ * @cert: a #GMimeCertificate
+ * @issuer_name: certificate's issuer name
+ *
+ * Set the certificate's issuer name.
+ **/
+void
+g_mime_certificate_set_issuer_name (GMimeCertificate *cert, const char *issuer_name)
+{
+	g_return_if_fail (GMIME_IS_CERTIFICATE (cert));
+	
+	g_free (cert->issuer_name);
+	cert->issuer_name = g_strdup (issuer_name);
+}
+
+
+/**
+ * g_mime_certificate_get_issuer_name:
+ * @cert: a #GMimeCertificate
+ *
+ * Get the certificate's issuer name.
+ *
+ * Returns: the certificate's issuer name or %NULL if unspecified.
+ **/
+const char *
+g_mime_certificate_get_issuer_name (GMimeCertificate *cert)
+{
+	g_return_val_if_fail (GMIME_IS_CERTIFICATE (cert), NULL);
+	
+	return cert->issuer_name;
+}
+
+
+/**
+ * g_mime_certificate_set_fingerprint:
+ * @cert: a #GMimeCertificate
+ * @fingerprint: fingerprint string
+ *
+ * Set the certificate's key fingerprint.
+ **/
+void
+g_mime_certificate_set_fingerprint (GMimeCertificate *cert, const char *fingerprint)
+{
+	g_return_if_fail (GMIME_IS_CERTIFICATE (cert));
+	
+	g_free (cert->fingerprint);
+	cert->fingerprint = g_strdup (fingerprint);
+}
+
+
+/**
+ * g_mime_certificate_get_fingerprint:
+ * @cert: a #GMimeCertificate
+ *
+ * Get the certificate's key fingerprint.
+ *
+ * Returns: the certificate's key fingerprint or %NULL if unspecified.
+ **/
+const char *
+g_mime_certificate_get_fingerprint (GMimeCertificate *cert)
+{
+	g_return_val_if_fail (GMIME_IS_CERTIFICATE (cert), NULL);
+	
+	return cert->fingerprint;
+}
+
+
+/**
+ * g_mime_certificate_set_key_id:
+ * @cert: a #GMimeCertificate
+ * @key_id: key id
+ *
+ * Set the certificate's key id.
+ **/
+void
+g_mime_certificate_set_key_id (GMimeCertificate *cert, const char *key_id)
+{
+	g_return_if_fail (GMIME_IS_CERTIFICATE (cert));
+	
+	g_free (cert->keyid);
+	cert->keyid = g_strdup (key_id);
+}
+
+
+/**
+ * g_mime_certificate_get_key_id:
+ * @cert: a #GMimeCertificate
+ *
+ * Get the certificate's key id.
+ *
+ * Returns: the certificate's key id or %NULL if unspecified.
+ **/
+const char *
+g_mime_certificate_get_key_id (GMimeCertificate *cert)
+{
+	g_return_val_if_fail (GMIME_IS_CERTIFICATE (cert), NULL);
+	
+	return cert->keyid;
+}
+
+
+/**
+ * g_mime_certificate_set_email:
+ * @cert: a #GMimeCertificate
+ * @email: certificate's email
+ *
+ * Set the certificate's email.
+ **/
+void
+g_mime_certificate_set_email (GMimeCertificate *cert, const char *email)
+{
+	g_return_if_fail (GMIME_IS_CERTIFICATE (cert));
+	
+	g_free (cert->email);
+	cert->email = g_strdup (email);
+}
+
+
+/**
+ * g_mime_certificate_get_email:
+ * @cert: a #GMimeCertificate
+ *
+ * Get the certificate's email.
+ *
+ * Returns: the certificate's email or %NULL if unspecified.
+ **/
+const char *
+g_mime_certificate_get_email (GMimeCertificate *cert)
+{
+	g_return_val_if_fail (GMIME_IS_CERTIFICATE (cert), NULL);
+	
+	return cert->email;
+}
+
+
+/**
+ * g_mime_certificate_set_name:
+ * @cert: a #GMimeCertificate
+ * @name: certificate's name
+ *
+ * Set the certificate's name.
+ **/
+void
+g_mime_certificate_set_name (GMimeCertificate *cert, const char *name)
+{
+	g_return_if_fail (GMIME_IS_CERTIFICATE (cert));
+	
+	g_free (cert->name);
+	cert->name = g_strdup (name);
+}
+
+
+/**
+ * g_mime_certificate_get_name:
+ * @cert: a #GMimeCertificate
+ *
+ * Get the certificate's name.
+ *
+ * Returns: the certificate's name or %NULL if unspecified.
+ **/
+const char *
+g_mime_certificate_get_name (GMimeCertificate *cert)
+{
+	g_return_val_if_fail (GMIME_IS_CERTIFICATE (cert), NULL);
+	
+	return cert->name;
+}
+
+
+/**
+ * g_mime_certificate_set_created:
+ * @cert: a #GMimeCertificate
+ * @created: creation date
+ *
+ * Set the creation date of the certificate's key.
+ **/
+void
+g_mime_certificate_set_created (GMimeCertificate *cert, time_t created)
+{
+	g_return_if_fail (GMIME_IS_CERTIFICATE (cert));
+	
+	cert->created = created;
+}
+
+
+/**
+ * g_mime_certificate_get_created:
+ * @cert: a #GMimeCertificate
+ *
+ * Get the creation date of the certificate's key.
+ *
+ * Returns: the creation date of the certificate's key or %-1 if unknown.
+ **/
+time_t
+g_mime_certificate_get_created (GMimeCertificate *cert)
+{
+	g_return_val_if_fail (GMIME_IS_CERTIFICATE (cert), (time_t) -1);
+	
+	return cert->created;
+}
+
+
+/**
+ * g_mime_certificate_set_expires:
+ * @cert: a #GMimeCertificate
+ * @expires: expiration date
+ *
+ * Set the expiration date of the certificate's key.
+ **/
+void
+g_mime_certificate_set_expires (GMimeCertificate *cert, time_t expires)
+{
+	g_return_if_fail (GMIME_IS_CERTIFICATE (cert));
+	
+	cert->expires = expires;
+}
+
+
+/**
+ * g_mime_certificate_get_expires:
+ * @cert: a #GMimeCertificate
+ *
+ * Get the expiration date of the certificate's key.
+ *
+ * Returns: the expiration date of the certificate's key or %-1 if unknown.
+ **/
+time_t
+g_mime_certificate_get_expires (GMimeCertificate *cert)
+{
+	g_return_val_if_fail (GMIME_IS_CERTIFICATE (cert), (time_t) -1);
+	
+	return cert->expires;
+}
+
+
+static void g_mime_certificate_list_class_init (GMimeCertificateListClass *klass);
+static void g_mime_certificate_list_init (GMimeCertificateList *list, GMimeCertificateListClass *klass);
+static void g_mime_certificate_list_finalize (GObject *object);
+
+
+static GObjectClass *list_parent_class = NULL;
+
+
+GType
+g_mime_certificate_list_get_type (void)
+{
+	static GType type = 0;
+	
+	if (!type) {
+		static const GTypeInfo info = {
+			sizeof (GMimeCertificateListClass),
+			NULL, /* base_class_init */
+			NULL, /* base_class_finalize */
+			(GClassInitFunc) g_mime_certificate_list_class_init,
+			NULL, /* class_finalize */
+			NULL, /* class_data */
+			sizeof (GMimeCertificateList),
+			0,    /* n_preallocs */
+			(GInstanceInitFunc) g_mime_certificate_list_init,
+		};
+		
+		type = g_type_register_static (G_TYPE_OBJECT, "GMimeCertificateList", &info, 0);
+	}
+	
+	return type;
+}
+
+
+static void
+g_mime_certificate_list_class_init (GMimeCertificateListClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	
+	list_parent_class = g_type_class_ref (G_TYPE_OBJECT);
+	
+	object_class->finalize = g_mime_certificate_list_finalize;
+}
+
+static void
+g_mime_certificate_list_init (GMimeCertificateList *list, GMimeCertificateListClass *klass)
+{
+	list->array = g_ptr_array_new ();
+}
+
+static void
+g_mime_certificate_list_finalize (GObject *object)
+{
+	GMimeCertificateList *list = (GMimeCertificateList *) object;
+	GMimeCertificate *cert;
+	guint i;
+	
+	for (i = 0; i < list->array->len; i++) {
+		cert = (GMimeCertificate *) list->array->pdata[i];
+		g_object_unref (cert);
+	}
+	
+	g_ptr_array_free (list->array, TRUE);
+	
+	G_OBJECT_CLASS (list_parent_class)->finalize (object);
+}
+
+
+/**
+ * g_mime_certificate_list_new:
+ *
+ * Creates a new #GMimeCertificateList.
+ *
+ * Returns: a new #GMimeCertificateList.
+ **/
+GMimeCertificateList *
+g_mime_certificate_list_new (void)
+{
+	return g_object_newv (GMIME_TYPE_CERTIFICATE_LIST, 0, NULL);
+}
+
+
+/**
+ * g_mime_certificate_list_length:
+ * @list: a #GMimeCertificateList
+ *
+ * Gets the length of the list.
+ *
+ * Returns: the number of #GMimeCertificate objects in the list.
+ **/
+int
+g_mime_certificate_list_length (GMimeCertificateList *list)
+{
+	g_return_val_if_fail (IS_G_MIME_CERTIFICATE_LIST (list), -1);
+	
+	return list->array->len;
+}
+
+
+/**
+ * g_mime_certificate_list_clear:
+ * @list: a #GMimeCertificateList
+ *
+ * Clears the list of addresses.
+ **/
+void
+g_mime_certificate_list_clear (GMimeCertificateList *list)
+{
+	GMimeCertificate *cert;
+	guint i;
+	
+	g_return_if_fail (IS_G_MIME_CERTIFICATE_LIST (list));
+	
+	for (i = 0; i < list->array->len; i++) {
+		cert = (GMimeCertificate *) list->array->pdata[i];
+		g_object_unref (cert);
+	}
+	
+	g_ptr_array_set_size (list->array, 0);
+}
+
+
+/**
+ * g_mime_certificate_list_add:
+ * @list: a #GMimeCertificateList
+ * @cert: a #GMimeCertificate
+ *
+ * Adds a #GMimeCertificate to the #GMimeCertificateList.
+ *
+ * Returns: the index of the added #GMimeCertificate.
+ **/
+int
+g_mime_certificate_list_add (GMimeCertificateList *list, GMimeCertificate *cert)
+{
+	int index;
+	
+	g_return_val_if_fail (GMIME_IS_CERTIFICATE_LIST (list), -1);
+	g_return_val_if_fail (GMIME_IS_CERTIFICATE (cert), -1);
+	
+	index = list->array->len;
+	g_ptr_array_add (list->array, cert);
+	g_object_ref (cert);
+	
+	return index;
+}
+
+
+/**
+ * g_mime_certificate_list_insert:
+ * @list: a #GMimeCertificateList
+ * @index: index to insert at
+ * @cert: a #GMimeCertificate
+ *
+ * Inserts a #GMimeCertificate into the #GMimeCertificateList at the specified
+ * index.
+ **/
+void
+g_mime_certificate_list_insert (GMimeCertificateList *list, int index, GMimeCertificate *cert)
+{
+	char *dest, *src;
+	size_t n;
+	
+	g_return_if_fail (GMIME_IS_CERTIFICATE_LIST (list));
+	g_return_if_fail (GMIME_IS_CERTIFICATE (cert));
+	g_return_if_fail (index >= 0);
+	
+	if ((guint) index < list->array->len) {
+		g_ptr_array_set_size (list->array, list->array->len + 1);
+		
+		dest = ((char *) list->array->pdata) + (sizeof (void *) * (index + 1));
+		src = ((char *) list->array->pdata) + (sizeof (void *) * index);
+		n = list->array->len - index - 1;
+		
+		g_memmove (dest, src, (sizeof (void *) * n));
+		list->array->pdata[index] = cert;
+	} else {
+		/* the easy case */
+		g_ptr_array_add (list->array, cert);
+	}
+	
+	g_object_ref (cert);
+}
+
+
+/**
+ * g_mime_certificate_list_remove:
+ * @list: a #GMimeCertificateList
+ * @cert: a #GMimeCertificate
+ *
+ * Removes a #GMimeCertificate from the #GMimeCertificateList.
+ *
+ * Returns: %TRUE if the specified #GMimeCertificate was removed or %FALSE
+ * otherwise.
+ **/
+gboolean
+g_mime_certificate_list_remove (GMimeCertificateList *list, GMimeCertificate *cert)
+{
+	int index;
+	
+	g_return_val_if_fail (GMIME_IS_CERTIFICATE_LIST (list), FALSE);
+	g_return_val_if_fail (GMIME_IS_CERTIFICATE (cert), FALSE);
+	
+	if ((index = g_mime_certificate_list_index_of (list, cert)) == -1)
+		return FALSE;
+	
+	g_mime_certificate_list_remove_at (list, index);
+	
+	return TRUE;
+}
+
+
+/**
+ * g_mime_certificate_list_remove_at:
+ * @list: a #GMimeCertificateList
+ * @index: index to remove
+ *
+ * Removes a #GMimeCertificate from the #GMimeCertificateList at the specified
+ * index.
+ *
+ * Returns: %TRUE if an #GMimeCertificate was removed or %FALSE otherwise.
+ **/
+gboolean
+g_mime_certificate_list_remove_at (GMimeCertificateList *list, int index)
+{
+	GMimeCertificate *cert;
+	
+	g_return_val_if_fail (GMIME_IS_CERTIFICATE_LIST (list), FALSE);
+	g_return_val_if_fail (index >= 0, FALSE);
+	
+	if ((guint) index >= list->array->len)
+		return FALSE;
+	
+	cert = list->array->pdata[index];
+	g_ptr_array_remove_index (list->array, index);
+	g_object_unref (cert);
+	
+	return TRUE;
+}
+
+
+/**
+ * g_mime_certificate_list_contains:
+ * @list: a #GMimeCertificateList
+ * @cert: a #GMimeCertificate
+ *
+ * Checks whether or not the specified #GMimeCertificate is contained within
+ * the #GMimeCertificateList.
+ *
+ * Returns: %TRUE if the specified #GMimeCertificate is contained within the
+ * specified #GMimeCertificateList or %FALSE otherwise.
+ **/
+gboolean
+g_mime_certificate_list_contains (GMimeCertificateList *list, GMimeCertificate *cert)
+{
+	return g_mime_certificate_list_index_of (list, cert) != -1;
+}
+
+
+/**
+ * g_mime_certificate_list_index_of:
+ * @list: a #GMimeCertificateList
+ * @cert: a #GMimeCertificate
+ *
+ * Gets the index of the specified #GMimeCertificate inside the
+ * #GMimeCertificateList.
+ *
+ * Returns: the index of the requested #GMimeCertificate within the
+ * #GMimeCertificateList or %-1 if it is not contained within the
+ * #GMimeCertificateList.
+ **/
+int
+g_mime_certificate_list_index_of (GMimeCertificateList *list, GMimeCertificate *cert)
+{
+	guint i;
+	
+	g_return_val_if_fail (GMIME_IS_CERTIFICATE_LIST (list), -1);
+	g_return_val_if_fail (GMIME_IS_CERTIFICATE (cert), -1);
+	
+	for (i = 0; i < list->array->len; i++) {
+		if (list->array->pdata[i] == cert)
+			return i;
+	}
+	
+	return -1;
+}
+
+
+/**
+ * g_mime_certificate_list_get_cert:
+ * @list: a #GMimeCertificateList
+ * @index: index of #GMimeCertificate to get
+ *
+ * Gets the #GMimeCertificate at the specified index.
+ *
+ * Returns: the #GMimeCertificate at the specified index or %NULL if
+ * the index is out of range.
+ **/
+GMimeCertificate *
+g_mime_certificate_list_get_cert (GMimeCertificateList *list, int index)
+{
+	g_return_val_if_fail (GMIME_IS_CERTIFICATE_LIST (list), NULL);
+	g_return_val_if_fail (index >= 0, NULL);
+	
+	if ((guint) index >= list->array->len)
+		return NULL;
+	
+	return list->array->pdata[index];
+}
+
+
+/**
+ * g_mime_certificate_list_set_cert:
+ * @list: a #GMimeCertificateList
+ * @index: index of #GMimeCertificate to set
+ * @cert: a #GMimeCertificate
+ *
+ * Sets the #GMimeCertificate at the specified index to @cert.
+ **/
+void
+g_mime_certificate_list_set_cert (GMimeCertificateList *list, int index, GMimeCertificate *cert)
+{
+	GMimeCertificate *old;
+	
+	g_return_if_fail (GMIME_IS_CERTIFICATE_LIST (list));
+	g_return_if_fail (GMIME_IS_CERTIFICATE (cert));
+	g_return_if_fail (index >= 0);
+	
+	if ((guint) index > list->array->len)
+		return;
+	
+	if ((guint) index == list->array->len) {
+		g_mime_certificate_list_add (list, cert);
+		return;
+	}
+	
+	if ((old = list->array->pdata[index]) == cert)
+		return;
+	
+	list->array->pdata[index] = cert;
+	g_object_unref (old);
+	g_object_ref (cert);
+}
diff --git a/gmime/gmime-certificate.h b/gmime/gmime-certificate.h
new file mode 100644
index 0000000..9ad6274
--- /dev/null
+++ b/gmime/gmime-certificate.h
@@ -0,0 +1,241 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*  GMime
+ *  Copyright (C) 2000-2011 Jeffrey Stedfast
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1
+ *  of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+ *  02110-1301, USA.
+ */
+
+
+#ifndef __GMIME_CERTIFICATE_H__
+#define __GMIME_CERTIFICATE_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <time.h>
+
+G_BEGIN_DECLS
+
+#define GMIME_TYPE_CERTIFICATE                  (g_mime_certificate_get_type ())
+#define GMIME_CERTIFICATE(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMIME_TYPE_CERTIFICATE, GMimeCertificate))
+#define GMIME_CERTIFICATE_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GMIME_TYPE_CERTIFICATE, GMimeCertificateClass))
+#define GMIME_IS_CERTIFICATE(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GMIME_TYPE_CERTIFICATE))
+#define GMIME_IS_CERTIFICATE_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GMIME_TYPE_CERTIFICATE))
+#define GMIME_CERTIFICATE_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GMIME_TYPE_CERTIFICATE, GMimeCertificateClass))
+
+#define GMIME_TYPE_CERTIFICATE_LIST             (g_mime_certificate_list_get_type ())
+#define GMIME_CERTIFICATE_LIST(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMIME_TYPE_CERTIFICATE_LIST, GMimeCertificateList))
+#define GMIME_CERTIFICATE_LIST_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GMIME_TYPE_CERTIFICATE_LIST, GMimeCertificateListClass))
+#define GMIME_IS_CERTIFICATE_LIST(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GMIME_TYPE_CERTIFICATE_LIST))
+#define GMIME_IS_CERTIFICATE_LIST_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GMIME_TYPE_CERTIFICATE_LIST))
+
+
+typedef struct _GMimeCertificate GMimeCertificate;
+typedef struct _GMimeCertificateClass GMimeCertificateClass;
+
+typedef struct _GMimeCertificateList GMimeCertificateList;
+typedef struct _GMimeCertificateListClass GMimeCertificateListClass;
+
+
+/**
+ * GMimeDigestAlgo:
+ * @GMIME_DIGEST_ALGO_DEFAULT: The default hash algorithm.
+ * @GMIME_DIGEST_ALGO_MD5: The MD5 hash algorithm.
+ * @GMIME_DIGEST_ALGO_SHA1: The SHA-1 hash algorithm.
+ * @GMIME_DIGEST_ALGO_RIPEMD160: The RIPEMD-160 hash algorithm.
+ * @GMIME_DIGEST_ALGO_MD2: The MD2 hash algorithm.
+ * @GMIME_DIGEST_ALGO_TIGER192: The TIGER-192 hash algorithm.
+ * @GMIME_DIGEST_ALGO_HAVAL5160: The HAVAL-5-160 hash algorithm.
+ * @GMIME_DIGEST_ALGO_SHA256: The SHA-256 hash algorithm.
+ * @GMIME_DIGEST_ALGO_SHA384: The SHA-384 hash algorithm.
+ * @GMIME_DIGEST_ALGO_SHA512: The SHA-512 hash algorithm.
+ * @GMIME_DIGEST_ALGO_SHA224: The SHA-224 hash algorithm.
+ * @GMIME_DIGEST_ALGO_MD4: The MD4 hash algorithm.
+ *
+ * A hash algorithm.
+ **/
+typedef enum {
+	GMIME_DIGEST_ALGO_DEFAULT     = 0,
+	GMIME_DIGEST_ALGO_MD5         = 1,
+	GMIME_DIGEST_ALGO_SHA1        = 2,
+	GMIME_DIGEST_ALGO_RIPEMD160   = 3,
+	GMIME_DIGEST_ALGO_MD2         = 5,
+	GMIME_DIGEST_ALGO_TIGER192    = 6,
+	GMIME_DIGEST_ALGO_HAVAL5160   = 7,
+	GMIME_DIGEST_ALGO_SHA256      = 8,
+	GMIME_DIGEST_ALGO_SHA384      = 9,
+	GMIME_DIGEST_ALGO_SHA512      = 10,
+	GMIME_DIGEST_ALGO_SHA224      = 11,
+	GMIME_DIGEST_ALGO_MD4         = 301,
+} GMimeDigestAlgo;
+
+/**
+ * GMimePubKeyAlgo:
+ * @GMIME_PUBKEY_ALGO_DEFAULT: The default public-key algorithm.
+ * @GMIME_PUBKEY_ALGO_RSA: The RSA algorithm.
+ * @GMIME_PUBKEY_ALGO_RSA_E: An encryption-only RSA algorithm.
+ * @GMIME_PUBKEY_ALGO_RSA_S: A signature-only RSA algorithm.
+ * @GMIME_PUBKEY_ALGO_ELG_E: An encryption-only ElGamal algorithm.
+ * @GMIME_PUBKEY_ALGO_DSA: The DSA algorithm.
+ * @GMIME_PUBKEY_ALGO_ELG: The ElGamal algorithm.
+ *
+ * A public-key algorithm.
+ **/
+typedef enum {
+	GMIME_PUBKEY_ALGO_DEFAULT  = 0,
+	GMIME_PUBKEY_ALGO_RSA      = 1,
+	GMIME_PUBKEY_ALGO_RSA_E    = 2,
+	GMIME_PUBKEY_ALGO_RSA_S    = 3,
+	GMIME_PUBKEY_ALGO_ELG_E    = 16,
+	GMIME_PUBKEY_ALGO_DSA      = 17,
+	GMIME_PUBKEY_ALGO_ELG      = 20
+} GMimePubKeyAlgo;
+
+/**
+ * GMimeCertificateTrust:
+ * @GMIME_CERTIFICATE_TRUST_NONE: No trust assigned.
+ * @GMIME_CERTIFICATE_TRUST_NEVER: Never trust this certificate.
+ * @GMIME_CERTIFICATE_TRUST_UNDEFINED: Undefined trust for this certificate.
+ * @GMIME_CERTIFICATE_TRUST_MARGINAL: Trust this certificate maginally.
+ * @GMIME_CERTIFICATE_TRUST_FULLY: Trust this certificate fully.
+ * @GMIME_CERTIFICATE_TRUST_ULTIMATE: Trust this certificate ultimately.
+ *
+ * The trust value of a certificate.
+ **/
+typedef enum {
+	GMIME_CERTIFICATE_TRUST_NONE,
+	GMIME_CERTIFICATE_TRUST_NEVER,
+	GMIME_CERTIFICATE_TRUST_UNDEFINED,
+	GMIME_CERTIFICATE_TRUST_MARGINAL,
+	GMIME_CERTIFICATE_TRUST_FULLY,
+	GMIME_CERTIFICATE_TRUST_ULTIMATE
+} GMimeCertificateTrust;
+
+/**
+ * GMimeCertificate:
+ * @pubkey_algo: The public-key algorithm used by the certificate, if known.
+ * @digest_algo: The digest algorithm used by the certificate, if known.
+ * @issuer_serial: The issuer of the certificate, if known.
+ * @issuer_name: The issuer of the certificate, if known.
+ * @fingerprint: A hex string representing the certificate's fingerprint.
+ * @created: The creation date of the certificate.
+ * @expires: The expiration date of the certificate.
+ * @keyid: The certificate's key id.
+ * @email: The email address of the person or entity.
+ * @name: The name of the person or entity.
+ *
+ * An object containing useful information about a certificate.
+ **/
+struct _GMimeCertificate {
+	GObject parent_object;
+	
+	GMimePubKeyAlgo pubkey_algo;
+	GMimeDigestAlgo digest_algo;
+	GMimeCertificateTrust trust;
+	char *issuer_serial;
+	char *issuer_name;
+	char *fingerprint;
+	time_t created;
+	time_t expires;
+	char *keyid;
+	char *email;
+	char *name;
+};
+
+struct _GMimeCertificateClass {
+	GObjectClass parent_class;
+	
+};
+
+
+GType g_mime_certificate_get_type (void);
+
+GMimeCertificate *g_mime_certificate_new (void);
+
+void g_mime_certificate_set_trust (GMimeCertificate *cert, GMimeCertificateTrust trust);
+GMimeCertificateTrust g_mime_certificate_get_trust (GMimeCertificate *cert);
+
+void g_mime_certificate_set_pubkey_algo (GMimeCertificate *cert, GMimePubKeyAlgo algo);
+GMimeCryptoPubKeyAlgo g_mime_certificate_get_pubkey_algo (GMimeCertificate *cert);
+
+void g_mime_certificate_set_digest_algo (GMimeCertificate *cert, GMimeDigestAlgo algo);
+GMimeCryptoHash g_mime_certificate_get_digest_algo (GMimeCertificate *cert);
+
+void g_mime_certificate_set_issuer_serial (GMimeCertificate *cert, const char *issuer_serial);
+const char *g_mime_certificate_get_issuer_serial (GMimeCertificate *cert);
+
+void g_mime_certificate_set_issuer_name (GMimeCertificate *cert, const char *issuer_name);
+const char *g_mime_certificate_get_issuer_name (GMimeCertificate *cert);
+
+void g_mime_certificate_set_fingerprint (GMimeCertificate *cert, const char *fingerprint);
+const char *g_mime_certificate_get_fingerprint (GMimeCertificate *cert);
+
+void g_mime_certificate_set_key_id (GMimeCertificate *cert, const char *key_id);
+const char *g_mime_certificate_get_key_id (GMimeCertificate *cert);
+
+void g_mime_certificate_set_email (GMimeCertificate *cert, const char *email);
+const char *g_mime_certificate_get_email (GMimeCertificate *cert);
+
+void g_mime_certificate_set_name (GMimeCertificate *cert, const char *name);
+const char *g_mime_certificate_get_name (GMimeCertificate *cert);
+
+void g_mime_certificate_set_created (GMimeCertificate *cert, time_t created);
+time_t g_mime_certificate_get_created (GMimeCertificate *cert);
+
+void g_mime_certificate_set_expires (GMimeCertificate *cert, time_t expires);
+time_t g_mime_certificate_get_expires (GMimeCertificate *cert);
+
+
+/**
+ * GMimeCertificateList:
+ * @parent_object: parent #GObject
+ * @array: An array of #GMimeCertificate objects.
+ *
+ * A collection of #GMimeCertificate objects.
+ **/
+struct _GMimeCertificateList {
+	GObject parent_object;
+	GPtrArray *array;
+};
+
+struct _GMimeCertificateListClass {
+	GObjectClass parent_class;
+	
+};
+
+
+GType g_mime_certificate_list_get_type (void);
+
+GMimeCertificateList *g_mime_certificate_list_new (void);
+
+int g_mime_certificate_list_length (GMimeCertificateList *list);
+
+void g_mime_certificate_list_clear (GMimeCertificateList *list);
+
+int g_mime_certificate_list_add (GMimeCertificateList *list, GMimeCertificate *cert);
+void g_mime_certificate_list_insert (GMimeCertificateList *list, int index, GMimeCertificate *cert);
+gboolean g_mime_certificate_list_remove (GMimeCertificateList *list, GMimeCertificate *cert);
+gboolean g_mime_certificate_list_remove_at (GMimeCertificateList *list, int index);
+
+gboolean g_mime_certificate_list_contains (GMimeCertificateList *list, GMimeCertificate *cert);
+int g_mime_certificate_list_index_of (GMimeCertificateList *list, GMimeCertificate *cert);
+
+GMimeCertificate *g_mime_certificate_list_get_cert (GMimeCertificateList *list, int index);
+void g_mime_certificate_list_set_cert (GMimeCertificateList *list, int index, GMimeCertificate *cert);
+
+G_END_DECLS
+
+#endif /* __GMIME_CERTIFICATE_H__ */
diff --git a/gmime/gmime-signature.c b/gmime/gmime-signature.c
new file mode 100644
index 0000000..d7695d9
--- /dev/null
+++ b/gmime/gmime-signature.c
@@ -0,0 +1,634 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*  GMime
+ *  Copyright (C) 2000-2011 Jeffrey Stedfast
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1
+ *  of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+ *  02110-1301, USA.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "gmime-signature.h"
+
+
+/**
+ * SECTION: gmime-signature
+ * @title: GMimeSignature
+ * @short_description: Digital signatures
+ * @see_also:
+ *
+ * A #GMimeSignature is an object containing useful information about a
+ * digital signature as used in signing and encrypting data.
+ **/
+
+
+static void g_mime_signature_class_init (GMimeSignatureClass *klass);
+static void g_mime_signature_init (GMimeSignature *sig, GMimeSignatureClass *klass);
+static void g_mime_signature_finalize (GObject *object);
+
+static GObjectClass *parent_class = NULL;
+
+
+GType
+g_mime_signature_get_type (void)
+{
+	static GType type = 0;
+	
+	if (!type) {
+		static const GTypeInfo info = {
+			sizeof (GMimeSignatureClass),
+			NULL, /* base_class_init */
+			NULL, /* base_class_finalize */
+			(GClassInitFunc) g_mime_signature_class_init,
+			NULL, /* class_finalize */
+			NULL, /* class_data */
+			sizeof (GMimeSignature),
+			0,    /* n_preallocs */
+			(GInstanceInitFunc) g_mime_signature_init,
+		};
+		
+		type = g_type_register_static (G_TYPE_OBJECT, "GMimeSignature", &info, 0);
+	}
+	
+	return type;
+}
+
+static void
+g_mime_signature_class_init (GMimeSignatureClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	
+	parent_class = g_type_class_ref (G_TYPE_OBJECT);
+	
+	object_class->finalize = g_mime_signature_finalize;
+}
+
+static void
+g_mime_signature_init (GMimeSignature *sig, GMimeSignatureClass *klass)
+{
+	sig->status = GMIME_SIGNATURE_STATUS_GOOD;
+	sig->errors = GMIME_SIGNATURE_ERROR_NONE;
+	sig->created = (time_t) -1;
+	sig->expires = (time_t) -1;
+	sig->cert = NULL;
+}
+
+static void
+g_mime_signature_finalize (GObject *object)
+{
+	GMimeSignature *sig = (GMimeSignature *) object;
+	
+	if (sig->cert)
+		g_object_unref (sig->cert);
+	
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+
+/**
+ * g_mime_signature_new:
+ *
+ * Creates a new #GMimeSignature object.
+ * 
+ * Returns: a new #GMimeSignature object.
+ **/
+GMimeSignature *
+g_mime_signature_new (void)
+{
+	return g_object_newv (GMIME_TYPE_SIGNATURE, 0, NULL);
+}
+
+
+/**
+ * g_mime_signature_set_status:
+ * @sig: a #GMimeSignature
+ * @status: a #GMimeSignatureStatus
+ *
+ * Set the status on the signature.
+ **/
+void
+g_mime_signature_set_status (GMimeSignature *sig, GMimeSignatureStatus status)
+{
+	g_return_if_fail (GMIME_IS_SIGNATURE (sig));
+	
+	sig->status = status;
+}
+
+
+/**
+ * g_mime_signature_get_status:
+ * @sig: a #GMimeSignature
+ *
+ * Get the signature status.
+ *
+ * Returns: the signature status.
+ **/
+GMimeSignatureStatus
+g_mime_signature_get_status (GMimeSignature *sig)
+{
+	g_return_val_if_fail (GMIME_IS_SIGNATURE (sig), GMIME_SIGNATURE_STATUS_BAD);
+	
+	return sig->status;
+}
+
+
+/**
+ * g_mime_signature_set_errors:
+ * @sig: a #GMimeSignature
+ * @error: a #GMimeSignatureError
+ *
+ * Set the errors on the signature.
+ **/
+void
+g_mime_signature_set_errors (GMimeSignature *sig, GMimeSignatureError errors)
+{
+	g_return_if_fail (GMIME_IS_SIGNATURE (sig));
+	
+	sig->errors = errors;
+}
+
+
+/**
+ * g_mime_signature_get_errors:
+ * @sig: a #GMimeSignature
+ *
+ * Get the signature errors. If the #GMimeSignatureStatus returned from
+ * g_mime_signature_get_status() is not #GMIME_SIGNATURE_STATUS_GOOD, then the
+ * errors may provide a clue as to why.
+ *
+ * Returns: a bitfield of errors.
+ **/
+GMimeSignatureError
+g_mime_signature_get_errors (GMimeSignature *sig)
+{
+	g_return_val_if_fail (GMIME_IS_SIGNATURE (sig), GMIME_SIGNATURE_ERROR_NONE);
+	
+	return sig->errors;
+}
+
+
+/**
+ * g_mime_signature_set_certificate:
+ * @sig: a #GMimeSignature
+ * @cert: a #GMimeCertificate
+ *
+ * Set the signature's certificate.
+ **/
+void
+g_mime_signature_set_certificate (GMimeSignature *sig, GMimeCertificate *cert)
+{
+	g_return_if_fail (GMIME_IS_SIGNATURE (sig));
+	g_return_if_fail (GMIME_IS_CERTIFICATE (cert));
+	
+	if (sig->cert == cert)
+		return;
+	
+	if (sig->cert != NULL)
+		g_object_unref (sig->cert);
+	
+	if (cert != NULL)
+		g_object_ref (cert);
+	
+	sig->cert = cert;
+}
+
+
+/**
+ * g_mime_signature_get_certificate:
+ * @sig: a #GMimeSignature
+ *
+ * Get the signature's certificate.
+ *
+ * Returns: the signature's certificate.
+ **/
+GMimeCertificate *
+g_mime_signature_get_certificate (GMimeSignature *sig)
+{
+	g_return_val_if_fail (GMIME_IS_SIGNATURE (sig), NULL);
+	
+	return sig->cert;
+}
+
+
+/**
+ * g_mime_signature_set_created:
+ * @sig: a #GMimeSignature
+ * @created: creation date
+ *
+ * Set the creation date of the signature.
+ **/
+void
+g_mime_signature_set_created (GMimeSignature *sig, time_t created)
+{
+	g_return_if_fail (GMIME_IS_SIGNATURE (sig));
+	
+	sig->created = created;
+}
+
+
+/**
+ * g_mime_signature_get_created:
+ * @sig: a #GMimeSignature
+ *
+ * Get the creation date of the signature.
+ *
+ * Returns: the creation date of the signature or %-1 if unknown.
+ **/
+time_t
+g_mime_signature_get_created (GMimeSignature *sig)
+{
+	g_return_val_if_fail (GMIME_IS_SIGNATURE (sig), (time_t) -1);
+	
+	return sig->created;
+}
+
+
+/**
+ * g_mime_signature_set_expires:
+ * @sig: a #GMimeSignature
+ * @expires: expiration date
+ *
+ * Set the expiration date of the signature.
+ **/
+void
+g_mime_signature_set_expires (GMimeSignature *sig, time_t expires)
+{
+	g_return_if_fail (GMIME_IS_SIGNATURE (sig));
+	
+	sig->expires = expires;
+}
+
+
+/**
+ * g_mime_signature_get_expires:
+ * @sig: a #GMimeSignature
+ *
+ * Get the expiration date of the signature.
+ *
+ * Returns: the expiration date of the signature or %-1 if unknown.
+ **/
+time_t
+g_mime_signature_get_expires (GMimeSignature *sig)
+{
+	g_return_val_if_fail (GMIME_IS_SIGNATURE (sig), (time_t) -1);
+	
+	return sig->expires;
+}
+
+
+static void g_mime_signature_list_class_init (GMimeSignatureListClass *klass);
+static void g_mime_signature_list_init (GMimeSignatureList *list, GMimeSignatureListClass *klass);
+static void g_mime_signature_list_finalize (GObject *object);
+
+
+static GObjectClass *list_parent_class = NULL;
+
+
+GType
+g_mime_signature_list_get_type (void)
+{
+	static GType type = 0;
+	
+	if (!type) {
+		static const GTypeInfo info = {
+			sizeof (GMimeSignatureListClass),
+			NULL, /* base_class_init */
+			NULL, /* base_class_finalize */
+			(GClassInitFunc) g_mime_signature_list_class_init,
+			NULL, /* class_finalize */
+			NULL, /* class_data */
+			sizeof (GMimeSignatureList),
+			0,    /* n_preallocs */
+			(GInstanceInitFunc) g_mime_signature_list_init,
+		};
+		
+		type = g_type_register_static (G_TYPE_OBJECT, "GMimeSignatureList", &info, 0);
+	}
+	
+	return type;
+}
+
+
+static void
+g_mime_signature_list_class_init (GMimeSignatureListClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	
+	list_parent_class = g_type_class_ref (G_TYPE_OBJECT);
+	
+	object_class->finalize = g_mime_signature_list_finalize;
+}
+
+static void
+g_mime_signature_list_init (GMimeSignatureList *list, GMimeSignatureListClass *klass)
+{
+	list->array = g_ptr_array_new ();
+}
+
+static void
+g_mime_signature_list_finalize (GObject *object)
+{
+	GMimeSignatureList *list = (GMimeSignatureList *) object;
+	GMimeSignature *sig;
+	guint i;
+	
+	for (i = 0; i < list->array->len; i++) {
+		sig = (GMimeSignature *) list->array->pdata[i];
+		g_object_unref (sig);
+	}
+	
+	g_ptr_array_free (list->array, TRUE);
+	
+	G_OBJECT_CLASS (list_parent_class)->finalize (object);
+}
+
+
+/**
+ * g_mime_signature_list_new:
+ *
+ * Creates a new #GMimeSignatureList.
+ *
+ * Returns: a new #GMimeSignatureList.
+ **/
+GMimeSignatureList *
+g_mime_signature_list_new (void)
+{
+	return g_object_newv (GMIME_TYPE_SIGNATURE_LIST, 0, NULL);
+}
+
+
+/**
+ * g_mime_signature_list_length:
+ * @list: a #GMimeSignatureList
+ *
+ * Gets the length of the list.
+ *
+ * Returns: the number of #GMimeSignature objects in the list.
+ **/
+int
+g_mime_signature_list_length (GMimeSignatureList *list)
+{
+	g_return_val_if_fail (IS_G_MIME_SIGNATURE_LIST (list), -1);
+	
+	return list->array->len;
+}
+
+
+/**
+ * g_mime_signature_list_clear:
+ * @list: a #GMimeSignatureList
+ *
+ * Clears the list of addresses.
+ **/
+void
+g_mime_signature_list_clear (GMimeSignatureList *list)
+{
+	GMimeSignature *sig;
+	guint i;
+	
+	g_return_if_fail (IS_G_MIME_SIGNATURE_LIST (list));
+	
+	for (i = 0; i < list->array->len; i++) {
+		sig = (GMimeSignature *) list->array->pdata[i];
+		g_object_unref (sig);
+	}
+	
+	g_ptr_array_set_size (list->array, 0);
+}
+
+
+/**
+ * g_mime_signature_list_add:
+ * @list: a #GMimeSignatureList
+ * @sig: a #GMimeSignature
+ *
+ * Adds a #GMimeSignature to the #GMimeSignatureList.
+ *
+ * Returns: the index of the added #GMimeSignature.
+ **/
+int
+g_mime_signature_list_add (GMimeSignatureList *list, GMimeSignature *sig)
+{
+	int index;
+	
+	g_return_val_if_fail (GMIME_IS_SIGNATURE_LIST (list), -1);
+	g_return_val_if_fail (GMIME_IS_SIGNATURE (sig), -1);
+	
+	index = list->array->len;
+	g_ptr_array_add (list->array, sig);
+	g_object_ref (sig);
+	
+	return index;
+}
+
+
+/**
+ * g_mime_signature_list_insert:
+ * @list: a #GMimeSignatureList
+ * @index: index to insert at
+ * @sig: a #GMimeSignature
+ *
+ * Inserts a #GMimeSignature into the #GMimeSignatureList at the specified
+ * index.
+ **/
+void
+g_mime_signature_list_insert (GMimeSignatureList *list, int index, GMimeSignature *sig)
+{
+	char *dest, *src;
+	size_t n;
+	
+	g_return_if_fail (GMIME_IS_SIGNATURE_LIST (list));
+	g_return_if_fail (GMIME_IS_SIGNATURE (sig));
+	g_return_if_fail (index >= 0);
+	
+	if ((guint) index < list->array->len) {
+		g_ptr_array_set_size (list->array, list->array->len + 1);
+		
+		dest = ((char *) list->array->pdata) + (sizeof (void *) * (index + 1));
+		src = ((char *) list->array->pdata) + (sizeof (void *) * index);
+		n = list->array->len - index - 1;
+		
+		g_memmove (dest, src, (sizeof (void *) * n));
+		list->array->pdata[index] = sig;
+	} else {
+		/* the easy case */
+		g_ptr_array_add (list->array, sig);
+	}
+	
+	g_object_ref (sig);
+}
+
+
+/**
+ * g_mime_signature_list_remove:
+ * @list: a #GMimeSignatureList
+ * @sig: a #GMimeSignature
+ *
+ * Removes a #GMimeSignature from the #GMimeSignatureList.
+ *
+ * Returns: %TRUE if the specified #GMimeSignature was removed or %FALSE
+ * otherwise.
+ **/
+gboolean
+g_mime_signature_list_remove (GMimeSignatureList *list, GMimeSignature *sig)
+{
+	int index;
+	
+	g_return_val_if_fail (GMIME_IS_SIGNATURE_LIST (list), FALSE);
+	g_return_val_if_fail (GMIME_IS_SIGNATURE (sig), FALSE);
+	
+	if ((index = g_mime_signature_list_index_of (list, sig)) == -1)
+		return FALSE;
+	
+	g_mime_signature_list_remove_at (list, index);
+	
+	return TRUE;
+}
+
+
+/**
+ * g_mime_signature_list_remove_at:
+ * @list: a #GMimeSignatureList
+ * @index: index to remove
+ *
+ * Removes a #GMimeSignature from the #GMimeSignatureList at the specified
+ * index.
+ *
+ * Returns: %TRUE if an #GMimeSignature was removed or %FALSE otherwise.
+ **/
+gboolean
+g_mime_signature_list_remove_at (GMimeSignatureList *list, int index)
+{
+	GMimeSignature *sig;
+	
+	g_return_val_if_fail (GMIME_IS_SIGNATURE_LIST (list), FALSE);
+	g_return_val_if_fail (index >= 0, FALSE);
+	
+	if ((guint) index >= list->array->len)
+		return FALSE;
+	
+	sig = list->array->pdata[index];
+	g_ptr_array_remove_index (list->array, index);
+	g_object_unref (sig);
+	
+	return TRUE;
+}
+
+
+/**
+ * g_mime_signature_list_contains:
+ * @list: a #GMimeSignatureList
+ * @sig: a #GMimeSignature
+ *
+ * Checks whether or not the specified #GMimeSignature is contained within
+ * the #GMimeSignatureList.
+ *
+ * Returns: %TRUE if the specified #GMimeSignature is contained within the
+ * specified #GMimeSignatureList or %FALSE otherwise.
+ **/
+gboolean
+g_mime_signature_list_contains (GMimeSignatureList *list, GMimeSignature *sig)
+{
+	return g_mime_signature_list_index_of (list, sig) != -1;
+}
+
+
+/**
+ * g_mime_signature_list_index_of:
+ * @list: a #GMimeSignatureList
+ * @sig: a #GMimeSignature
+ *
+ * Gets the index of the specified #GMimeSignature inside the
+ * #GMimeSignatureList.
+ *
+ * Returns: the index of the requested #GMimeSignature within the
+ * #GMimeSignatureList or %-1 if it is not contained within the
+ * #GMimeSignatureList.
+ **/
+int
+g_mime_signature_list_index_of (GMimeSignatureList *list, GMimeSignature *sig)
+{
+	guint i;
+	
+	g_return_val_if_fail (GMIME_IS_SIGNATURE_LIST (list), -1);
+	g_return_val_if_fail (GMIME_IS_SIGNATURE (sig), -1);
+	
+	for (i = 0; i < list->array->len; i++) {
+		if (list->array->pdata[i] == sig)
+			return i;
+	}
+	
+	return -1;
+}
+
+
+/**
+ * g_mime_signature_list_get_signature:
+ * @list: a #GMimeSignatureList
+ * @index: index of #GMimeSignature to get
+ *
+ * Gets the #GMimeSignature at the specified index.
+ *
+ * Returns: the #GMimeSignature at the specified index or %NULL if
+ * the index is out of range.
+ **/
+GMimeSignature *
+g_mime_signature_list_get_signature (GMimeSignatureList *list, int index)
+{
+	g_return_val_if_fail (GMIME_IS_SIGNATURE_LIST (list), NULL);
+	g_return_val_if_fail (index >= 0, NULL);
+	
+	if ((guint) index >= list->array->len)
+		return NULL;
+	
+	return list->array->pdata[index];
+}
+
+
+/**
+ * g_mime_signature_list_set_signature:
+ * @list: a #GMimeSignatureList
+ * @index: index of #GMimeSignature to set
+ * @sig: a #GMimeSignature
+ *
+ * Sets the #GMimeSignature at the specified index to @sig.
+ **/
+void
+g_mime_signature_list_set_signature (GMimeSignatureList *list, int index, GMimeSignature *sig)
+{
+	GMimeSignature *old;
+	
+	g_return_if_fail (GMIME_IS_SIGNATURE_LIST (list));
+	g_return_if_fail (GMIME_IS_SIGNATURE (sig));
+	g_return_if_fail (index >= 0);
+	
+	if ((guint) index > list->array->len)
+		return;
+	
+	if ((guint) index == list->array->len) {
+		g_mime_signature_list_add (list, sig);
+		return;
+	}
+	
+	if ((old = list->array->pdata[index]) == sig)
+		return;
+	
+	list->array->pdata[index] = sig;
+	g_object_unref (old);
+	g_object_ref (sig);
+}
diff --git a/gmime/gmime-signature.h b/gmime/gmime-signature.h
new file mode 100644
index 0000000..2baf9c1
--- /dev/null
+++ b/gmime/gmime-signature.h
@@ -0,0 +1,172 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*  GMime
+ *  Copyright (C) 2000-2011 Jeffrey Stedfast
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1
+ *  of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+ *  02110-1301, USA.
+ */
+
+
+#ifndef __GMIME_SIGNATURE_H__
+#define __GMIME_SIGNATURE_H__
+
+#include <gmime/gmime-certificate.h>
+
+G_BEGIN_DECLS
+
+#define GMIME_TYPE_SIGNATURE                  (g_mime_signature_get_type ())
+#define GMIME_SIGNATURE(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMIME_TYPE_SIGNATURE, GMimeSignature))
+#define GMIME_SIGNATURE_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GMIME_TYPE_SIGNATURE, GMimeSignatureClass))
+#define GMIME_IS_SIGNATURE(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GMIME_TYPE_SIGNATURE))
+#define GMIME_IS_SIGNATURE_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GMIME_TYPE_SIGNATURE))
+#define GMIME_SIGNATURE_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GMIME_TYPE_SIGNATURE, GMimeSignatureClass))
+
+#define GMIME_TYPE_SIGNATURE_LIST             (g_mime_signature_list_get_type ())
+#define GMIME_SIGNATURE_LIST(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMIME_TYPE_SIGNATURE_LIST, GMimeSignatureList))
+#define GMIME_SIGNATURE_LIST_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GMIME_TYPE_SIGNATURE_LIST, GMimeSignatureListClass))
+#define GMIME_IS_SIGNATURE_LIST(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GMIME_TYPE_SIGNATURE_LIST))
+#define GMIME_IS_SIGNATURE_LIST_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GMIME_TYPE_SIGNATURE_LIST))
+
+
+typedef struct _GMimeSignature GMimeSignature;
+typedef struct _GMimeSignatureClass GMimeSignatureClass;
+
+typedef struct _GMimeSignatureList GMimeSignatureList;
+typedef struct _GMimeSignatureListClass GMimeSignatureListClass;
+
+
+/**
+ * GMimeSignatureStatus:
+ * @GMIME_SIGNATURE_STATUS_GOOD: Good signature.
+ * @GMIME_SIGNATURE_STATUS_ERROR: An error occurred.
+ * @GMIME_SIGNATURE_STATUS_BAD: Bad signature.
+ *
+ * A value representing the signature status for a particular
+ * #GMimeSignature.
+ **/
+typedef enum {
+	GMIME_SIGNATURE_STATUS_GOOD,
+	GMIME_SIGNATURE_STATUS_ERROR,
+	GMIME_SIGNATURE_STATUS_BAD
+} GMimeSignatureStatus;
+
+
+/**
+ * GMimeSignatureError:
+ * @GMIME_SIGNATURE_ERROR_NONE: No error.
+ * @GMIME_SIGNATURE_ERROR_EXPSIG: Expired signature.
+ * @GMIME_SIGNATURE_ERROR_NO_PUBKEY: No public key found.
+ * @GMIME_SIGNATURE_ERROR_EXPKEYSIG: Expired signature key.
+ * @GMIME_SIGNATURE_ERROR_REVKEYSIG: Revoked signature key.
+ * @GMIME_SIGNATURE_ERROR_UNSUPP_ALGO: Unsupported algorithm.
+ *
+ * Possible errors that a #GMimeSignature could have.
+ **/
+typedef enum {
+	GMIME_SIGNATURE_ERROR_NONE        = 0,
+	GMIME_SIGNATURE_ERROR_EXPSIG      = (1 << 0),  /* expired signature */
+	GMIME_SIGNATURE_ERROR_NO_PUBKEY   = (1 << 1),  /* no public key */
+	GMIME_SIGNATURE_ERROR_EXPKEYSIG   = (1 << 2),  /* expired key */
+	GMIME_SIGNATURE_ERROR_REVKEYSIG   = (1 << 3),  /* revoked key */
+	GMIME_SIGNATURE_ERROR_UNSUPP_ALGO = (1 << 4)   /* unsupported algorithm */
+} GMimeSignatureError;
+
+
+/**
+ * GMimeSignature:
+ * @status: A #GMimeSignatureStatus.
+ * @errors: A bitfield of #GMimeSignatureError values.
+ * @cert: The #GMimeCertificate used in the signature.
+ * @created: The creation date of the signature.
+ * @expires: The expiration date of the signature.
+ *
+ * An object containing useful information about a signature.
+ **/
+struct _GMimeSignature {
+	GObject parent_object;
+	
+	GMimeSignatureStatus status;
+	GMimeSignatureError errors;
+	GMimeCertificate *cert;
+	time_t created;
+	time_t expires;
+};
+
+struct _GMimeSignatureClass {
+	GObjectClass parent_class;
+	
+};
+
+
+GType g_mime_signature_get_type (void);
+
+GMimeSignature *g_mime_signature_new (void);
+
+void g_mime_signature_set_certificate (GMimeSignature *sig, GMimeCertificate *cert);
+GMimeCertificate *g_mime_signature_get_certificate (GMimeSignature *sig);
+
+void g_mime_signature_set_status (GMimeSignature *sig, GMimeSignatureStatus status);
+GMimeSignatureStatus g_mime_signature_get_status (GMimeSignature *sig);
+
+void g_mime_signature_set_errors (GMimeSignature *sig, GMimeSignatureError errors);
+GMimeSignatureError g_mime_signature_get_errors (GMimeSignature *sig);
+
+void g_mime_signature_set_created (GMimeSignature *sig, time_t created);
+time_t g_mime_signature_get_created (GMimeSignature *sig);
+
+void g_mime_signature_set_expires (GMimeSignature *sig, time_t expires);
+time_t g_mime_signature_get_expires (GMimeSignature *sig);
+
+
+/**
+ * GMimeSignatureList:
+ * @parent_object: parent #GObject
+ * @array: An array of #GMimeSignature objects.
+ *
+ * A collection of #GMimeSignature objects.
+ **/
+struct _GMimeSignatureList {
+	GObject parent_object;
+	GPtrArray *array;
+};
+
+struct _GMimeSignatureListClass {
+	GObjectClass parent_class;
+	
+};
+
+
+GType g_mime_signature_list_get_type (void);
+
+GMimeSignatureList *g_mime_signature_list_new (void);
+
+int g_mime_signature_list_length (GMimeSignatureList *list);
+
+void g_mime_signature_list_clear (GMimeSignatureList *list);
+
+int g_mime_signature_list_add (GMimeSignatureList *list, GMimeSignature *sig);
+void g_mime_signature_list_insert (GMimeSignatureList *list, int index, GMimeSignature *sig);
+gboolean g_mime_signature_list_remove (GMimeSignatureList *list, GMimeSignature *sig);
+gboolean g_mime_signature_list_remove_at (GMimeSignatureList *list, int index);
+
+gboolean g_mime_signature_list_contains (GMimeSignatureList *list, GMimeSignature *sig);
+int g_mime_signature_list_index_of (GMimeSignatureList *list, GMimeSignature *sig);
+
+GMimeSignature *g_mime_signature_list_get_signature (GMimeSignatureList *list, int index);
+void g_mime_signature_list_set_signature (GMimeSignatureList *list, int index, GMimeSignature *sig);
+
+G_END_DECLS
+
+#endif /* __GMIME_SIGNATURE_H__ */



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