~ubuntu-branches/ubuntu/natty/gnome-keyring/natty

« back to all changes in this revision

Viewing changes to pkcs11/gck/gck-null-key.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-02-16 19:00:06 UTC
  • mfrom: (1.1.58 upstream)
  • Revision ID: james.westby@ubuntu.com-20100216190006-cqpnic4zxlkmmi0o
Tags: 2.29.90git20100218-0ubuntu1
Updated to a git snapshot version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "gck-attributes.h"
 
25
#include "gck-null-mechanism.h"
 
26
#include "gck-null-key.h"
 
27
#include "gck-session.h"
 
28
#include "gck-util.h"
 
29
 
 
30
#include "pkcs11/pkcs11.h"
 
31
#include "pkcs11/pkcs11i.h"
 
32
 
 
33
struct _GckNullKey {
 
34
        GckSecretKey parent;
 
35
};
 
36
 
 
37
G_DEFINE_TYPE (GckNullKey, gck_null_key, GCK_TYPE_SECRET_KEY);
 
38
 
 
39
/* -----------------------------------------------------------------------------
 
40
 * INTERNAL
 
41
 */
 
42
 
 
43
static GckObject*
 
44
factory_create_null_key (GckSession *session, GckTransaction *transaction,
 
45
                         CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs)
 
46
{
 
47
        GckNullKey *key;
 
48
        GckManager *manager;
 
49
 
 
50
        manager = gck_manager_for_template (attrs, n_attrs, session);
 
51
        key = g_object_new (GCK_TYPE_NULL_KEY,
 
52
                            "module", gck_session_get_module (session),
 
53
                            "manager", manager,
 
54
                            NULL);
 
55
 
 
56
        gck_session_complete_object_creation (session, transaction, GCK_OBJECT (key),
 
57
                                              TRUE, attrs, n_attrs);
 
58
        return GCK_OBJECT (key);
 
59
}
 
60
 
 
61
/* -----------------------------------------------------------------------------
 
62
 * OBJECT
 
63
 */
 
64
 
 
65
static CK_RV
 
66
gck_null_key_real_get_attribute (GckObject *base, GckSession *session, CK_ATTRIBUTE *attr)
 
67
{
 
68
        switch (attr->type)
 
69
        {
 
70
        case CKA_KEY_TYPE:
 
71
                return gck_attribute_set_ulong (attr, CKK_G_NULL);
 
72
 
 
73
        case CKA_UNWRAP:
 
74
        case CKA_WRAP:
 
75
                return gck_attribute_set_bool (attr, CK_TRUE);
 
76
 
 
77
        case CKA_VALUE:
 
78
                return gck_attribute_set_empty (attr);
 
79
 
 
80
        case CKA_VALUE_LEN:
 
81
                return gck_attribute_set_ulong (attr, 0);
 
82
 
 
83
        case CKA_CHECK_VALUE:
 
84
                return gck_attribute_set_data (attr, "\0\0\0", 3);
 
85
 
 
86
        case CKA_ALLOWED_MECHANISMS:
 
87
                return gck_attribute_set_data (attr, (CK_VOID_PTR)GCK_NULL_MECHANISMS,
 
88
                                               sizeof (GCK_NULL_MECHANISMS));
 
89
        };
 
90
 
 
91
        return GCK_OBJECT_CLASS (gck_null_key_parent_class)->get_attribute (base, session, attr);
 
92
}
 
93
 
 
94
static void
 
95
gck_null_key_init (GckNullKey *self)
 
96
{
 
97
 
 
98
}
 
99
 
 
100
static void
 
101
gck_null_key_class_init (GckNullKeyClass *klass)
 
102
{
 
103
        GckObjectClass *gck_class = GCK_OBJECT_CLASS (klass);
 
104
 
 
105
        gck_null_key_parent_class = g_type_class_peek_parent (klass);
 
106
        gck_class->get_attribute = gck_null_key_real_get_attribute;
 
107
}
 
108
 
 
109
/* -----------------------------------------------------------------------------
 
110
 * PUBLIC
 
111
 */
 
112
 
 
113
GckFactory*
 
114
gck_null_key_get_factory (void)
 
115
{
 
116
        static CK_OBJECT_CLASS klass = CKO_SECRET_KEY;
 
117
        static CK_KEY_TYPE type = CKK_G_NULL;
 
118
 
 
119
        static CK_ATTRIBUTE attributes[] = {
 
120
                { CKA_CLASS, &klass, sizeof (klass) },
 
121
                { CKA_KEY_TYPE, &type, sizeof (type) }
 
122
        };
 
123
 
 
124
        static GckFactory factory = {
 
125
                attributes,
 
126
                G_N_ELEMENTS (attributes),
 
127
                factory_create_null_key
 
128
        };
 
129
 
 
130
        return &factory;
 
131
}