summaryrefslogtreecommitdiffstats
path: root/security/nss/lib/ckfw/dbm/object.c
blob: 4f6e4d409ce4bd4aac4e0bf52ecef050393721e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "ckdbm.h"

static void
nss_dbm_mdObject_Finalize(
    NSSCKMDObject *mdObject,
    NSSCKFWObject *fwObject,
    NSSCKMDSession *mdSession,
    NSSCKFWSession *fwSession,
    NSSCKMDToken *mdToken,
    NSSCKFWToken *fwToken,
    NSSCKMDInstance *mdInstance,
    NSSCKFWInstance *fwInstance)
{
    ;
}

static CK_RV
nss_dbm_mdObject_Destroy(
    NSSCKMDObject *mdObject,
    NSSCKFWObject *fwObject,
    NSSCKMDSession *mdSession,
    NSSCKFWSession *fwSession,
    NSSCKMDToken *mdToken,
    NSSCKFWToken *fwToken,
    NSSCKMDInstance *mdInstance,
    NSSCKFWInstance *fwInstance)
{
    nss_dbm_object_t *object = (nss_dbm_object_t *)mdObject->etc;
    return nss_dbm_db_delete_object(object->handle);
}

static CK_ULONG
nss_dbm_mdObject_GetAttributeCount(
    NSSCKMDObject *mdObject,
    NSSCKFWObject *fwObject,
    NSSCKMDSession *mdSession,
    NSSCKFWSession *fwSession,
    NSSCKMDToken *mdToken,
    NSSCKFWToken *fwToken,
    NSSCKMDInstance *mdInstance,
    NSSCKFWInstance *fwInstance,
    CK_RV *pError)
{
    nss_dbm_object_t *object = (nss_dbm_object_t *)mdObject->etc;
    nss_dbm_session_t *session = (nss_dbm_session_t *)mdSession->etc;
    return nss_dbm_db_get_object_attribute_count(object->handle, pError,
                                                 &session->deviceError);
}

static CK_RV
nss_dbm_mdObject_GetAttributeTypes(
    NSSCKMDObject *mdObject,
    NSSCKFWObject *fwObject,
    NSSCKMDSession *mdSession,
    NSSCKFWSession *fwSession,
    NSSCKMDToken *mdToken,
    NSSCKFWToken *fwToken,
    NSSCKMDInstance *mdInstance,
    NSSCKFWInstance *fwInstance,
    CK_ATTRIBUTE_TYPE_PTR typeArray,
    CK_ULONG ulCount)
{
    nss_dbm_object_t *object = (nss_dbm_object_t *)mdObject->etc;
    nss_dbm_session_t *session = (nss_dbm_session_t *)mdSession->etc;
    return nss_dbm_db_get_object_attribute_types(object->handle, typeArray,
                                                 ulCount, &session->deviceError);
}

static CK_ULONG
nss_dbm_mdObject_GetAttributeSize(
    NSSCKMDObject *mdObject,
    NSSCKFWObject *fwObject,
    NSSCKMDSession *mdSession,
    NSSCKFWSession *fwSession,
    NSSCKMDToken *mdToken,
    NSSCKFWToken *fwToken,
    NSSCKMDInstance *mdInstance,
    NSSCKFWInstance *fwInstance,
    CK_ATTRIBUTE_TYPE attribute,
    CK_RV *pError)
{
    nss_dbm_object_t *object = (nss_dbm_object_t *)mdObject->etc;
    nss_dbm_session_t *session = (nss_dbm_session_t *)mdSession->etc;
    return nss_dbm_db_get_object_attribute_size(object->handle, attribute, pError,
                                                &session->deviceError);
}

static NSSItem *
nss_dbm_mdObject_GetAttribute(
    NSSCKMDObject *mdObject,
    NSSCKFWObject *fwObject,
    NSSCKMDSession *mdSession,
    NSSCKFWSession *fwSession,
    NSSCKMDToken *mdToken,
    NSSCKFWToken *fwToken,
    NSSCKMDInstance *mdInstance,
    NSSCKFWInstance *fwInstance,
    CK_ATTRIBUTE_TYPE attribute,
    CK_RV *pError)
{
    nss_dbm_object_t *object = (nss_dbm_object_t *)mdObject->etc;
    nss_dbm_session_t *session = (nss_dbm_session_t *)mdSession->etc;
    return nss_dbm_db_get_object_attribute(object->handle, object->arena, attribute,
                                           pError, &session->deviceError);
}

static CK_RV
nss_dbm_mdObject_SetAttribute(
    NSSCKMDObject *mdObject,
    NSSCKFWObject *fwObject,
    NSSCKMDSession *mdSession,
    NSSCKFWSession *fwSession,
    NSSCKMDToken *mdToken,
    NSSCKFWToken *fwToken,
    NSSCKMDInstance *mdInstance,
    NSSCKFWInstance *fwInstance,
    CK_ATTRIBUTE_TYPE attribute,
    NSSItem *value)
{
    nss_dbm_object_t *object = (nss_dbm_object_t *)mdObject->etc;
    nss_dbm_session_t *session = (nss_dbm_session_t *)mdSession->etc;
    return nss_dbm_db_set_object_attribute(object->handle, attribute, value,
                                           &session->deviceError);
}

NSS_IMPLEMENT NSSCKMDObject *
nss_dbm_mdObject_factory(
    nss_dbm_object_t *object,
    CK_RV *pError)
{
    NSSCKMDObject *rv;

    rv = nss_ZNEW(object->arena, NSSCKMDObject);
    if ((NSSCKMDObject *)NULL == rv) {
        *pError = CKR_HOST_MEMORY;
        return (NSSCKMDObject *)NULL;
    }

    rv->etc = (void *)object;
    rv->Finalize = nss_dbm_mdObject_Finalize;
    rv->Destroy = nss_dbm_mdObject_Destroy;
    /*  IsTokenObject can be deferred */
    rv->GetAttributeCount = nss_dbm_mdObject_GetAttributeCount;
    rv->GetAttributeTypes = nss_dbm_mdObject_GetAttributeTypes;
    rv->GetAttributeSize = nss_dbm_mdObject_GetAttributeSize;
    rv->GetAttribute = nss_dbm_mdObject_GetAttribute;
    rv->SetAttribute = nss_dbm_mdObject_SetAttribute;
    /*  GetObjectSize can be deferred */

    return rv;
}