| 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 |
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 |
gkm_certificate_key_get_attribute (GkmObject *base, GkmSession *session, CK_ATTRIBUTE_PTR attr) |
| 49 |
{ |
| 50 |
GkmCertificateKey *self = GKM_CERTIFICATE_KEY (base); |
| 51 |
|
| 52 |
switch (attr->type) { |
| 53 |
case CKA_LABEL: |
| 54 |
if (self->pv->certificate) |
| 55 |
return gkm_object_get_attribute (GKM_OBJECT (self->pv->certificate), session, attr); |
| 56 |
return gkm_attribute_set_string (attr, ""); |
| 57 |
} |
| 58 |
|
| 59 |
return GKM_OBJECT_CLASS (gkm_certificate_key_parent_class)->get_attribute (base, session, attr); |
| 60 |
} |
| 61 |
|
| 62 |
static void |
| 63 |
gkm_certificate_key_init (GkmCertificateKey *self) |
| 64 |
{ |
| 65 |
self->pv = gkm_certificate_key_get_instance_private (self); |
| 66 |
} |
| 67 |
|
| 68 |
static void |
| 69 |
gkm_certificate_key_finalize (GObject *obj) |
| 70 |
{ |
| 71 |
GkmCertificateKey *self = GKM_CERTIFICATE_KEY (obj); |
| 72 |
|
| 73 |
if (self->pv->certificate) |
| 74 |
g_object_remove_weak_pointer (G_OBJECT (self->pv->certificate), (gpointer*)&(self->pv->certificate)); |
| 75 |
self->pv->certificate = NULL; |
| 76 |
|
| 77 |
G_OBJECT_CLASS (gkm_certificate_key_parent_class)->finalize (obj); |
| 78 |
} |
| 79 |
|
| 80 |
static void |
| 81 |
gkm_certificate_key_set_property (GObject *obj, guint prop_id, const GValue *value, |
| 82 |
GParamSpec *pspec) |
| 83 |
{ |
| 84 |
GkmCertificateKey *self = GKM_CERTIFICATE_KEY (obj); |
| 85 |
|
| 86 |
switch (prop_id) { |
| 87 |
case PROP_CERTIFICATE: |
| 88 |
g_return_if_fail (!self->pv->certificate); |
| 89 |
self->pv->certificate = g_value_get_object (value); |
| 90 |
g_return_if_fail (self->pv->certificate); |
| 91 |
g_object_add_weak_pointer (G_OBJECT (self->pv->certificate), (gpointer*)&(self->pv->certificate)); |
| 92 |
break; |
| 93 |
default: |
| 94 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec); |
| 95 |
break; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
static void |
| 100 |
gkm_certificate_key_get_property (GObject *obj, guint prop_id, GValue *value, |
| 101 |
GParamSpec *pspec) |
| 102 |
{ |
| 103 |
GkmCertificateKey *self = GKM_CERTIFICATE_KEY (obj); |
| 104 |
|
| 105 |
switch (prop_id) { |
| 106 |
case PROP_CERTIFICATE: |
| 107 |
g_value_set_object (value, gkm_certificate_key_get_certificate (self)); |
| 108 |
break; |
| 109 |
default: |
| 110 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec); |
| 111 |
break; |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
static void |
| 116 |
gkm_certificate_key_class_init (GkmCertificateKeyClass *klass) |
| 117 |
{ |
| 118 |
GObjectClass *gobject_class = G_OBJECT_CLASS (klass); |
| 119 |
GkmObjectClass *gkm_class = GKM_OBJECT_CLASS (klass); |
| 120 |
|
| 121 |
gobject_class->finalize = gkm_certificate_key_finalize; |
| 122 |
gobject_class->set_property = gkm_certificate_key_set_property; |
| 123 |
gobject_class->get_property = gkm_certificate_key_get_property; |
| 124 |
|
| 125 |
gkm_class->get_attribute = gkm_certificate_key_get_attribute; |
| 126 |
|
| 127 |
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 |
} |
| 131 |
|
| 132 |
/* ----------------------------------------------------------------------------- |
| 133 |
* PUBLIC |
| 134 |
*/ |
| 135 |
|
| 136 |
GkmCertificateKey* |
| 137 |
gkm_certificate_key_new (GkmModule *module, GkmManager *manager, GkmCertificate *cert) |
| 138 |
{ |
| 139 |
return g_object_new (GKM_TYPE_CERTIFICATE_KEY, "module", module, |
| 140 |
"manager", manager, "certificate", cert, NULL); |
| 141 |
} |
| 142 |
|
| 143 |
GkmCertificate* |
| 144 |
gkm_certificate_key_get_certificate (GkmCertificateKey *self) |
| 145 |
{ |
| 146 |
g_return_val_if_fail (GKM_IS_CERTIFICATE_KEY (self), NULL); |
| 147 |
g_return_val_if_fail (self->pv->certificate, NULL); |
| 148 |
return self->pv->certificate; |
| 149 |
} |