| 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 #ifdef DEBUG | |
| 15 static const char CKHELPER_CVS_ID[] = "@(#) $RCSfile: ckhelper.h,v $ $Revision:
1.21 $ $Date: 2012/04/25 14:49:42 $"; | |
| 16 #endif /* DEBUG */ | |
| 17 | |
| 18 PR_BEGIN_EXTERN_C | |
| 19 | |
| 20 /* Some globals to keep from constantly redeclaring common cryptoki | |
| 21 * attribute types on the stack. | |
| 22 */ | |
| 23 | |
| 24 /* Boolean values */ | |
| 25 NSS_EXTERN_DATA const NSSItem g_ck_true; | |
| 26 NSS_EXTERN_DATA const NSSItem g_ck_false; | |
| 27 | |
| 28 /* Object classes */ | |
| 29 NSS_EXTERN_DATA const NSSItem g_ck_class_cert; | |
| 30 NSS_EXTERN_DATA const NSSItem g_ck_class_pubkey; | |
| 31 NSS_EXTERN_DATA const NSSItem g_ck_class_privkey; | |
| 32 | |
| 33 #define NSS_CK_TEMPLATE_START(_template, attr, size) \ | |
| 34 attr = _template; \ | |
| 35 size = 0; | |
| 36 | |
| 37 #define NSS_CK_SET_ATTRIBUTE_ITEM(pattr, kind, item) \ | |
| 38 (pattr)->type = kind; \ | |
| 39 (pattr)->pValue = (CK_VOID_PTR)(item)->data; \ | |
| 40 (pattr)->ulValueLen = (CK_ULONG)(item)->size; \ | |
| 41 (pattr)++; | |
| 42 | |
| 43 #define NSS_CK_SET_ATTRIBUTE_UTF8(pattr, kind, utf8) \ | |
| 44 (pattr)->type = kind; \ | |
| 45 (pattr)->pValue = (CK_VOID_PTR)utf8; \ | |
| 46 (pattr)->ulValueLen = (CK_ULONG)nssUTF8_Size(utf8, NULL); \ | |
| 47 if ((pattr)->ulValueLen) ((pattr)->ulValueLen)--; \ | |
| 48 (pattr)++; | |
| 49 | |
| 50 #define NSS_CK_SET_ATTRIBUTE_VAR(pattr, kind, var) \ | |
| 51 (pattr)->type = kind; \ | |
| 52 (pattr)->pValue = (CK_VOID_PTR)&var; \ | |
| 53 (pattr)->ulValueLen = (CK_ULONG)sizeof(var); \ | |
| 54 (pattr)++; | |
| 55 | |
| 56 #define NSS_CK_SET_ATTRIBUTE_NULL(pattr, kind) \ | |
| 57 (pattr)->type = kind; \ | |
| 58 (pattr)->pValue = (CK_VOID_PTR)NULL; \ | |
| 59 (pattr)->ulValueLen = 0; \ | |
| 60 (pattr)++; | |
| 61 | |
| 62 #define NSS_CK_TEMPLATE_FINISH(_template, attr, size) \ | |
| 63 size = (attr) - (_template); \ | |
| 64 PR_ASSERT(size <= sizeof(_template)/sizeof(_template[0])); | |
| 65 | |
| 66 /* NSS_CK_ATTRIBUTE_TO_ITEM(attrib, item) | |
| 67 * | |
| 68 * Convert a CK_ATTRIBUTE to an NSSItem. | |
| 69 */ | |
| 70 #define NSS_CK_ATTRIBUTE_TO_ITEM(attrib, item) \ | |
| 71 if ((CK_LONG)(attrib)->ulValueLen > 0) { \ | |
| 72 (item)->data = (void *)(attrib)->pValue; \ | |
| 73 (item)->size = (PRUint32)(attrib)->ulValueLen; \ | |
| 74 } else { \ | |
| 75 (item)->data = 0; \ | |
| 76 (item)->size = 0; \ | |
| 77 } | |
| 78 | |
| 79 #define NSS_CK_ATTRIBUTE_TO_BOOL(attrib, boolvar) \ | |
| 80 if ((attrib)->ulValueLen > 0) { \ | |
| 81 if (*((CK_BBOOL*)(attrib)->pValue) == CK_TRUE) { \ | |
| 82 boolvar = PR_TRUE; \ | |
| 83 } else { \ | |
| 84 boolvar = PR_FALSE; \ | |
| 85 } \ | |
| 86 } | |
| 87 | |
| 88 #define NSS_CK_ATTRIBUTE_TO_ULONG(attrib, ulongvar) \ | |
| 89 if ((attrib)->ulValueLen > 0) { \ | |
| 90 ulongvar = *((CK_ULONG*)(attrib)->pValue); \ | |
| 91 } | |
| 92 | |
| 93 /* NSS_CK_ATTRIBUTE_TO_UTF8(attrib, str) | |
| 94 * | |
| 95 * Convert a CK_ATTRIBUTE to a string. | |
| 96 */ | |
| 97 #define NSS_CK_ATTRIBUTE_TO_UTF8(attrib, str) \ | |
| 98 str = (NSSUTF8 *)((attrib)->pValue); | |
| 99 | |
| 100 /* NSS_CK_ITEM_TO_ATTRIBUTE(item, attrib) | |
| 101 * | |
| 102 * Convert an NSSItem to a CK_ATTRIBUTE. | |
| 103 */ | |
| 104 #define NSS_CK_ITEM_TO_ATTRIBUTE(item, attrib) \ | |
| 105 (attrib)->pValue = (CK_VOID_PTR)(item)->data; \ | |
| 106 (attrib)->ulValueLen = (CK_ULONG)(item)->size; \ | |
| 107 | |
| 108 /* Get an array of attributes from an object. */ | |
| 109 NSS_EXTERN PRStatus | |
| 110 nssCKObject_GetAttributes | |
| 111 ( | |
| 112 CK_OBJECT_HANDLE object, | |
| 113 CK_ATTRIBUTE_PTR obj_template, | |
| 114 CK_ULONG count, | |
| 115 NSSArena *arenaOpt, | |
| 116 nssSession *session, | |
| 117 NSSSlot *slot | |
| 118 ); | |
| 119 | |
| 120 /* Get a single attribute as an item. */ | |
| 121 NSS_EXTERN PRStatus | |
| 122 nssCKObject_GetAttributeItem | |
| 123 ( | |
| 124 CK_OBJECT_HANDLE object, | |
| 125 CK_ATTRIBUTE_TYPE attribute, | |
| 126 NSSArena *arenaOpt, | |
| 127 nssSession *session, | |
| 128 NSSSlot *slot, | |
| 129 NSSItem *rvItem | |
| 130 ); | |
| 131 | |
| 132 NSS_EXTERN PRBool | |
| 133 nssCKObject_IsAttributeTrue | |
| 134 ( | |
| 135 CK_OBJECT_HANDLE object, | |
| 136 CK_ATTRIBUTE_TYPE attribute, | |
| 137 nssSession *session, | |
| 138 NSSSlot *slot, | |
| 139 PRStatus *rvStatus | |
| 140 ); | |
| 141 | |
| 142 NSS_EXTERN PRStatus | |
| 143 nssCKObject_SetAttributes | |
| 144 ( | |
| 145 CK_OBJECT_HANDLE object, | |
| 146 CK_ATTRIBUTE_PTR obj_template, | |
| 147 CK_ULONG count, | |
| 148 nssSession *session, | |
| 149 NSSSlot *slot | |
| 150 ); | |
| 151 | |
| 152 NSS_EXTERN PRBool | |
| 153 nssCKObject_IsTokenObjectTemplate | |
| 154 ( | |
| 155 CK_ATTRIBUTE_PTR objectTemplate, | |
| 156 CK_ULONG otsize | |
| 157 ); | |
| 158 | |
| 159 PR_END_EXTERN_C | |
| 160 | |
| 161 #endif /* CKHELPER_H */ | |
| OLD | NEW |