updated makefiles
[gnutls.git] / lib / minitasn1 / libtasn1.h
blobe9337e2d8a2f3511d129bc3bfe18c1e1fa66607b
1 /*
2 * Copyright (C) 2002-2012 Free Software Foundation, Inc.
4 * This file is part of LIBTASN1.
6 * LIBTASN1 is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
11 * LIBTASN1 is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with LIBTASN1; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02110-1301, USA
23 #ifndef LIBTASN1_H
24 # define LIBTASN1_H
26 # ifndef ASN1_API
27 # if defined ASN1_BUILDING && defined HAVE_VISIBILITY && HAVE_VISIBILITY
28 # define ASN1_API __attribute__((__visibility__("default")))
29 # elif defined ASN1_BUILDING && defined _MSC_VER && ! defined ASN1_STATIC
30 # define ASN1_API __declspec(dllexport)
31 # elif defined _MSC_VER && ! defined ASN1_STATIC
32 # define ASN1_API __declspec(dllimport)
33 # else
34 # define ASN1_API
35 # endif
36 # endif
38 #include <stdio.h> /* for FILE* */
39 #include <sys/types.h>
40 #include <time.h>
42 #ifdef __cplusplus
43 extern "C"
45 #endif
47 #define ASN1_VERSION "2.14"
49 typedef int asn1_retCode; /* type returned by libtasn1 functions */
51 /*****************************************/
52 /* Errors returned by libtasn1 functions */
53 /*****************************************/
54 #define ASN1_SUCCESS 0
55 #define ASN1_FILE_NOT_FOUND 1
56 #define ASN1_ELEMENT_NOT_FOUND 2
57 #define ASN1_IDENTIFIER_NOT_FOUND 3
58 #define ASN1_DER_ERROR 4
59 #define ASN1_VALUE_NOT_FOUND 5
60 #define ASN1_GENERIC_ERROR 6
61 #define ASN1_VALUE_NOT_VALID 7
62 #define ASN1_TAG_ERROR 8
63 #define ASN1_TAG_IMPLICIT 9
64 #define ASN1_ERROR_TYPE_ANY 10
65 #define ASN1_SYNTAX_ERROR 11
66 #define ASN1_MEM_ERROR 12
67 #define ASN1_MEM_ALLOC_ERROR 13
68 #define ASN1_DER_OVERFLOW 14
69 #define ASN1_NAME_TOO_LONG 15
70 #define ASN1_ARRAY_ERROR 16
71 #define ASN1_ELEMENT_NOT_EMPTY 17
73 /*************************************/
74 /* Constants used in asn1_visit_tree */
75 /*************************************/
76 #define ASN1_PRINT_NAME 1
77 #define ASN1_PRINT_NAME_TYPE 2
78 #define ASN1_PRINT_NAME_TYPE_VALUE 3
79 #define ASN1_PRINT_ALL 4
81 /*****************************************/
82 /* Constants returned by asn1_read_tag */
83 /*****************************************/
84 #define ASN1_CLASS_UNIVERSAL 0x00 /* old: 1 */
85 #define ASN1_CLASS_APPLICATION 0x40 /* old: 2 */
86 #define ASN1_CLASS_CONTEXT_SPECIFIC 0x80 /* old: 3 */
87 #define ASN1_CLASS_PRIVATE 0xC0 /* old: 4 */
88 #define ASN1_CLASS_STRUCTURED 0x20
90 /*****************************************/
91 /* Constants returned by asn1_read_tag */
92 /*****************************************/
93 #define ASN1_TAG_BOOLEAN 0x01
94 #define ASN1_TAG_INTEGER 0x02
95 #define ASN1_TAG_SEQUENCE 0x10
96 #define ASN1_TAG_SET 0x11
97 #define ASN1_TAG_OCTET_STRING 0x04
98 #define ASN1_TAG_BIT_STRING 0x03
99 #define ASN1_TAG_UTCTime 0x17
100 #define ASN1_TAG_GENERALIZEDTime 0x18
101 #define ASN1_TAG_OBJECT_ID 0x06
102 #define ASN1_TAG_ENUMERATED 0x0A
103 #define ASN1_TAG_NULL 0x05
104 #define ASN1_TAG_GENERALSTRING 0x1B
106 /******************************************************/
107 /* Structure definition used for the node of the tree */
108 /* that represent an ASN.1 DEFINITION. */
109 /******************************************************/
111 #if !defined ASN1_BUILDING
112 /* This structure is also in internal.h, but then contains more
113 fields. You cannot make any modifications to these fields
114 without breaking ABI. */
115 struct node_asn_struct
117 char *name; /* Node name */
118 unsigned int type; /* Node type */
119 unsigned char *value; /* Node value */
120 int value_len;
121 struct node_asn_struct *down; /* Pointer to the son node */
122 struct node_asn_struct *right; /* Pointer to the brother node */
123 struct node_asn_struct *left; /* Pointer to the next list element */
125 #endif
127 typedef struct node_asn_struct node_asn;
129 typedef node_asn *ASN1_TYPE;
131 #define ASN1_TYPE_EMPTY NULL
133 /*****************************************/
134 /* For the on-disk format of ASN.1 trees */
135 /*****************************************/
136 struct static_struct_asn
138 const char *name; /* Node name */
139 unsigned int type; /* Node type */
140 const void *value; /* Node value */
142 typedef struct static_struct_asn ASN1_ARRAY_TYPE;
144 /* List of constants for field type of typedef node_asn */
145 #define ASN1_ETYPE_CONSTANT 1
146 #define ASN1_ETYPE_IDENTIFIER 2
147 #define ASN1_ETYPE_INTEGER 3
148 #define ASN1_ETYPE_BOOLEAN 4
149 #define ASN1_ETYPE_SEQUENCE 5
150 #define ASN1_ETYPE_BIT_STRING 6
151 #define ASN1_ETYPE_OCTET_STRING 7
152 #define ASN1_ETYPE_TAG 8
153 #define ASN1_ETYPE_DEFAULT 9
154 #define ASN1_ETYPE_SIZE 10
155 #define ASN1_ETYPE_SEQUENCE_OF 11
156 #define ASN1_ETYPE_OBJECT_ID 12
157 #define ASN1_ETYPE_ANY 13
158 #define ASN1_ETYPE_SET 14
159 #define ASN1_ETYPE_SET_OF 15
160 #define ASN1_ETYPE_DEFINITIONS 16
161 #define ASN1_ETYPE_TIME 17
162 #define ASN1_ETYPE_CHOICE 18
163 #define ASN1_ETYPE_IMPORTS 19
164 #define ASN1_ETYPE_NULL 20
165 #define ASN1_ETYPE_ENUMERATED 21
166 #define ASN1_ETYPE_GENERALSTRING 27
168 struct node_data_struct
170 const char *name; /* Node name */
171 const void *value; /* Node value */
172 unsigned int value_len; /* Node value size */
173 unsigned int type; /* Node value type (ASN1_ETYPE_*) */
175 typedef struct node_data_struct ASN1_DATA_NODE;
177 /***********************************/
178 /* Fixed constants */
179 /***********************************/
181 /* maximum number of characters of a name */
182 /* inside a file with ASN1 definitons */
183 #define ASN1_MAX_NAME_SIZE 128
185 /* maximum number of characters */
186 /* of a description message */
187 /* (null character included) */
188 #define ASN1_MAX_ERROR_DESCRIPTION_SIZE 128
190 /***********************************/
191 /* Functions definitions */
192 /***********************************/
194 extern ASN1_API asn1_retCode
195 asn1_parser2tree (const char *file_name,
196 ASN1_TYPE * definitions, char *errorDescription);
198 extern ASN1_API asn1_retCode
199 asn1_parser2array (const char *inputFileName,
200 const char *outputFileName,
201 const char *vectorName, char *errorDescription);
203 extern ASN1_API asn1_retCode
204 asn1_array2tree (const ASN1_ARRAY_TYPE * array,
205 ASN1_TYPE * definitions, char *errorDescription);
207 extern ASN1_API void
208 asn1_print_structure (FILE * out, ASN1_TYPE structure,
209 const char *name, int mode);
211 extern ASN1_API asn1_retCode
212 asn1_create_element (ASN1_TYPE definitions,
213 const char *source_name, ASN1_TYPE * element);
215 extern ASN1_API asn1_retCode asn1_delete_structure (ASN1_TYPE * structure);
217 extern ASN1_API asn1_retCode
218 asn1_delete_element (ASN1_TYPE structure, const char *element_name);
220 extern ASN1_API asn1_retCode
221 asn1_write_value (ASN1_TYPE node_root, const char *name,
222 const void *ivalue, int len);
224 extern ASN1_API asn1_retCode
225 asn1_read_value (ASN1_TYPE root, const char *name,
226 void *ivalue, int *len);
228 extern ASN1_API asn1_retCode
229 asn1_read_node_value (ASN1_TYPE node, ASN1_DATA_NODE* data);
231 extern ASN1_API asn1_retCode
232 asn1_number_of_elements (ASN1_TYPE element, const char *name, int *num);
234 extern ASN1_API asn1_retCode
235 asn1_der_coding (ASN1_TYPE element, const char *name,
236 void *ider, int *len, char *ErrorDescription);
238 extern ASN1_API asn1_retCode
239 asn1_der_decoding (ASN1_TYPE * element, const void *ider,
240 int len, char *errorDescription);
242 extern ASN1_API asn1_retCode
243 asn1_der_decoding_element (ASN1_TYPE * structure,
244 const char *elementName,
245 const void *ider, int len,
246 char *errorDescription);
248 extern ASN1_API asn1_retCode
249 asn1_der_decoding_startEnd (ASN1_TYPE element,
250 const void *ider, int len,
251 const char *name_element,
252 int *start, int *end);
254 extern ASN1_API asn1_retCode
255 asn1_expand_any_defined_by (ASN1_TYPE definitions, ASN1_TYPE * element);
257 extern ASN1_API asn1_retCode
258 asn1_expand_octet_string (ASN1_TYPE definitions,
259 ASN1_TYPE * element,
260 const char *octetName, const char *objectName);
262 extern ASN1_API asn1_retCode
263 asn1_read_tag (ASN1_TYPE root, const char *name,
264 int *tagValue, int *classValue);
266 extern ASN1_API const char *asn1_find_structure_from_oid (ASN1_TYPE
267 definitions,
268 const char
269 *oidValue);
271 extern ASN1_API const char *asn1_check_version (const char *req_version);
273 extern ASN1_API const char *asn1_strerror (asn1_retCode error);
275 extern ASN1_API void asn1_perror (asn1_retCode error);
277 /* DER utility functions. */
279 extern ASN1_API int
280 asn1_get_tag_der (const unsigned char *der, int der_len,
281 unsigned char *cls, int *len, unsigned long *tag);
283 extern ASN1_API void
284 asn1_octet_der (const unsigned char *str, int str_len,
285 unsigned char *der, int *der_len);
287 extern ASN1_API asn1_retCode
288 asn1_get_octet_der (const unsigned char *der, int der_len,
289 int *ret_len, unsigned char *str,
290 int str_size, int *str_len);
292 extern ASN1_API void asn1_bit_der (const unsigned char *str, int bit_len,
293 unsigned char *der, int *der_len);
295 extern ASN1_API asn1_retCode
296 asn1_get_bit_der (const unsigned char *der, int der_len,
297 int *ret_len, unsigned char *str,
298 int str_size, int *bit_len);
300 extern ASN1_API long
301 asn1_get_length_der (const unsigned char *der, int der_len, int *len);
303 extern ASN1_API long
304 asn1_get_length_ber (const unsigned char *ber, int ber_len, int *len);
306 extern ASN1_API void
307 asn1_length_der (unsigned long int len, unsigned char *ans, int *ans_len);
309 /* Other utility functions. */
311 extern ASN1_API ASN1_TYPE
312 asn1_find_node (ASN1_TYPE pointer, const char *name);
314 extern ASN1_API asn1_retCode
315 asn1_copy_node (ASN1_TYPE dst, const char *dst_name,
316 ASN1_TYPE src, const char *src_name);
318 /* Deprecated stuff. */
320 #ifndef ASN1_DISABLE_DEPRECATED
322 #define LIBTASN1_VERSION ASN1_VERSION
324 #ifndef MAX_NAME_SIZE
325 # define MAX_NAME_SIZE ASN1_MAX_NAME_SIZE
326 #endif
328 #ifndef MAX_ERROR_DESCRIPTION_SIZE
329 # define MAX_ERROR_DESCRIPTION_SIZE ASN1_MAX_ERROR_DESCRIPTION_SIZE
330 #endif
332 #ifndef __attribute__
333 /* This feature is available in gcc versions 2.5 and later. */
334 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
335 # define __attribute__(Spec) /* empty */
336 # endif
337 #endif
339 /* Use asn1_strerror instead. */
340 extern ASN1_API const char *libtasn1_strerror (asn1_retCode error)
341 __attribute__ ((deprecated));
343 /* Use asn1_perror instead. */
344 extern ASN1_API void
345 libtasn1_perror (asn1_retCode error) __attribute__ ((deprecated));
347 #endif
349 #ifdef __cplusplus
351 #endif
353 #endif /* LIBTASN1_H */