comparison nss/lib/dev/ckhelper.h @ 0:1e5118fa0cb1

This is NSS with a Cmake Buildsyste To compile a static NSS library for Windows we've used the Chromium-NSS fork and added a Cmake buildsystem to compile it statically for Windows. See README.chromium for chromium changes and README.trustbridge for our modifications.
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 28 Jul 2014 10:47:06 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1e5118fa0cb1
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 /*
6 * ckhelper.h
7 *
8 * This file contains some helper utilities for interaction with cryptoki.
9 */
10
11 #ifndef CKHELPER_H
12 #define CKHELPER_H
13
14 PR_BEGIN_EXTERN_C
15
16 /* Some globals to keep from constantly redeclaring common cryptoki
17 * attribute types on the stack.
18 */
19
20 /* Boolean values */
21 NSS_EXTERN_DATA const NSSItem g_ck_true;
22 NSS_EXTERN_DATA const NSSItem g_ck_false;
23
24 /* Object classes */
25 NSS_EXTERN_DATA const NSSItem g_ck_class_cert;
26 NSS_EXTERN_DATA const NSSItem g_ck_class_pubkey;
27 NSS_EXTERN_DATA const NSSItem g_ck_class_privkey;
28
29 #define NSS_CK_TEMPLATE_START(_template, attr, size) \
30 attr = _template; \
31 size = 0;
32
33 #define NSS_CK_SET_ATTRIBUTE_ITEM(pattr, kind, item) \
34 (pattr)->type = kind; \
35 (pattr)->pValue = (CK_VOID_PTR)(item)->data; \
36 (pattr)->ulValueLen = (CK_ULONG)(item)->size; \
37 (pattr)++;
38
39 #define NSS_CK_SET_ATTRIBUTE_UTF8(pattr, kind, utf8) \
40 (pattr)->type = kind; \
41 (pattr)->pValue = (CK_VOID_PTR)utf8; \
42 (pattr)->ulValueLen = (CK_ULONG)nssUTF8_Size(utf8, NULL); \
43 if ((pattr)->ulValueLen) ((pattr)->ulValueLen)--; \
44 (pattr)++;
45
46 #define NSS_CK_SET_ATTRIBUTE_VAR(pattr, kind, var) \
47 (pattr)->type = kind; \
48 (pattr)->pValue = (CK_VOID_PTR)&var; \
49 (pattr)->ulValueLen = (CK_ULONG)sizeof(var); \
50 (pattr)++;
51
52 #define NSS_CK_SET_ATTRIBUTE_NULL(pattr, kind) \
53 (pattr)->type = kind; \
54 (pattr)->pValue = (CK_VOID_PTR)NULL; \
55 (pattr)->ulValueLen = 0; \
56 (pattr)++;
57
58 #define NSS_CK_TEMPLATE_FINISH(_template, attr, size) \
59 size = (attr) - (_template); \
60 PR_ASSERT(size <= sizeof(_template)/sizeof(_template[0]));
61
62 /* NSS_CK_ATTRIBUTE_TO_ITEM(attrib, item)
63 *
64 * Convert a CK_ATTRIBUTE to an NSSItem.
65 */
66 #define NSS_CK_ATTRIBUTE_TO_ITEM(attrib, item) \
67 if ((CK_LONG)(attrib)->ulValueLen > 0) { \
68 (item)->data = (void *)(attrib)->pValue; \
69 (item)->size = (PRUint32)(attrib)->ulValueLen; \
70 } else { \
71 (item)->data = 0; \
72 (item)->size = 0; \
73 }
74
75 #define NSS_CK_ATTRIBUTE_TO_BOOL(attrib, boolvar) \
76 if ((attrib)->ulValueLen > 0) { \
77 if (*((CK_BBOOL*)(attrib)->pValue) == CK_TRUE) { \
78 boolvar = PR_TRUE; \
79 } else { \
80 boolvar = PR_FALSE; \
81 } \
82 }
83
84 #define NSS_CK_ATTRIBUTE_TO_ULONG(attrib, ulongvar) \
85 if ((attrib)->ulValueLen > 0) { \
86 ulongvar = *((CK_ULONG*)(attrib)->pValue); \
87 }
88
89 /* NSS_CK_ATTRIBUTE_TO_UTF8(attrib, str)
90 *
91 * Convert a CK_ATTRIBUTE to a string.
92 */
93 #define NSS_CK_ATTRIBUTE_TO_UTF8(attrib, str) \
94 str = (NSSUTF8 *)((attrib)->pValue);
95
96 /* NSS_CK_ITEM_TO_ATTRIBUTE(item, attrib)
97 *
98 * Convert an NSSItem to a CK_ATTRIBUTE.
99 */
100 #define NSS_CK_ITEM_TO_ATTRIBUTE(item, attrib) \
101 (attrib)->pValue = (CK_VOID_PTR)(item)->data; \
102 (attrib)->ulValueLen = (CK_ULONG)(item)->size; \
103
104 /* Get an array of attributes from an object. */
105 NSS_EXTERN PRStatus
106 nssCKObject_GetAttributes
107 (
108 CK_OBJECT_HANDLE object,
109 CK_ATTRIBUTE_PTR obj_template,
110 CK_ULONG count,
111 NSSArena *arenaOpt,
112 nssSession *session,
113 NSSSlot *slot
114 );
115
116 /* Get a single attribute as an item. */
117 NSS_EXTERN PRStatus
118 nssCKObject_GetAttributeItem
119 (
120 CK_OBJECT_HANDLE object,
121 CK_ATTRIBUTE_TYPE attribute,
122 NSSArena *arenaOpt,
123 nssSession *session,
124 NSSSlot *slot,
125 NSSItem *rvItem
126 );
127
128 NSS_EXTERN PRBool
129 nssCKObject_IsAttributeTrue
130 (
131 CK_OBJECT_HANDLE object,
132 CK_ATTRIBUTE_TYPE attribute,
133 nssSession *session,
134 NSSSlot *slot,
135 PRStatus *rvStatus
136 );
137
138 NSS_EXTERN PRStatus
139 nssCKObject_SetAttributes
140 (
141 CK_OBJECT_HANDLE object,
142 CK_ATTRIBUTE_PTR obj_template,
143 CK_ULONG count,
144 nssSession *session,
145 NSSSlot *slot
146 );
147
148 NSS_EXTERN PRBool
149 nssCKObject_IsTokenObjectTemplate
150 (
151 CK_ATTRIBUTE_PTR objectTemplate,
152 CK_ULONG otsize
153 );
154
155 PR_END_EXTERN_C
156
157 #endif /* CKHELPER_H */
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)