Line data Source code
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, see
18 : * <http://www.gnu.org/licenses/>.
19 : */
20 :
21 : #include "config.h"
22 :
23 : #include "gkm-attributes.h"
24 : #include "gkm-certificate.h"
25 : #include "gkm-certificate-key.h"
26 :
27 : #include "gkm-object.h"
28 : #include "gkm-util.h"
29 :
30 : #include <glib/gi18n.h>
31 :
32 : enum {
33 : PROP_0,
34 : PROP_CERTIFICATE
35 : };
36 :
37 : struct _GkmCertificateKeyPrivate {
38 : GkmCertificate *certificate;
39 : };
40 :
41 216 : G_DEFINE_TYPE_WITH_PRIVATE (GkmCertificateKey, gkm_certificate_key, GKM_TYPE_PUBLIC_XSA_KEY);
42 :
43 : /* -----------------------------------------------------------------------------
44 : * OBJECT
45 : */
46 :
47 : static CK_RV
48 54 : gkm_certificate_key_get_attribute (GkmObject *base, GkmSession *session, CK_ATTRIBUTE_PTR attr)
49 : {
50 54 : GkmCertificateKey *self = GKM_CERTIFICATE_KEY (base);
51 :
52 54 : switch (attr->type) {
53 0 : case CKA_LABEL:
54 0 : if (self->pv->certificate)
55 0 : return gkm_object_get_attribute (GKM_OBJECT (self->pv->certificate), session, attr);
56 0 : return gkm_attribute_set_string (attr, "");
57 : }
58 :
59 54 : return GKM_OBJECT_CLASS (gkm_certificate_key_parent_class)->get_attribute (base, session, attr);
60 : }
61 :
62 : static void
63 36 : gkm_certificate_key_init (GkmCertificateKey *self)
64 : {
65 36 : self->pv = gkm_certificate_key_get_instance_private (self);
66 36 : }
67 :
68 : static void
69 36 : gkm_certificate_key_finalize (GObject *obj)
70 : {
71 36 : GkmCertificateKey *self = GKM_CERTIFICATE_KEY (obj);
72 :
73 36 : if (self->pv->certificate)
74 36 : g_object_remove_weak_pointer (G_OBJECT (self->pv->certificate), (gpointer*)&(self->pv->certificate));
75 36 : self->pv->certificate = NULL;
76 :
77 36 : G_OBJECT_CLASS (gkm_certificate_key_parent_class)->finalize (obj);
78 36 : }
79 :
80 : static void
81 36 : gkm_certificate_key_set_property (GObject *obj, guint prop_id, const GValue *value,
82 : GParamSpec *pspec)
83 : {
84 36 : GkmCertificateKey *self = GKM_CERTIFICATE_KEY (obj);
85 :
86 36 : switch (prop_id) {
87 36 : case PROP_CERTIFICATE:
88 36 : g_return_if_fail (!self->pv->certificate);
89 36 : self->pv->certificate = g_value_get_object (value);
90 36 : g_return_if_fail (self->pv->certificate);
91 36 : g_object_add_weak_pointer (G_OBJECT (self->pv->certificate), (gpointer*)&(self->pv->certificate));
92 36 : break;
93 0 : default:
94 0 : G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
95 0 : break;
96 : }
97 : }
98 :
99 : static void
100 0 : gkm_certificate_key_get_property (GObject *obj, guint prop_id, GValue *value,
101 : GParamSpec *pspec)
102 : {
103 0 : GkmCertificateKey *self = GKM_CERTIFICATE_KEY (obj);
104 :
105 0 : switch (prop_id) {
106 0 : case PROP_CERTIFICATE:
107 0 : g_value_set_object (value, gkm_certificate_key_get_certificate (self));
108 0 : break;
109 0 : default:
110 0 : G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
111 0 : break;
112 : }
113 0 : }
114 :
115 : static void
116 6 : gkm_certificate_key_class_init (GkmCertificateKeyClass *klass)
117 : {
118 6 : GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
119 6 : GkmObjectClass *gkm_class = GKM_OBJECT_CLASS (klass);
120 :
121 6 : gobject_class->finalize = gkm_certificate_key_finalize;
122 6 : gobject_class->set_property = gkm_certificate_key_set_property;
123 6 : gobject_class->get_property = gkm_certificate_key_get_property;
124 :
125 6 : gkm_class->get_attribute = gkm_certificate_key_get_attribute;
126 :
127 6 : g_object_class_install_property (gobject_class, PROP_CERTIFICATE,
128 : g_param_spec_object ("certificate", "Certificate", "Certificate this key belongs to",
129 : GKM_TYPE_CERTIFICATE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
130 6 : }
131 :
132 : /* -----------------------------------------------------------------------------
133 : * PUBLIC
134 : */
135 :
136 : GkmCertificateKey*
137 36 : gkm_certificate_key_new (GkmModule *module, GkmManager *manager, GkmCertificate *cert)
138 : {
139 36 : return g_object_new (GKM_TYPE_CERTIFICATE_KEY, "module", module,
140 : "manager", manager, "certificate", cert, NULL);
141 : }
142 :
143 : GkmCertificate*
144 0 : gkm_certificate_key_get_certificate (GkmCertificateKey *self)
145 : {
146 0 : g_return_val_if_fail (GKM_IS_CERTIFICATE_KEY (self), NULL);
147 0 : g_return_val_if_fail (self->pv->certificate, NULL);
148 0 : return self->pv->certificate;
149 : }
|