security/nss/lib/dev/ckhelper.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial