moved ca-certs.
[gnutls.git] / lib / minitasn1 / libtasn1.h
blob289fb5792a63e9d829e0040a5cdb691311563515
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.12"
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 /***********************************/
145 /* Fixed constants */
146 /***********************************/
148 /* maximum number of characters of a name */
149 /* inside a file with ASN1 definitons */
150 #define ASN1_MAX_NAME_SIZE 128
152 /* maximum number of characters */
153 /* of a description message */
154 /* (null character included) */
155 #define ASN1_MAX_ERROR_DESCRIPTION_SIZE 128
157 /***********************************/
158 /* Functions definitions */
159 /***********************************/
161 extern ASN1_API asn1_retCode
162 asn1_parser2tree (const char *file_name,
163 ASN1_TYPE * definitions, char *errorDescription);
165 extern ASN1_API asn1_retCode
166 asn1_parser2array (const char *inputFileName,
167 const char *outputFileName,
168 const char *vectorName, char *errorDescription);
170 extern ASN1_API asn1_retCode
171 asn1_array2tree (const ASN1_ARRAY_TYPE * array,
172 ASN1_TYPE * definitions, char *errorDescription);
174 extern ASN1_API void
175 asn1_print_structure (FILE * out, ASN1_TYPE structure,
176 const char *name, int mode);
178 extern ASN1_API asn1_retCode
179 asn1_create_element (ASN1_TYPE definitions,
180 const char *source_name, ASN1_TYPE * element);
182 extern ASN1_API asn1_retCode asn1_delete_structure (ASN1_TYPE * structure);
184 extern ASN1_API asn1_retCode
185 asn1_delete_element (ASN1_TYPE structure, const char *element_name);
187 extern ASN1_API asn1_retCode
188 asn1_write_value (ASN1_TYPE node_root, const char *name,
189 const void *ivalue, int len);
191 extern ASN1_API asn1_retCode
192 asn1_read_value (ASN1_TYPE root, const char *name,
193 void *ivalue, int *len);
195 extern ASN1_API asn1_retCode
196 asn1_number_of_elements (ASN1_TYPE element, const char *name, int *num);
198 extern ASN1_API asn1_retCode
199 asn1_der_coding (ASN1_TYPE element, const char *name,
200 void *ider, int *len, char *ErrorDescription);
202 extern ASN1_API asn1_retCode
203 asn1_der_decoding (ASN1_TYPE * element, const void *ider,
204 int len, char *errorDescription);
206 extern ASN1_API asn1_retCode
207 asn1_der_decoding_element (ASN1_TYPE * structure,
208 const char *elementName,
209 const void *ider, int len,
210 char *errorDescription);
212 extern ASN1_API asn1_retCode
213 asn1_der_decoding_startEnd (ASN1_TYPE element,
214 const void *ider, int len,
215 const char *name_element,
216 int *start, int *end);
218 extern ASN1_API asn1_retCode
219 asn1_expand_any_defined_by (ASN1_TYPE definitions, ASN1_TYPE * element);
221 extern ASN1_API asn1_retCode
222 asn1_expand_octet_string (ASN1_TYPE definitions,
223 ASN1_TYPE * element,
224 const char *octetName, const char *objectName);
226 extern ASN1_API asn1_retCode
227 asn1_read_tag (ASN1_TYPE root, const char *name,
228 int *tagValue, int *classValue);
230 extern ASN1_API const char *asn1_find_structure_from_oid (ASN1_TYPE
231 definitions,
232 const char
233 *oidValue);
235 extern ASN1_API const char *asn1_check_version (const char *req_version);
237 extern ASN1_API const char *asn1_strerror (asn1_retCode error);
239 extern ASN1_API void asn1_perror (asn1_retCode error);
241 /* DER utility functions. */
243 extern ASN1_API int
244 asn1_get_tag_der (const unsigned char *der, int der_len,
245 unsigned char *cls, int *len, unsigned long *tag);
247 extern ASN1_API void
248 asn1_octet_der (const unsigned char *str, int str_len,
249 unsigned char *der, int *der_len);
251 extern ASN1_API asn1_retCode
252 asn1_get_octet_der (const unsigned char *der, int der_len,
253 int *ret_len, unsigned char *str,
254 int str_size, int *str_len);
256 extern ASN1_API void asn1_bit_der (const unsigned char *str, int bit_len,
257 unsigned char *der, int *der_len);
259 extern ASN1_API asn1_retCode
260 asn1_get_bit_der (const unsigned char *der, int der_len,
261 int *ret_len, unsigned char *str,
262 int str_size, int *bit_len);
264 extern ASN1_API signed long
265 asn1_get_length_der (const unsigned char *der, int der_len, int *len);
267 extern ASN1_API signed long
268 asn1_get_length_ber (const unsigned char *ber, int ber_len, int *len);
270 extern ASN1_API void
271 asn1_length_der (unsigned long int len, unsigned char *ans, int *ans_len);
273 /* Other utility functions. */
275 extern ASN1_API ASN1_TYPE
276 asn1_find_node (ASN1_TYPE pointer, const char *name);
278 extern ASN1_API asn1_retCode
279 asn1_copy_node (ASN1_TYPE dst, const char *dst_name,
280 ASN1_TYPE src, const char *src_name);
282 /* Deprecated stuff. */
284 #ifndef ASN1_DISABLE_DEPRECATED
286 #define LIBTASN1_VERSION ASN1_VERSION
288 #ifndef MAX_NAME_SIZE
289 # define MAX_NAME_SIZE ASN1_MAX_NAME_SIZE
290 #endif
292 #ifndef MAX_ERROR_DESCRIPTION_SIZE
293 # define MAX_ERROR_DESCRIPTION_SIZE ASN1_MAX_ERROR_DESCRIPTION_SIZE
294 #endif
296 #ifndef __attribute__
297 /* This feature is available in gcc versions 2.5 and later. */
298 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
299 # define __attribute__(Spec) /* empty */
300 # endif
301 #endif
303 /* Use asn1_strerror instead. */
304 extern ASN1_API const char *libtasn1_strerror (asn1_retCode error)
305 __attribute__ ((deprecated));
307 /* Use asn1_perror instead. */
308 extern ASN1_API void
309 libtasn1_perror (asn1_retCode error) __attribute__ ((deprecated));
311 #endif
313 #ifdef __cplusplus
315 #endif
317 #endif /* LIBTASN1_H */