/lib/libmicrohttpd/src/daemon/https/minitasn1/libtasn1.h

http://github.com/xbmc/xbmc · C++ Header · 216 lines · 126 code · 44 blank · 46 comment · 0 complexity · 4dd2b6ccbab2625ea2e1b3c5fb420e14 MD5 · raw file

  1. /*
  2. * Copyright (C) 2004, 2005, 2006 Free Software Foundation
  3. * Copyright (C) 2002 Fabio Fiorina
  4. *
  5. * This file is part of LIBTASN1.
  6. *
  7. * LIBTASN1 is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * LIBTASN1 is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with LIBTASN1; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. * 02110-1301, USA
  21. *
  22. */
  23. #ifndef LIBTASN1_H
  24. # define LIBTASN1_H
  25. #include <stdio.h> /* for FILE* */
  26. #ifdef __cplusplus
  27. extern "C"
  28. {
  29. #endif
  30. #define LIBTASN1_VERSION "1.2"
  31. #include <sys/types.h>
  32. #include <time.h>
  33. #define MAX_NAME_SIZE 128 /* maximum number of characters of a name */
  34. /* inside a file with ASN1 definitons */
  35. #define MAX_ERROR_DESCRIPTION_SIZE 128 /* maximum number of characters */
  36. /* of a description message */
  37. /* (null character included) */
  38. typedef int MHD__asn1_retCode; /* type returned by libtasn1 functions */
  39. /*****************************************/
  40. /* Errors returned by libtasn1 functions */
  41. /*****************************************/
  42. #define ASN1_SUCCESS 0
  43. #define ASN1_FILE_NOT_FOUND 1
  44. #define ASN1_ELEMENT_NOT_FOUND 2
  45. #define ASN1_IDENTIFIER_NOT_FOUND 3
  46. #define ASN1_DER_ERROR 4
  47. #define ASN1_VALUE_NOT_FOUND 5
  48. #define ASN1_GENERIC_ERROR 6
  49. #define ASN1_VALUE_NOT_VALID 7
  50. #define ASN1_TAG_ERROR 8
  51. #define ASN1_TAG_IMPLICIT 9
  52. #define ASN1_ERROR_TYPE_ANY 10
  53. #define ASN1_SYNTAX_ERROR 11
  54. #define ASN1_MEM_ERROR 12
  55. #define ASN1_MEM_ALLOC_ERROR 13
  56. #define ASN1_DER_OVERFLOW 14
  57. #define ASN1_NAME_TOO_LONG 15
  58. #define ASN1_ARRAY_ERROR 16
  59. #define ASN1_ELEMENT_NOT_EMPTY 17
  60. /*************************************/
  61. /* Constants used in MHD__asn1_visit_tree */
  62. /*************************************/
  63. #define ASN1_PRINT_NAME 1
  64. #define ASN1_PRINT_NAME_TYPE 2
  65. #define ASN1_PRINT_NAME_TYPE_VALUE 3
  66. #define ASN1_PRINT_ALL 4
  67. /*****************************************/
  68. /* Constants returned by MHD__asn1_read_tag */
  69. /*****************************************/
  70. #define ASN1_CLASS_UNIVERSAL 0x00 /* old: 1 */
  71. #define ASN1_CLASS_APPLICATION 0x40 /* old: 2 */
  72. #define ASN1_CLASS_CONTEXT_SPECIFIC 0x80 /* old: 3 */
  73. #define ASN1_CLASS_PRIVATE 0xC0 /* old: 4 */
  74. #define ASN1_CLASS_STRUCTURED 0x20
  75. /*****************************************/
  76. /* Constants returned by MHD__asn1_read_tag */
  77. /*****************************************/
  78. #define ASN1_TAG_BOOLEAN 0x01
  79. #define ASN1_TAG_INTEGER 0x02
  80. #define ASN1_TAG_SEQUENCE 0x10
  81. #define ASN1_TAG_SET 0x11
  82. #define ASN1_TAG_OCTET_STRING 0x04
  83. #define ASN1_TAG_BIT_STRING 0x03
  84. #define ASN1_TAG_UTCTime 0x17
  85. #define ASN1_TAG_GENERALIZEDTime 0x18
  86. #define ASN1_TAG_OBJECT_ID 0x06
  87. #define ASN1_TAG_ENUMERATED 0x0A
  88. #define ASN1_TAG_NULL 0x05
  89. #define ASN1_TAG_GENERALSTRING 0x1B
  90. /******************************************************/
  91. /* Structure definition used for the node of the tree */
  92. /* that represent an ASN.1 DEFINITION. */
  93. /******************************************************/
  94. struct node_asn_struct
  95. {
  96. char *name; /* Node name */
  97. unsigned int type; /* Node type */
  98. unsigned char *value; /* Node value */
  99. int value_len;
  100. struct node_asn_struct *down; /* Pointer to the son node */
  101. struct node_asn_struct *right; /* Pointer to the brother node */
  102. struct node_asn_struct *left; /* Pointer to the next list element */
  103. };
  104. typedef struct node_asn_struct node_asn;
  105. typedef node_asn *ASN1_TYPE;
  106. #define ASN1_TYPE_EMPTY NULL
  107. struct static_struct_asn
  108. {
  109. const char *name; /* Node name */
  110. unsigned int type; /* Node type */
  111. const void *value; /* Node value */
  112. };
  113. typedef struct static_struct_asn ASN1_ARRAY_TYPE;
  114. /***********************************/
  115. /* Functions definitions */
  116. /***********************************/
  117. MHD__asn1_retCode MHD__asn1_parser2tree (const char *file_name,
  118. ASN1_TYPE * definitions,
  119. char *errorDescription);
  120. MHD__asn1_retCode MHD__asn1_parser2array (const char *inputFileName,
  121. const char *outputFileName,
  122. const char *vectorName,
  123. char *errorDescription);
  124. MHD__asn1_retCode MHD__asn1_array2tree (const ASN1_ARRAY_TYPE * array,
  125. ASN1_TYPE * definitions,
  126. char *errorDescription);
  127. MHD__asn1_retCode MHD__asn1_create_element (ASN1_TYPE definitions,
  128. const char *source_name,
  129. ASN1_TYPE * element);
  130. MHD__asn1_retCode MHD__asn1_delete_structure (ASN1_TYPE * structure);
  131. MHD__asn1_retCode MHD__asn1_write_value (ASN1_TYPE node_root,
  132. const char *name,
  133. const void *ivalue, int len);
  134. MHD__asn1_retCode MHD__asn1_read_value (ASN1_TYPE root, const char *name,
  135. void *ivalue, int *len);
  136. MHD__asn1_retCode MHD__asn1_der_coding (ASN1_TYPE element, const char *name,
  137. void *ider, int *len,
  138. char *ErrorDescription);
  139. MHD__asn1_retCode MHD__asn1_der_decoding (ASN1_TYPE * element,
  140. const void *ider, int len,
  141. char *errorDescription);
  142. MHD__asn1_retCode MHD__asn1_der_decoding_startEnd (ASN1_TYPE element,
  143. const void *ider,
  144. int len,
  145. const char *name_element,
  146. int *start, int *end);
  147. /* DER utility functions. */
  148. int MHD__asn1_get_tag_der (const unsigned char *der, int der_len,
  149. unsigned char *cls, int *len,
  150. unsigned long *tag);
  151. void MHD__asn1_octet_der (const unsigned char *str, int str_len,
  152. unsigned char *der, int *der_len);
  153. MHD__asn1_retCode MHD__asn1_get_octet_der (const unsigned char *der,
  154. int der_len, int *ret_len,
  155. unsigned char *str, int str_size,
  156. int *str_len);
  157. void MHD__asn1_bit_der (const unsigned char *str, int bit_len,
  158. unsigned char *der, int *der_len);
  159. MHD__asn1_retCode MHD__asn1_get_bit_der (const unsigned char *der,
  160. int der_len, int *ret_len,
  161. unsigned char *str, int str_size,
  162. int *bit_len);
  163. signed long MHD__asn1_get_length_der (const unsigned char *der, int der_len,
  164. int *len);
  165. void MHD__asn1_length_der (unsigned long int len, unsigned char *ans,
  166. int *ans_len);
  167. /* Other utility functions. */
  168. ASN1_TYPE MHD__asn1_find_node (ASN1_TYPE pointer, const char *name);
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172. #endif /* LIBTASN1_H */