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