PageRenderTime 20ms CodeModel.GetById 12ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/security/nss/lib/dev/ckhelper.h

http://github.com/zpao/v8monkey
C Header | 193 lines | 109 code | 25 blank | 59 comment | 8 complexity | a73fafdd3ac06d6fec87ed9a41728c64 MD5 | raw file
  1/* ***** BEGIN LICENSE BLOCK *****
  2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3 *
  4 * The contents of this file are subject to the Mozilla Public License Version
  5 * 1.1 (the "License"); you may not use this file except in compliance with
  6 * the License. You may obtain a copy of the License at
  7 * http://www.mozilla.org/MPL/
  8 *
  9 * Software distributed under the License is distributed on an "AS IS" basis,
 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 11 * for the specific language governing rights and limitations under the
 12 * License.
 13 *
 14 * The Original Code is the Netscape security libraries.
 15 *
 16 * The Initial Developer of the Original Code is
 17 * Netscape Communications Corporation.
 18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
 19 * the Initial Developer. All Rights Reserved.
 20 *
 21 * Contributor(s):
 22 *
 23 * Alternatively, the contents of this file may be used under the terms of
 24 * either the GNU General Public License Version 2 or later (the "GPL"), or
 25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 26 * in which case the provisions of the GPL or the LGPL are applicable instead
 27 * of those above. If you wish to allow use of your version of this file only
 28 * under the terms of either the GPL or the LGPL, and not to allow others to
 29 * use your version of this file under the terms of the MPL, indicate your
 30 * decision by deleting the provisions above and replace them with the notice
 31 * and other provisions required by the GPL or the LGPL. If you do not delete
 32 * the provisions above, a recipient may use your version of this file under
 33 * the terms of any one of the MPL, the GPL or the LGPL.
 34 *
 35 * ***** END LICENSE BLOCK ***** */
 36
 37/*
 38 * ckhelper.h
 39 *
 40 * This file contains some helper utilities for interaction with cryptoki.
 41 */
 42
 43#ifndef CKHELPER_H
 44#define CKHELPER_H
 45
 46#ifdef DEBUG
 47static const char CKHELPER_CVS_ID[] = "@(#) $RCSfile: ckhelper.h,v $ $Revision: 1.20 $ $Date: 2010/01/08 02:00:58 $";
 48#endif /* DEBUG */
 49
 50PR_BEGIN_EXTERN_C
 51
 52/* Some globals to keep from constantly redeclaring common cryptoki
 53 * attribute types on the stack.
 54 */
 55
 56/* Boolean values */
 57NSS_EXTERN_DATA const NSSItem g_ck_true;
 58NSS_EXTERN_DATA const NSSItem g_ck_false;
 59
 60/* Object classes */
 61NSS_EXTERN_DATA const NSSItem g_ck_class_cert;
 62NSS_EXTERN_DATA const NSSItem g_ck_class_pubkey;
 63NSS_EXTERN_DATA const NSSItem g_ck_class_privkey;
 64
 65#define NSS_CK_TEMPLATE_START(_template, attr, size)   \
 66    attr = _template;                                  \
 67    size = 0;
 68
 69#define NSS_CK_SET_ATTRIBUTE_ITEM(pattr, kind, item)  \
 70    (pattr)->type = kind;                             \
 71    (pattr)->pValue = (CK_VOID_PTR)(item)->data;      \
 72    (pattr)->ulValueLen = (CK_ULONG)(item)->size;     \
 73    (pattr)++;
 74
 75#define NSS_CK_SET_ATTRIBUTE_UTF8(pattr, kind, utf8)  \
 76    (pattr)->type = kind;                             \
 77    (pattr)->pValue = (CK_VOID_PTR)utf8;              \
 78    (pattr)->ulValueLen = (CK_ULONG)nssUTF8_Size(utf8, NULL); \
 79    if ((pattr)->ulValueLen) ((pattr)->ulValueLen)--; \
 80    (pattr)++;
 81
 82#define NSS_CK_SET_ATTRIBUTE_VAR(pattr, kind, var)    \
 83    (pattr)->type = kind;                             \
 84    (pattr)->pValue = (CK_VOID_PTR)&var;              \
 85    (pattr)->ulValueLen = (CK_ULONG)sizeof(var);      \
 86    (pattr)++;
 87
 88#define NSS_CK_SET_ATTRIBUTE_NULL(pattr, kind)        \
 89    (pattr)->type = kind;                             \
 90    (pattr)->pValue = (CK_VOID_PTR)NULL;              \
 91    (pattr)->ulValueLen = 0;                          \
 92    (pattr)++;
 93
 94#define NSS_CK_TEMPLATE_FINISH(_template, attr, size) \
 95    size = (attr) - (_template);                      \
 96    PR_ASSERT(size <= sizeof(_template)/sizeof(_template[0]));
 97
 98/* NSS_CK_ATTRIBUTE_TO_ITEM(attrib, item)
 99 *
100 * Convert a CK_ATTRIBUTE to an NSSItem.
101 */
102#define NSS_CK_ATTRIBUTE_TO_ITEM(attrib, item)         \
103    if ((CK_LONG)(attrib)->ulValueLen > 0) {           \
104	(item)->data = (void *)(attrib)->pValue;       \
105	(item)->size = (PRUint32)(attrib)->ulValueLen; \
106    } else {                                           \
107	(item)->data = 0;                              \
108	(item)->size = 0;                              \
109    }
110
111#define NSS_CK_ATTRIBUTE_TO_BOOL(attrib, boolvar)        \
112    if ((attrib)->ulValueLen > 0) {                      \
113	if (*((CK_BBOOL*)(attrib)->pValue) == CK_TRUE) { \
114	    boolvar = PR_TRUE;                           \
115	} else {                                         \
116	    boolvar = PR_FALSE;                          \
117	}                                                \
118    }
119
120#define NSS_CK_ATTRIBUTE_TO_ULONG(attrib, ulongvar)      \
121    if ((attrib)->ulValueLen > 0) {                      \
122	ulongvar = *((CK_ULONG*)(attrib)->pValue);       \
123    }
124
125/* NSS_CK_ATTRIBUTE_TO_UTF8(attrib, str)
126 *
127 * Convert a CK_ATTRIBUTE to a string.
128 */
129#define NSS_CK_ATTRIBUTE_TO_UTF8(attrib, str)      \
130    str = (NSSUTF8 *)((attrib)->pValue);
131
132/* NSS_CK_ITEM_TO_ATTRIBUTE(item, attrib)
133 *
134 * Convert an NSSItem to a  CK_ATTRIBUTE.
135 */
136#define NSS_CK_ITEM_TO_ATTRIBUTE(item, attrib)     \
137    (attrib)->pValue = (CK_VOID_PTR)(item)->data;  \
138    (attrib)->ulValueLen = (CK_ULONG)(item)->size; \
139
140/* Get an array of attributes from an object. */
141NSS_EXTERN PRStatus 
142nssCKObject_GetAttributes
143(
144  CK_OBJECT_HANDLE object,
145  CK_ATTRIBUTE_PTR obj_template,
146  CK_ULONG count,
147  NSSArena *arenaOpt,
148  nssSession *session,
149  NSSSlot *slot
150);
151
152/* Get a single attribute as an item. */
153NSS_EXTERN PRStatus
154nssCKObject_GetAttributeItem
155(
156  CK_OBJECT_HANDLE object,
157  CK_ATTRIBUTE_TYPE attribute,
158  NSSArena *arenaOpt,
159  nssSession *session,
160  NSSSlot *slot,
161  NSSItem *rvItem
162);
163
164NSS_EXTERN PRBool
165nssCKObject_IsAttributeTrue
166(
167  CK_OBJECT_HANDLE object,
168  CK_ATTRIBUTE_TYPE attribute,
169  nssSession *session,
170  NSSSlot *slot,
171  PRStatus *rvStatus
172);
173
174NSS_EXTERN PRStatus 
175nssCKObject_SetAttributes
176(
177  CK_OBJECT_HANDLE object,
178  CK_ATTRIBUTE_PTR obj_template,
179  CK_ULONG count,
180  nssSession *session,
181  NSSSlot  *slot
182);
183
184NSS_EXTERN PRBool
185nssCKObject_IsTokenObjectTemplate
186(
187  CK_ATTRIBUTE_PTR objectTemplate, 
188  CK_ULONG otsize
189);
190
191PR_END_EXTERN_C
192
193#endif /* CKHELPER_H */