]> git.0d.be Git - empathy.git/blob - libempathy-gtk/gcr-simple-certificate.c
Merge branch 'sasl'
[empathy.git] / libempathy-gtk / gcr-simple-certificate.c
1 /* 
2  * gnome-keyring
3  * 
4  * Copyright (C) 2008 Stefan Walter
5  *
6  * This file is copied from the gnome-keyring gcr library, which can be
7  * found at git://git.gnome.org/gnome-keyring
8  * 
9  * This program is free software; you can redistribute it and/or modify 
10  * it under the terms of the GNU Lesser General Public License as
11  * published by the Free Software Foundation; either version 2.1 of
12  * the License, or (at your option) any later version.
13  *  
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *  
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22  * 02111-1307, USA.  
23  */
24
25 #include "config.h"
26
27 #include <gcr/gcr.h>
28 #include "gcr-simple-certificate.h"
29
30 #include <string.h>
31
32 struct _GcrSimpleCertificatePrivate {
33         guchar *owned_data;
34         gsize n_owned_data;
35 };
36
37 static void gcr_certificate_iface (GcrCertificateIface *iface); 
38 G_DEFINE_TYPE_WITH_CODE (GcrSimpleCertificate, gcr_simple_certificate, G_TYPE_OBJECT, 
39                          G_IMPLEMENT_INTERFACE (GCR_TYPE_CERTIFICATE, gcr_certificate_iface));
40
41 /* -----------------------------------------------------------------------------
42  * OBJECT 
43  */
44
45 static void
46 gcr_simple_certificate_init (GcrSimpleCertificate *self)
47 {
48         self->pv = G_TYPE_INSTANCE_GET_PRIVATE (self, GCR_TYPE_SIMPLE_CERTIFICATE, GcrSimpleCertificatePrivate);
49 }
50
51 static void
52 gcr_simple_certificate_finalize (GObject *obj)
53 {
54         GcrSimpleCertificate *self = GCR_SIMPLE_CERTIFICATE (obj);
55         
56         g_free (self->pv->owned_data);
57         self->pv->owned_data = NULL;
58         self->pv->n_owned_data = 0;
59
60         G_OBJECT_CLASS (gcr_simple_certificate_parent_class)->finalize (obj);
61 }
62
63 static void
64 gcr_simple_certificate_set_property (GObject *obj, guint prop_id, const GValue *value, 
65                                      GParamSpec *pspec)
66 {
67         switch (prop_id) {
68         default:
69                 G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
70                 break;
71         }
72 }
73
74 static void
75 gcr_simple_certificate_get_property (GObject *obj, guint prop_id, GValue *value, 
76                                      GParamSpec *pspec)
77 {
78         switch (prop_id) {
79         default:
80                 G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
81                 break;
82         }
83 }
84
85 static void
86 gcr_simple_certificate_class_init (GcrSimpleCertificateClass *klass)
87 {
88         GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
89     
90         gobject_class->finalize = gcr_simple_certificate_finalize;
91         gobject_class->set_property = gcr_simple_certificate_set_property;
92         gobject_class->get_property = gcr_simple_certificate_get_property;
93         
94         g_type_class_add_private (gobject_class, sizeof (GcrSimpleCertificatePrivate));
95 }
96
97 static const guchar* 
98 gcr_simple_certificate_real_get_der_data (GcrCertificate *base, gsize *n_data)
99 {
100         GcrSimpleCertificate *self = GCR_SIMPLE_CERTIFICATE (base);
101         
102         g_return_val_if_fail (GCR_IS_CERTIFICATE (self), NULL);
103         g_return_val_if_fail (n_data, NULL);
104         g_return_val_if_fail (self->pv->owned_data, NULL);
105         
106         /* This is called when we're not a base class */
107         *n_data = self->pv->n_owned_data;
108         return self->pv->owned_data;
109 }
110
111 static void 
112 gcr_certificate_iface (GcrCertificateIface *iface) 
113 {
114         iface->get_der_data = (gpointer)gcr_simple_certificate_real_get_der_data;
115 }
116
117 /* -----------------------------------------------------------------------------
118  * PUBLIC 
119  */
120
121 GcrCertificate*
122 gcr_simple_certificate_new (const guchar *data, gsize n_data)
123 {
124         GcrSimpleCertificate *cert;
125         
126         g_return_val_if_fail (data, NULL);
127         g_return_val_if_fail (n_data, NULL);
128         
129         cert = g_object_new (GCR_TYPE_SIMPLE_CERTIFICATE, NULL);
130         
131         cert->pv->owned_data = g_memdup (data, n_data);
132         cert->pv->n_owned_data = n_data;
133         return GCR_CERTIFICATE (cert);
134 }