uri.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * Copyright (c) 2011 Collabora Ltd.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * * Redistributions of source code must retain the above
  9. * copyright notice, this list of conditions and the
  10. * following disclaimer.
  11. * * Redistributions in binary form must reproduce the
  12. * above copyright notice, this list of conditions and
  13. * the following disclaimer in the documentation and/or
  14. * other materials provided with the distribution.
  15. * * The names of contributors to this software may not be
  16. * used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  30. * DAMAGE.
  31. *
  32. * Author: Stef Walter <stefw@collabora.co.uk>
  33. */
  34. #ifndef P11_KIT_URI_H
  35. #define P11_KIT_URI_H
  36. #include "p11-kit/pkcs11.h"
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. #define P11_KIT_URI_SCHEME "pkcs11"
  41. #define P11_KIT_URI_SCHEME_LEN 6
  42. typedef enum {
  43. P11_KIT_URI_OK = 0,
  44. P11_KIT_URI_UNEXPECTED = -1,
  45. P11_KIT_URI_BAD_SCHEME = -2,
  46. P11_KIT_URI_BAD_ENCODING = -3,
  47. P11_KIT_URI_BAD_SYNTAX = -4,
  48. P11_KIT_URI_BAD_VERSION = -5,
  49. P11_KIT_URI_NOT_FOUND = -6,
  50. } P11KitUriResult;
  51. #define P11_KIT_URI_NO_MEMORY P11_KIT_URI_UNEXPECTED
  52. typedef enum {
  53. P11_KIT_URI_FOR_OBJECT = (1 << 1),
  54. P11_KIT_URI_FOR_TOKEN = (1 << 2),
  55. P11_KIT_URI_FOR_SLOT = (1 << 5),
  56. P11_KIT_URI_FOR_MODULE = (1 << 3),
  57. P11_KIT_URI_FOR_MODULE_WITH_VERSION =
  58. (1 << 4) | P11_KIT_URI_FOR_MODULE,
  59. P11_KIT_URI_FOR_OBJECT_ON_TOKEN =
  60. P11_KIT_URI_FOR_OBJECT | P11_KIT_URI_FOR_TOKEN,
  61. P11_KIT_URI_FOR_OBJECT_ON_TOKEN_AND_MODULE =
  62. P11_KIT_URI_FOR_OBJECT_ON_TOKEN | P11_KIT_URI_FOR_MODULE,
  63. P11_KIT_URI_FOR_ANY = 0x0000FFFF,
  64. } P11KitUriType;
  65. /*
  66. * If the caller is using the PKCS#11 GNU calling convention, then we cater
  67. * to that here.
  68. */
  69. #ifdef CRYPTOKI_GNU
  70. typedef struct ck_info CK_INFO;
  71. typedef struct ck_info *CK_INFO_PTR;
  72. typedef struct ck_token_info CK_TOKEN_INFO;
  73. typedef struct ck_token_info *CK_TOKEN_INFO_PTR;
  74. typedef ck_attribute_type_t CK_ATTRIBUTE_TYPE;
  75. typedef struct ck_attribute CK_ATTRIBUTE;
  76. typedef struct ck_attribute *CK_ATTRIBUTE_PTR;
  77. typedef unsigned long int CK_ULONG;
  78. typedef struct ck_slot_info CK_SLOT_INFO;
  79. typedef struct ck_slot_info *CK_SLOT_INFO_PTR;
  80. typedef ck_slot_id_t CK_SLOT_ID;
  81. typedef P11KitUriType p11_kit_uri_type_t;
  82. typedef P11KitUriResult p11_kit_uri_result_t;
  83. #endif
  84. typedef struct p11_kit_uri P11KitUri;
  85. typedef struct p11_kit_uri p11_kit_uri;
  86. CK_INFO_PTR p11_kit_uri_get_module_info (P11KitUri *uri);
  87. int p11_kit_uri_match_module_info (const P11KitUri *uri,
  88. const CK_INFO *info);
  89. CK_SLOT_INFO_PTR p11_kit_uri_get_slot_info (P11KitUri *uri);
  90. int p11_kit_uri_match_slot_info (const P11KitUri *uri,
  91. const CK_SLOT_INFO *slot_info);
  92. CK_SLOT_ID p11_kit_uri_get_slot_id (P11KitUri *uri);
  93. void p11_kit_uri_set_slot_id (P11KitUri *uri,
  94. CK_SLOT_ID slot_id);
  95. CK_TOKEN_INFO_PTR p11_kit_uri_get_token_info (P11KitUri *uri);
  96. int p11_kit_uri_match_token_info (const P11KitUri *uri,
  97. const CK_TOKEN_INFO *token_info);
  98. CK_ATTRIBUTE_PTR p11_kit_uri_get_attribute (P11KitUri *uri,
  99. CK_ATTRIBUTE_TYPE attr_type);
  100. int p11_kit_uri_set_attribute (P11KitUri *uri,
  101. CK_ATTRIBUTE_PTR attr);
  102. int p11_kit_uri_clear_attribute (P11KitUri *uri,
  103. CK_ATTRIBUTE_TYPE attr_type);
  104. CK_ATTRIBUTE_PTR p11_kit_uri_get_attributes (P11KitUri *uri,
  105. CK_ULONG *n_attrs);
  106. int p11_kit_uri_set_attributes (P11KitUri *uri,
  107. CK_ATTRIBUTE_PTR attrs,
  108. CK_ULONG n_attrs);
  109. void p11_kit_uri_clear_attributes (P11KitUri *uri);
  110. int p11_kit_uri_match_attributes (const P11KitUri *uri,
  111. const CK_ATTRIBUTE *attrs,
  112. CK_ULONG n_attrs);
  113. const char* p11_kit_uri_get_pin_value (const P11KitUri *uri);
  114. void p11_kit_uri_set_pin_value (P11KitUri *uri,
  115. const char *pin);
  116. const char* p11_kit_uri_get_pin_source (const P11KitUri *uri);
  117. void p11_kit_uri_set_pin_source (P11KitUri *uri,
  118. const char *pin_source);
  119. #ifndef P11_KIT_DISABLE_DEPRECATED
  120. const char* p11_kit_uri_get_pinfile (const P11KitUri *uri);
  121. void p11_kit_uri_set_pinfile (P11KitUri *uri,
  122. const char *pinfile);
  123. #endif /* P11_KIT_DISABLE_DEPRECATED */
  124. const char* p11_kit_uri_get_module_name (const P11KitUri *uri);
  125. void p11_kit_uri_set_module_name (P11KitUri *uri,
  126. const char *name);
  127. const char* p11_kit_uri_get_module_path (const P11KitUri *uri);
  128. void p11_kit_uri_set_module_path (P11KitUri *uri,
  129. const char *path);
  130. const char* p11_kit_uri_get_vendor_query (const P11KitUri *uri,
  131. const char *name);
  132. int p11_kit_uri_set_vendor_query (P11KitUri *uri,
  133. const char *name,
  134. const char *value);
  135. void p11_kit_uri_set_unrecognized (P11KitUri *uri,
  136. int unrecognized);
  137. int p11_kit_uri_any_unrecognized (P11KitUri *uri);
  138. P11KitUri* p11_kit_uri_new (void);
  139. int p11_kit_uri_format (P11KitUri *uri,
  140. P11KitUriType uri_type,
  141. char **string);
  142. int p11_kit_uri_parse (const char *string,
  143. P11KitUriType uri_type,
  144. P11KitUri *uri);
  145. void p11_kit_uri_free (P11KitUri *uri);
  146. const char* p11_kit_uri_message (int code);
  147. #ifdef __cplusplus
  148. } /* extern "C" */
  149. #endif
  150. #endif /* P11_KIT_URI_H */