| OLD | NEW |
| (Empty) |
| 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) \ | |
| 44 ((pattr)->ulValueLen)--; \ | |
| 45 (pattr)++; | |
| 46 | |
| 47 #define NSS_CK_SET_ATTRIBUTE_VAR(pattr, kind, var) \ | |
| 48 (pattr)->type = kind; \ | |
| 49 (pattr)->pValue = (CK_VOID_PTR)&var; \ | |
| 50 (pattr)->ulValueLen = (CK_ULONG)sizeof(var); \ | |
| 51 (pattr)++; | |
| 52 | |
| 53 #define NSS_CK_SET_ATTRIBUTE_NULL(pattr, kind) \ | |
| 54 (pattr)->type = kind; \ | |
| 55 (pattr)->pValue = (CK_VOID_PTR)NULL; \ | |
| 56 (pattr)->ulValueLen = 0; \ | |
| 57 (pattr)++; | |
| 58 | |
| 59 #define NSS_CK_TEMPLATE_FINISH(_template, attr, size) \ | |
| 60 size = (attr) - (_template); \ | |
| 61 PR_ASSERT(size <= sizeof(_template) / sizeof(_template[0])); | |
| 62 | |
| 63 /* NSS_CK_ATTRIBUTE_TO_ITEM(attrib, item) | |
| 64 * | |
| 65 * Convert a CK_ATTRIBUTE to an NSSItem. | |
| 66 */ | |
| 67 #define NSS_CK_ATTRIBUTE_TO_ITEM(attrib, item) \ | |
| 68 if ((CK_LONG)(attrib)->ulValueLen > 0) { \ | |
| 69 (item)->data = (void *)(attrib)->pValue; \ | |
| 70 (item)->size = (PRUint32)(attrib)->ulValueLen; \ | |
| 71 } else { \ | |
| 72 (item)->data = 0; \ | |
| 73 (item)->size = 0; \ | |
| 74 } | |
| 75 | |
| 76 #define NSS_CK_ATTRIBUTE_TO_BOOL(attrib, boolvar) \ | |
| 77 if ((attrib)->ulValueLen > 0) { \ | |
| 78 if (*((CK_BBOOL *)(attrib)->pValue) == CK_TRUE) { \ | |
| 79 boolvar = PR_TRUE; \ | |
| 80 } else { \ | |
| 81 boolvar = PR_FALSE; \ | |
| 82 } \ | |
| 83 } | |
| 84 | |
| 85 #define NSS_CK_ATTRIBUTE_TO_ULONG(attrib, ulongvar) \ | |
| 86 if ((attrib)->ulValueLen > 0) { \ | |
| 87 ulongvar = *((CK_ULONG *)(attrib)->pValue); \ | |
| 88 } | |
| 89 | |
| 90 /* NSS_CK_ATTRIBUTE_TO_UTF8(attrib, str) | |
| 91 * | |
| 92 * Convert a CK_ATTRIBUTE to a string. | |
| 93 */ | |
| 94 #define NSS_CK_ATTRIBUTE_TO_UTF8(attrib, str) \ | |
| 95 str = (NSSUTF8 *)((attrib)->pValue); | |
| 96 | |
| 97 /* NSS_CK_ITEM_TO_ATTRIBUTE(item, attrib) | |
| 98 * | |
| 99 * Convert an NSSItem to a CK_ATTRIBUTE. | |
| 100 */ | |
| 101 #define NSS_CK_ITEM_TO_ATTRIBUTE(item, attrib) \ | |
| 102 (attrib)->pValue = (CK_VOID_PTR)(item)->data; \ | |
| 103 (attrib)->ulValueLen = (CK_ULONG)(item)->size; | |
| 104 | |
| 105 /* Get an array of attributes from an object. */ | |
| 106 NSS_EXTERN PRStatus | |
| 107 nssCKObject_GetAttributes( | |
| 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 /* Get a single attribute as an item. */ | |
| 116 NSS_EXTERN PRStatus | |
| 117 nssCKObject_GetAttributeItem( | |
| 118 CK_OBJECT_HANDLE object, | |
| 119 CK_ATTRIBUTE_TYPE attribute, | |
| 120 NSSArena *arenaOpt, | |
| 121 nssSession *session, | |
| 122 NSSSlot *slot, | |
| 123 NSSItem *rvItem); | |
| 124 | |
| 125 NSS_EXTERN PRBool | |
| 126 nssCKObject_IsAttributeTrue( | |
| 127 CK_OBJECT_HANDLE object, | |
| 128 CK_ATTRIBUTE_TYPE attribute, | |
| 129 nssSession *session, | |
| 130 NSSSlot *slot, | |
| 131 PRStatus *rvStatus); | |
| 132 | |
| 133 NSS_EXTERN PRStatus | |
| 134 nssCKObject_SetAttributes( | |
| 135 CK_OBJECT_HANDLE object, | |
| 136 CK_ATTRIBUTE_PTR obj_template, | |
| 137 CK_ULONG count, | |
| 138 nssSession *session, | |
| 139 NSSSlot *slot); | |
| 140 | |
| 141 NSS_EXTERN PRBool | |
| 142 nssCKObject_IsTokenObjectTemplate( | |
| 143 CK_ATTRIBUTE_PTR objectTemplate, | |
| 144 CK_ULONG otsize); | |
| 145 | |
| 146 PR_END_EXTERN_C | |
| 147 | |
| 148 #endif /* CKHELPER_H */ | |
| OLD | NEW |