[gmime] Added the start of a GMimeApplicationPkcs7Mime class
- From: Jeffrey Stedfast <fejj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gmime] Added the start of a GMimeApplicationPkcs7Mime class
- Date: Fri, 30 Jan 2015 20:23:41 +0000 (UTC)
commit 48d11fdffb39e61bf5f1fc130a35482110b42401
Author: Jeffrey Stedfast <jeff xamarin com>
Date: Fri Jan 30 15:23:12 2015 -0500
Added the start of a GMimeApplicationPkcs7Mime class
gmime/gmime-application-pkcs7-mime.c | 216 ++++++++++++++++++++++++++++++++++
gmime/gmime-application-pkcs7-mime.h | 100 ++++++++++++++++
2 files changed, 316 insertions(+), 0 deletions(-)
---
diff --git a/gmime/gmime-application-pkcs7-mime.c b/gmime/gmime-application-pkcs7-mime.c
new file mode 100644
index 0000000..10ccebe
--- /dev/null
+++ b/gmime/gmime-application-pkcs7-mime.c
@@ -0,0 +1,216 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* GMime
+ * Copyright (C) 2000-2014 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
+
+/**
+ * SECTION: gmime-application-pkcs7-mime
+ * @title: GMimeApplicationPkcs7Mime
+ * @short_description: Pkcs7 MIME parts
+ * @see_also:
+ *
+ * A #GMimeApplicationPkcs7Mime represents the application/pkcs7-mime MIME part.
+ **/
+
+/* GObject class methods */
+static void g_mime_application_pkcs7_mime_class_init (GMimeApplicationPkcs7MimeClass *klass);
+static void g_mime_application_pkcs7_mime_init (GMimeApplicationPkcs7Mime *catpart,
GMimeApplicationPkcs7MimeClass *klass);
+static void g_mime_application_pkcs7_mime_finalize (GObject *object);
+
+/* GMimeObject class methods */
+static void application_pkcs7_mime_prepend_header (GMimeObject *object, const char *header, const char
*value);
+static void application_pkcs7_mime_append_header (GMimeObject *object, const char *header, const char
*value);
+static void application_pkcs7_mime_set_header (GMimeObject *object, const char *header, const char *value);
+static const char *application_pkcs7_mime_get_header (GMimeObject *object, const char *header);
+static gboolean application_pkcs7_mime_remove_header (GMimeObject *object, const char *header);
+static void application_pkcs7_mime_set_content_type (GMimeObject *object, GMimeContentType *content_type);
+
+
+static GMimePartClass *parent_class = NULL;
+
+
+GType
+g_mime_application_pkcs7_mime_get_type (void)
+{
+ static GType type = 0;
+
+ if (!type) {
+ static const GTypeInfo info = {
+ sizeof (GMimeApplicationPkcs7MimeClass),
+ NULL, /* base_class_init */
+ NULL, /* base_class_finalize */
+ (GClassInitFunc) g_mime_application_pkcs7_mime_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (GMimeApplicationPkcs7Mime),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) g_mime_application_pkcs7_mime_init,
+ };
+
+ type = g_type_register_static (GMIME_TYPE_PART, "GMimeApplicationPkcs7Mime", &info, 0);
+ }
+
+ return type;
+}
+
+
+static void
+g_mime_application_pkcs7_mime_class_init (GMimeApplicationPkcs7MimeClass *klass)
+{
+ GMimeObjectClass *object_class = GMIME_OBJECT_CLASS (klass);
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ parent_class = g_type_class_ref (GMIME_TYPE_PART);
+
+ gobject_class->finalize = g_mime_application_pkcs7_mime_finalize;
+
+ object_class->prepend_header = application_pkcs7_mime_prepend_header;
+ object_class->append_header = application_pkcs7_mime_append_header;
+ object_class->remove_header = application_pkcs7_mime_remove_header;
+ object_class->set_header = application_pkcs7_mime_set_header;
+ object_class->get_header = application_pkcs7_mime_get_header;
+ object_class->set_content_type = application_pkcs7_mime_set_content_type;
+}
+
+static void
+g_mime_application_pkcs7_mime_init (GMimeApplicationPkcs7Mime *pkcs7_mime, GMimeApplicationPkcs7MimeClass
*klass)
+{
+ pkcs7_mime->smime_type = GMIME_SECURE_MIME_TYPE_UNKNOWN;
+}
+
+static void
+g_mime_application_pkcs7_mime_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+application_pkcs7_mime_prepend_header (GMimeObject *object, const char *header, const char *value)
+{
+ GMIME_OBJECT_CLASS (parent_class)->prepend_header (object, header, value);
+}
+
+static void
+application_pkcs7_mime_append_header (GMimeObject *object, const char *header, const char *value)
+{
+ GMIME_OBJECT_CLASS (parent_class)->append_header (object, header, value);
+}
+
+static void
+application_pkcs7_mime_set_header (GMimeObject *object, const char *header, const char *value)
+{
+ GMIME_OBJECT_CLASS (parent_class)->set_header (object, header, value);
+}
+
+static const char *
+application_pkcs7_mime_get_header (GMimeObject *object, const char *header)
+{
+ return GMIME_OBJECT_CLASS (parent_class)->get_header (object, header);
+}
+
+static gboolean
+application_pkcs7_mime_remove_header (GMimeObject *object, const char *header)
+{
+ return GMIME_OBJECT_CLASS (parent_class)->remove_header (object, header);
+}
+
+static void
+application_pkcs7_mime_set_content_type (GMimeObject *object, GMimeContentType *content_type)
+{
+ GMimeApplicationPkcs7Mime *pkcs7_mime = (GMimeApplicationPkcs7Mime *) object;
+ const char *value;
+
+ if ((value = g_mime_content_type_get_parameter (content_type, "smime-type")) != NULL) {
+ if (!g_ascii_strcasecmp (value, "compressed-data"))
+ pkcs7_mime->smime_type = GMIME_SECURE_MIME_TYPE_COMPRESSED_DATA;
+ else if (!g_ascii_strcasecmp (value, "enveloped-data"))
+ pkcs7_mime->smime_type = GMIME_SECURE_MIME_TYPE_ENVELOPED_DATA;
+ else if (!g_ascii_strcasecmp (value, "signed-data"))
+ pkcs7_mime->smime_type = GMIME_SECURE_MIME_TYPE_SIGNED_DATA;
+ else if (!g_ascii_strcasecmp (value, "certs-only"))
+ pkcs7_mime->smime_type = GMIME_SECURE_MIME_TYPE_CERTS_ONLY;
+ else
+ pkcs7_mime->smime_type = GMIME_SECURE_MIME_TYPE_UNKNOWN;
+ } else {
+ pkcs7_mime->smime_type = GMIME_SECURE_MIME_TYPE_UNKNOWN;
+ }
+
+ GMIME_OBJECT_CLASS (parent_class)->set_content_type (object, content_type);
+}
+
+/**
+ * g_mime_application_pkcs7_mime_new:
+ * @type: The type of S/MIME data contained within the part.
+ *
+ * Creates a new application/pkcs7-mime object.
+ *
+ * Returns: an empty application/pkcs7-mime object.
+ **/
+GMimeApplicationPkcs7Mime *
+g_mime_application_pkcs7_mime_new (GMimeSecureMimeType type)
+{
+ GMimeApplicationPkcs7Mime *pkcs7_mime;
+ GMimeContentType *content_type;
+
+ pkcs7_mime = g_object_newv (GMIME_TYPE_APPLICATION_PKCS7_MIME, 0, NULL);
+ content_type = g_mime_content_type_new ("application", "pkcs7-mime");
+
+ switch (type) {
+ case GMIME_SECURE_MIME_TYPE_COMPRESSED_DATA:
+ g_mime_content_type_set_parameter (content_type, "smime-type", "compressed-data");
+ break;
+ case GMIME_SECURE_MIME_TYPE_ENVELOPED_DATA:
+ g_mime_content_type_set_parameter (content_type, "smime-type", "enveloped-data");
+ break;
+ case GMIME_SECURE_MIME_TYPE_SIGNED_DATA:
+ g_mime_content_type_set_parameter (content_type, "smime-type", "signed-data");
+ break;
+ case GMIME_SECURE_MIME_TYPE_CERTS_ONLY:
+ g_mime_content_type_set_parameter (content_type, "smime-type", "certs-only");
+ break;
+ default:
+ break;
+ }
+
+ g_mime_object_set_content_type (GMIME_OBJECT (pkcs7_mime), content_type);
+ g_object_unref (content_type);
+
+ return pkcs7_mime;
+}
+
+
+/**
+ * g_mime_application_pkcs7_mime_get_smime_type:
+ * @pkcs7_mime: A #GMimeApplicationPkcs7Mime object
+ *
+ * Gets the smime-type value of the Content-Type header.
+ *
+ * Returns: the smime-type value.
+ **/
+GMimeSecureMimeType
+g_mime_application_pkcs7_mime_get_smime_type (GMimeApplicationPkcs7Mime *pkcs7_mime)
+{
+ g_return_val_if_fail (GMIME_IS_APPLICATION_PKCS7_MIME (pkcs7_mime), GMIME_SECURE_MIME_TYPE_UNKNOWN);
+
+ return pkcs7_mime->smime_type;
+}
diff --git a/gmime/gmime-application-pkcs7-mime.h b/gmime/gmime-application-pkcs7-mime.h
new file mode 100644
index 0000000..51c23ff
--- /dev/null
+++ b/gmime/gmime-application-pkcs7-mime.h
@@ -0,0 +1,100 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* GMime
+ * Copyright (C) 2000-2014 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_APPLICATION_PKCS7_MIME_H__
+#define __GMIME_APPLICATION_PKCS7_MIME_H__
+
+#include <glib.h>
+
+#include <gmime/gmime-part.h>
+#include <gmime/gmime-pkcs7-context.h>
+
+G_BEGIN_DECLS
+
+#define GMIME_TYPE_APPLICATION_PKCS7_MIME (g_mime_application_pkcs7_mime_get_type ())
+#define GMIME_APPLICATION_PKCS7_MIME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GMIME_TYPE_APPLICATION_PKCS7_MIME, GMimeApplicationPkcs7Mime))
+#define GMIME_APPLICATION_PKCS7_MIME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GMIME_TYPE_APPLICATION_PKCS7_MIME, GMimeApplicationPkcs7MimeClass))
+#define GMIME_IS_APPLICATION_PKCS7_MIME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GMIME_TYPE_APPLICATION_PKCS7_MIME))
+#define GMIME_IS_APPLICATION_PKCS7_MIME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GMIME_TYPE_APPLICATION_PKCS7_MIME))
+#define GMIME_APPLICATION_PKCS7_MIME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GMIME_TYPE_APPLICATION_PKCS7_MIME, GMimeApplicationPkcs7MimeClass))
+
+typedef struct _GMimeApplicationPkcs7Mime GMimeApplicationPkcs7Mime;
+typedef struct _GMimeApplicationPkcs7MimeClass GMimeApplicationPkcs7MimeClass;
+
+/**
+ * GMimeSecureMimeType:
+ * @GMIME_SECURE_MIME_TYPE_COMPRESSED_DATA: The S/MIME content contains compressed data.
+ * @GMIME_SECURE_MIME_TYPE_ENVELOPED_DATA: The S/MIME content contains enveloped data.
+ * @GMIME_SECURE_MIME_TYPE_SIGNED_DATA: The S/MIME content contains signed data.
+ * @GMIME_SECURE_MIME_TYPE_CERTS_ONLY: The S/MIME content contains only certificates.
+ * @GMIME_SECURE_MIME_TYPE_UNKNOWN: The S/MIME content is unknown.
+ *
+ * The S/MIME data type.
+ **/
+typedef enum _GMimeSecureMimeType {
+ GMIME_SECURE_MIME_TYPE_COMPRESSED_DATA,
+ GMIME_SECURE_MIME_TYPE_ENVELOPED_DATA,
+ GMIME_SECURE_MIME_TYPE_SIGNED_DATA,
+ GMIME_SECURE_MIME_TYPE_CERTS_ONLY,
+ GMIME_SECURE_MIME_TYPE_UNKNOWN,
+} GMimeSecureMimeType;
+
+/**
+ * GMimeApplicationPkcs7Mime:
+ * @parent_object: parent #GMimePart object
+ *
+ * An application/pkcs7-mime MIME part.
+ **/
+struct _GMimeApplicationPkcs7Mime {
+ GMimePart parent_object;
+
+ GMimeSecureMimeType smime_type;
+};
+
+struct _GMimeApplicationPkcs7MimeClass {
+ GMimePartClass parent_class;
+
+};
+
+
+GType g_mime_application_pkcs7_mime_get_type (void);
+
+GMimeApplicationPkcs7Mime *g_mime_application_pkcs7_mime_new (GMimeSecureMimeType type);
+
+GMimeSecureMimeType g_mime_application_pkcs7_mime_get_smime_type (GMimeApplicationPkcs7Mime *pkcs7_mime);
+
+/*GMimeApplicationPkcs7Mime *g_mime_application_pkcs7_mime_compress (GMimePkcs7Context *ctx, GMimeObject
*entity, GError **err);*/
+/*GMimeObject *g_mime_application_pkcs7_mime_decompress (GMimeApplicationPkcs7Mime *pkcs7_mime,
GMimePkcs7Context *ctx);*/
+
+GMimeApplicationPkcs7Mime *g_mime_application_pkcs7_mime_encrypt (GMimePkcs7Context *ctx, GMimeObject
*entity,
+ GPtrArray *recipients, GError **err);
+GMimeObject *g_mime_application_pkcs7_mime_decrypt (GMimeApplicationPkcs7Mime *pkcs7_mime,
GMimeCryptoContext *ctx,
+ GMimeDecryptResult **result, GError **err);
+
+GMimeApplicationPkcs7Mime *g_mime_application_pkcs7_mime_sign (GMimePkcs7Context *ctx, GMimeObject *entity,
+ const char *userid, GMimeDigestAlgo digest,
+ GError **err);
+GMimeSignatureList *g_mime_application_pkcs7_mime_verify (GMimeApplicationPkcs7Mime *pkcs7_mime,
GMimeCryptoContext *ctx,
+ GMimeObject **entity, GError **err);
+
+G_END_DECLS
+
+#endif /* __GMIME_APPLICATION_PKCS7_MIME_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]