4
* Copyright (C) 2008 Stefan Walter
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as
8
* published by the Free Software Foundation; either version 2.1 of
9
* the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24
#include "gcr-certificate.h"
25
#include "gcr-comparable.h"
26
#include "gcr-internal.h"
27
#include "gcr-simple-certificate.h"
32
* SECTION:gcr-simple-certificate
33
* @title: GcrSimpleCertificate
34
* @short_description: A certificate loaded from a memory buffer
36
* An implementation of #GcrCertificate which loads a certificate from DER
37
* data already located in memory.
39
* To create a #GcrSimpleCertificate object use the
40
* gcr_simple_certificate_new() or gcr_simple_certificate_new_static()
45
* GcrSimpleCertificate:
47
* A #GcrCertificate which represents a certificate already in memory.
51
* GcrSimpleCertificateClass:
52
* @parent_class: The parent class
54
* The class for #GcrSimpleCertificate.
57
struct _GcrSimpleCertificatePrivate {
63
/* Forward declarations */
64
static void gcr_simple_certificate_iface_init (GcrCertificateIface *iface);
66
G_DEFINE_TYPE_WITH_CODE (GcrSimpleCertificate, gcr_simple_certificate, G_TYPE_OBJECT,
67
GCR_CERTIFICATE_MIXIN_IMPLEMENT_COMPARABLE ();
68
G_IMPLEMENT_INTERFACE (GCR_TYPE_CERTIFICATE, gcr_simple_certificate_iface_init);
71
/* -----------------------------------------------------------------------------
76
gcr_simple_certificate_init (GcrSimpleCertificate *self)
78
self->pv = G_TYPE_INSTANCE_GET_PRIVATE (self, GCR_TYPE_SIMPLE_CERTIFICATE, GcrSimpleCertificatePrivate);
82
gcr_simple_certificate_real_finalize (GObject *obj)
84
GcrSimpleCertificate *self = GCR_SIMPLE_CERTIFICATE (obj);
86
g_free (self->pv->owned);
87
self->pv->owned = NULL;
88
self->pv->data = NULL;
91
G_OBJECT_CLASS (gcr_simple_certificate_parent_class)->finalize (obj);
95
gcr_simple_certificate_class_init (GcrSimpleCertificateClass *klass)
97
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
99
gobject_class->finalize = gcr_simple_certificate_real_finalize;
100
gobject_class->get_property = gcr_certificate_mixin_get_property;
102
g_type_class_add_private (gobject_class, sizeof (GcrSimpleCertificatePrivate));
104
gcr_certificate_mixin_class_init (gobject_class);
105
_gcr_initialize_library ();
108
static const guchar *
109
gcr_simple_certificate_get_der_data (GcrCertificate *cert,
112
GcrSimpleCertificate *self = GCR_SIMPLE_CERTIFICATE (cert);
114
g_return_val_if_fail (GCR_IS_CERTIFICATE (self), NULL);
115
g_return_val_if_fail (n_data, NULL);
116
g_return_val_if_fail (self->pv->data, NULL);
118
/* This is called when we're not a base class */
119
*n_data = self->pv->n_data;
120
return self->pv->data;
124
gcr_simple_certificate_iface_init (GcrCertificateIface *iface)
126
iface->get_der_data = gcr_simple_certificate_get_der_data;
129
/* -----------------------------------------------------------------------------
134
* gcr_simple_certificate_new:
135
* @data: (array length=n_data): the raw DER certificate data
136
* @n_data: The length of @data
138
* Create a new #GcrSimpleCertificate for the raw DER data. The @data memory is
139
* copied so you can dispose of it after this function returns.
141
* Returns: (transfer full) (type Gcr.SimpleCertificate): a new #GcrSimpleCertificate
144
gcr_simple_certificate_new (const guchar *data,
147
GcrSimpleCertificate *cert;
149
g_return_val_if_fail (data, NULL);
150
g_return_val_if_fail (n_data, NULL);
152
cert = g_object_new (GCR_TYPE_SIMPLE_CERTIFICATE, NULL);
154
cert->pv->data = cert->pv->owned = g_memdup (data, n_data);
155
cert->pv->n_data = n_data;
156
return GCR_CERTIFICATE (cert);
160
* gcr_simple_certificate_new_static: (skip)
161
* @data: (array length=n_data): The raw DER certificate data
162
* @n_data: The length of @data
164
* Create a new #GcrSimpleCertificate for the raw DER data. The @data memory is
165
* not copied and must persist until the #GcrSimpleCertificate object is
168
* Returns: (transfer full) (type Gcr.SimpleCertificate): a new #GcrSimpleCertificate
171
gcr_simple_certificate_new_static (const guchar *data,
174
GcrSimpleCertificate *cert;
176
g_return_val_if_fail (data, NULL);
177
g_return_val_if_fail (n_data, NULL);
179
cert = g_object_new (GCR_TYPE_SIMPLE_CERTIFICATE, NULL);
181
cert->pv->owned = NULL;
182
cert->pv->data = data;
183
cert->pv->n_data = n_data;
184
return GCR_CERTIFICATE (cert);