]> git.0d.be Git - empathy.git/blob - libempathy-gtk/gcr-simple-certificate.c
Import gcr-simple-certificate from gcr
[empathy.git] / libempathy-gtk / gcr-simple-certificate.c
1 /* 
2  * gnome-keyring
3  * 
4  * Copyright (C) 2008 Stefan Walter
5  * 
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.
10  *  
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.
15  *  
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
19  * 02111-1307, USA.  
20  */
21
22 #include "config.h"
23
24 #include <gcr/gcr.h>
25 #include "gcr-simple-certificate.h"
26
27 #include <string.h>
28
29 struct _GcrSimpleCertificatePrivate {
30         guchar *owned_data;
31         gsize n_owned_data;
32 };
33
34 static void gcr_certificate_iface (GcrCertificateIface *iface); 
35 G_DEFINE_TYPE_WITH_CODE (GcrSimpleCertificate, gcr_simple_certificate, G_TYPE_OBJECT, 
36                          G_IMPLEMENT_INTERFACE (GCR_TYPE_CERTIFICATE, gcr_certificate_iface));
37
38 /* -----------------------------------------------------------------------------
39  * OBJECT 
40  */
41
42 static void
43 gcr_simple_certificate_init (GcrSimpleCertificate *self)
44 {
45         self->pv = G_TYPE_INSTANCE_GET_PRIVATE (self, GCR_TYPE_SIMPLE_CERTIFICATE, GcrSimpleCertificatePrivate);
46 }
47
48 static void
49 gcr_simple_certificate_finalize (GObject *obj)
50 {
51         GcrSimpleCertificate *self = GCR_SIMPLE_CERTIFICATE (obj);
52         
53         g_free (self->pv->owned_data);
54         self->pv->owned_data = NULL;
55         self->pv->n_owned_data = 0;
56
57         G_OBJECT_CLASS (gcr_simple_certificate_parent_class)->finalize (obj);
58 }
59
60 static void
61 gcr_simple_certificate_set_property (GObject *obj, guint prop_id, const GValue *value, 
62                                      GParamSpec *pspec)
63 {
64         switch (prop_id) {
65         default:
66                 G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
67                 break;
68         }
69 }
70
71 static void
72 gcr_simple_certificate_get_property (GObject *obj, guint prop_id, GValue *value, 
73                                      GParamSpec *pspec)
74 {
75         switch (prop_id) {
76         default:
77                 G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
78                 break;
79         }
80 }
81
82 static void
83 gcr_simple_certificate_class_init (GcrSimpleCertificateClass *klass)
84 {
85         GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
86     
87         gobject_class->finalize = gcr_simple_certificate_finalize;
88         gobject_class->set_property = gcr_simple_certificate_set_property;
89         gobject_class->get_property = gcr_simple_certificate_get_property;
90         
91         g_type_class_add_private (gobject_class, sizeof (GcrSimpleCertificatePrivate));
92 }
93
94 static const guchar* 
95 gcr_simple_certificate_real_get_der_data (GcrCertificate *base, gsize *n_data)
96 {
97         GcrSimpleCertificate *self = GCR_SIMPLE_CERTIFICATE (base);
98         
99         g_return_val_if_fail (GCR_IS_CERTIFICATE (self), NULL);
100         g_return_val_if_fail (n_data, NULL);
101         g_return_val_if_fail (self->pv->owned_data, NULL);
102         
103         /* This is called when we're not a base class */
104         *n_data = self->pv->n_owned_data;
105         return self->pv->owned_data;
106 }
107
108 static void 
109 gcr_certificate_iface (GcrCertificateIface *iface) 
110 {
111         iface->get_der_data = (gpointer)gcr_simple_certificate_real_get_der_data;
112 }
113
114 /* -----------------------------------------------------------------------------
115  * PUBLIC 
116  */
117
118 GcrCertificate*
119 gcr_simple_certificate_new (const guchar *data, gsize n_data)
120 {
121         GcrSimpleCertificate *cert;
122         
123         g_return_val_if_fail (data, NULL);
124         g_return_val_if_fail (n_data, NULL);
125         
126         cert = g_object_new (GCR_TYPE_SIMPLE_CERTIFICATE, NULL);
127         
128         cert->pv->owned_data = g_memdup (data, n_data);
129         cert->pv->n_owned_data = n_data;
130         return GCR_CERTIFICATE (cert);
131 }