Line data Source code
1 : /*
2 : * gnome-keyring
3 : *
4 : * Copyright (C) 2009 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 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 License for more details.
15 : *
16 : * You should have received a copy of the GNU Lesser General
17 : * License along with this program; if not, see
18 : * <http://www.gnu.org/licenses/>.
19 : */
20 :
21 : #include "config.h"
22 :
23 : #include "mock-locked-object.h"
24 :
25 : #include "gkm/gkm-attributes.h"
26 : #include "gkm/gkm-credential.h"
27 :
28 13 : G_DEFINE_TYPE (MockLockedObject, mock_locked_object, GKM_TYPE_OBJECT);
29 :
30 : /* -----------------------------------------------------------------------------
31 : * INTERNAL
32 : */
33 :
34 : /* -----------------------------------------------------------------------------
35 : * KEY
36 : */
37 :
38 : static CK_RV
39 33 : mock_locked_object_real_get_attribute (GkmObject *base, GkmSession *session, CK_ATTRIBUTE* attr)
40 : {
41 33 : switch (attr->type) {
42 22 : case CKA_CLASS:
43 22 : return gkm_attribute_set_ulong (attr, CKO_DATA);
44 0 : case CKA_ALWAYS_AUTHENTICATE:
45 0 : return gkm_attribute_set_bool (attr, TRUE);
46 : };
47 :
48 11 : return GKM_OBJECT_CLASS (mock_locked_object_parent_class)->get_attribute (base, session, attr);
49 : }
50 :
51 : static CK_RV
52 6 : mock_locked_object_real_unlock (GkmObject *base, GkmCredential *auth)
53 : {
54 : const gchar *password;
55 : gsize n_password;
56 :
57 6 : password = gkm_credential_get_password (auth, &n_password);
58 6 : if (n_password == 4 && memcmp (password, "mock", 4) == 0)
59 5 : return CKR_OK;
60 :
61 1 : return CKR_USER_NOT_LOGGED_IN;
62 : }
63 :
64 : static void
65 11 : mock_locked_object_init (MockLockedObject *self)
66 : {
67 :
68 11 : }
69 :
70 : static void
71 1 : mock_locked_object_class_init (MockLockedObjectClass *klass)
72 : {
73 1 : GkmObjectClass *gkm_class = GKM_OBJECT_CLASS (klass);
74 1 : mock_locked_object_parent_class = g_type_class_peek_parent (klass);
75 1 : gkm_class->get_attribute = mock_locked_object_real_get_attribute;
76 1 : gkm_class->unlock = mock_locked_object_real_unlock;
77 1 : }
78 :
79 : /* -----------------------------------------------------------------------------
80 : * PUBLIC
81 : */
82 :
83 : GkmObject*
84 11 : mock_locked_object_new (GkmModule *module, GkmManager *manager)
85 : {
86 11 : return g_object_new (MOCK_TYPE_LOCKED_OBJECT,
87 : "module", module,
88 : "manager", manager,
89 : NULL);
90 : }
|