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 "pkcs11/pkcs11.h"
26
#include "gck-attributes.h"
27
#include "gck-crypto.h"
28
#include "gck-secret-key.h"
29
#include "gck-session.h"
32
struct _GckSecretKeyPrivate {
37
G_DEFINE_TYPE (GckSecretKey, gck_secret_key, GCK_TYPE_OBJECT);
39
/* -----------------------------------------------------------------------------
43
/* -----------------------------------------------------------------------------
48
gck_secret_key_real_get_attribute (GckObject *base, GckSession *session, CK_ATTRIBUTE* attr)
50
GckSecretKey *self = GCK_SECRET_KEY (base);
55
return gck_attribute_set_ulong (attr, CKO_SECRET_KEY);
65
return gck_attribute_set_bool (attr, FALSE);
68
return gck_attribute_set_bool (attr, TRUE);
70
case CKA_ALWAYS_SENSITIVE:
71
return gck_attribute_set_bool (attr, FALSE);
73
case CKA_NEVER_EXTRACTABLE:
74
return gck_attribute_set_bool (attr, FALSE);
76
case CKA_WRAP_WITH_TRUSTED:
77
return gck_attribute_set_bool (attr, FALSE);
80
return gck_attribute_set_bool (attr, FALSE);
82
case CKA_WRAP_TEMPLATE:
83
case CKA_UNWRAP_TEMPLATE:
84
return CKR_ATTRIBUTE_TYPE_INVALID;
88
return gck_attribute_set_empty (attr);
91
return gck_attribute_set_bool (attr, FALSE);
94
return gck_attribute_set_data (attr, self->pv->id, self->pv->n_id);
96
case CKA_KEY_GEN_MECHANISM:
97
return gck_attribute_set_ulong (attr, CK_UNAVAILABLE_INFORMATION);
100
return GCK_OBJECT_CLASS (gck_secret_key_parent_class)->get_attribute (base, session, attr);
104
gck_secret_key_real_create_attributes (GckObject *object, GckSession *session, GckTransaction *transaction,
105
CK_ATTRIBUTE *attrs, CK_ULONG n_attrs)
107
GckSecretKey *self = GCK_SECRET_KEY (object);
110
if (!self->pv->n_id) {
111
id = gck_attributes_find (attrs, n_attrs, CKA_ID);
116
self->pv->id = g_memdup (id->pValue, id->ulValueLen);
117
self->pv->n_id = id->ulValueLen;
118
gck_attribute_consume (id);
124
gck_secret_key_init (GckSecretKey *self)
126
self->pv = G_TYPE_INSTANCE_GET_PRIVATE (self, GCK_TYPE_SECRET_KEY, GckSecretKeyPrivate);
130
gck_secret_key_finalize (GObject *obj)
132
GckSecretKey *self = GCK_SECRET_KEY (obj);
134
g_free (self->pv->id);
138
G_OBJECT_CLASS (gck_secret_key_parent_class)->finalize (obj);
142
gck_secret_key_class_init (GckSecretKeyClass *klass)
144
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
145
GckObjectClass *gck_class = GCK_OBJECT_CLASS (klass);
147
gck_secret_key_parent_class = g_type_class_peek_parent (klass);
149
gobject_class->finalize = gck_secret_key_finalize;
151
gck_class->get_attribute = gck_secret_key_real_get_attribute;
152
gck_class->create_attributes = gck_secret_key_real_create_attributes;
154
g_type_class_add_private (klass, sizeof (GckSecretKeyPrivate));
157
/* -----------------------------------------------------------------------------