Initialize Tizen 2.3
[external/libtasn1.git] / lib / libtasn1.h
1 /*
2  * Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
3  * Software Foundation, Inc.
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
24 #ifndef LIBTASN1_H
25 # define LIBTASN1_H
26
27 # ifndef ASN1_API
28 #  if defined ASN1_BUILDING && defined HAVE_VISIBILITY && HAVE_VISIBILITY
29 #   define ASN1_API __attribute__((__visibility__("default")))
30 #  elif defined ASN1_BUILDING && defined _MSC_VER && ! defined ASN1_STATIC
31 #   define ASN1_API __declspec(dllexport)
32 #  elif defined _MSC_VER && ! defined ASN1_STATIC
33 #   define ASN1_API __declspec(dllimport)
34 #  else
35 #   define ASN1_API
36 #  endif
37 # endif
38
39 #include <stdio.h>              /* for FILE* */
40 #include <sys/types.h>
41 #include <time.h>
42
43 #ifdef __cplusplus
44 extern "C"
45 {
46 #endif
47
48 #define ASN1_VERSION "2.7"
49
50   typedef int asn1_retCode;     /* type returned by libtasn1 functions */
51
52   /*****************************************/
53   /* Errors returned by libtasn1 functions */
54   /*****************************************/
55 #define ASN1_SUCCESS                    0
56 #define ASN1_FILE_NOT_FOUND             1
57 #define ASN1_ELEMENT_NOT_FOUND          2
58 #define ASN1_IDENTIFIER_NOT_FOUND       3
59 #define ASN1_DER_ERROR                  4
60 #define ASN1_VALUE_NOT_FOUND            5
61 #define ASN1_GENERIC_ERROR              6
62 #define ASN1_VALUE_NOT_VALID            7
63 #define ASN1_TAG_ERROR                  8
64 #define ASN1_TAG_IMPLICIT               9
65 #define ASN1_ERROR_TYPE_ANY             10
66 #define ASN1_SYNTAX_ERROR               11
67 #define ASN1_MEM_ERROR                  12
68 #define ASN1_MEM_ALLOC_ERROR            13
69 #define ASN1_DER_OVERFLOW               14
70 #define ASN1_NAME_TOO_LONG              15
71 #define ASN1_ARRAY_ERROR                16
72 #define ASN1_ELEMENT_NOT_EMPTY          17
73
74   /*************************************/
75   /* Constants used in asn1_visit_tree */
76   /*************************************/
77 #define ASN1_PRINT_NAME                 1
78 #define ASN1_PRINT_NAME_TYPE            2
79 #define ASN1_PRINT_NAME_TYPE_VALUE      3
80 #define ASN1_PRINT_ALL                  4
81
82   /*****************************************/
83   /* Constants returned by asn1_read_tag   */
84   /*****************************************/
85 #define ASN1_CLASS_UNIVERSAL            0x00    /* old: 1 */
86 #define ASN1_CLASS_APPLICATION          0x40    /* old: 2 */
87 #define ASN1_CLASS_CONTEXT_SPECIFIC     0x80    /* old: 3 */
88 #define ASN1_CLASS_PRIVATE              0xC0    /* old: 4 */
89 #define ASN1_CLASS_STRUCTURED           0x20
90
91   /*****************************************/
92   /* Constants returned by asn1_read_tag   */
93   /*****************************************/
94 #define ASN1_TAG_BOOLEAN                0x01
95 #define ASN1_TAG_INTEGER                0x02
96 #define ASN1_TAG_SEQUENCE               0x10
97 #define ASN1_TAG_SET                    0x11
98 #define ASN1_TAG_OCTET_STRING           0x04
99 #define ASN1_TAG_BIT_STRING             0x03
100 #define ASN1_TAG_UTCTime                0x17
101 #define ASN1_TAG_GENERALIZEDTime        0x18
102 #define ASN1_TAG_OBJECT_ID              0x06
103 #define ASN1_TAG_ENUMERATED             0x0A
104 #define ASN1_TAG_NULL                   0x05
105 #define ASN1_TAG_GENERALSTRING          0x1B
106
107   /******************************************************/
108   /* Structure definition used for the node of the tree */
109   /* that represent an ASN.1 DEFINITION.                */
110   /******************************************************/
111
112 #if !defined ASN1_BUILDING
113   /* This structure is also in internal.h, but then contains more
114      fields.  You cannot make any modifications to these fields
115      without breaking ABI.  */
116   struct node_asn_struct
117   {
118     char *name;                 /* Node name */
119     unsigned int type;          /* Node type */
120     unsigned char *value;       /* Node value */
121     int value_len;
122     struct node_asn_struct *down;       /* Pointer to the son node */
123     struct node_asn_struct *right;      /* Pointer to the brother node */
124     struct node_asn_struct *left;       /* Pointer to the next list element */
125   };
126 #endif
127
128   typedef struct node_asn_struct node_asn;
129
130   typedef node_asn *ASN1_TYPE;
131
132 #define ASN1_TYPE_EMPTY  NULL
133
134   /*****************************************/
135   /* For the on-disk format of ASN.1 trees */
136   /*****************************************/
137   struct static_struct_asn
138   {
139     const char *name;           /* Node name */
140     unsigned int type;          /* Node type */
141     const void *value;          /* Node value */
142   };
143   typedef struct static_struct_asn ASN1_ARRAY_TYPE;
144
145   /***********************************/
146   /*  Fixed constants                */
147   /***********************************/
148
149   /* maximum number of characters of a name */
150   /* inside a file with ASN1 definitons     */
151 #define ASN1_MAX_NAME_SIZE 128
152
153   /* maximum number of characters */
154   /* of a description message     */
155   /* (null character included)    */
156 #define ASN1_MAX_ERROR_DESCRIPTION_SIZE 128
157
158   /***********************************/
159   /*  Functions definitions          */
160   /***********************************/
161
162   extern ASN1_API asn1_retCode
163     asn1_parser2tree (const char *file_name,
164                       ASN1_TYPE * definitions, char *errorDescription);
165
166   extern ASN1_API asn1_retCode
167     asn1_parser2array (const char *inputFileName,
168                        const char *outputFileName,
169                        const char *vectorName, char *errorDescription);
170
171   extern ASN1_API asn1_retCode
172     asn1_array2tree (const ASN1_ARRAY_TYPE * array,
173                      ASN1_TYPE * definitions, char *errorDescription);
174
175   extern ASN1_API void
176     asn1_print_structure (FILE * out, ASN1_TYPE structure,
177                           const char *name, int mode);
178
179   extern ASN1_API asn1_retCode
180     asn1_create_element (ASN1_TYPE definitions,
181                          const char *source_name, ASN1_TYPE * element);
182
183   extern ASN1_API asn1_retCode asn1_delete_structure (ASN1_TYPE * structure);
184
185   extern ASN1_API asn1_retCode
186     asn1_delete_element (ASN1_TYPE structure, const char *element_name);
187
188   extern ASN1_API asn1_retCode
189     asn1_write_value (ASN1_TYPE node_root, const char *name,
190                       const void *ivalue, int len);
191
192   extern ASN1_API asn1_retCode
193     asn1_read_value (ASN1_TYPE root, const char *name,
194                      void *ivalue, int *len);
195
196   extern ASN1_API asn1_retCode
197     asn1_number_of_elements (ASN1_TYPE element, const char *name, int *num);
198
199   extern ASN1_API asn1_retCode
200     asn1_der_coding (ASN1_TYPE element, const char *name,
201                      void *ider, int *len, char *ErrorDescription);
202
203   extern ASN1_API asn1_retCode
204     asn1_der_decoding (ASN1_TYPE * element, const void *ider,
205                        int len, char *errorDescription);
206
207   extern ASN1_API asn1_retCode
208     asn1_der_decoding_element (ASN1_TYPE * structure,
209                                const char *elementName,
210                                const void *ider, int len,
211                                char *errorDescription);
212
213   extern ASN1_API asn1_retCode
214     asn1_der_decoding_startEnd (ASN1_TYPE element,
215                                 const void *ider, int len,
216                                 const char *name_element,
217                                 int *start, int *end);
218
219   extern ASN1_API asn1_retCode
220     asn1_expand_any_defined_by (ASN1_TYPE definitions, ASN1_TYPE * element);
221
222   extern ASN1_API asn1_retCode
223     asn1_expand_octet_string (ASN1_TYPE definitions,
224                               ASN1_TYPE * element,
225                               const char *octetName, const char *objectName);
226
227   extern ASN1_API asn1_retCode
228     asn1_read_tag (ASN1_TYPE root, const char *name,
229                    int *tagValue, int *classValue);
230
231   extern ASN1_API const char *asn1_find_structure_from_oid (ASN1_TYPE
232                                                             definitions,
233                                                             const char
234                                                             *oidValue);
235
236   extern ASN1_API const char *asn1_check_version (const char *req_version);
237
238   extern ASN1_API const char *asn1_strerror (asn1_retCode error);
239
240   extern ASN1_API void asn1_perror (asn1_retCode error);
241
242   /* DER utility functions. */
243
244   extern ASN1_API int
245     asn1_get_tag_der (const unsigned char *der, int der_len,
246                       unsigned char *cls, int *len, unsigned long *tag);
247
248   extern ASN1_API void
249     asn1_octet_der (const unsigned char *str, int str_len,
250                     unsigned char *der, int *der_len);
251
252   extern ASN1_API asn1_retCode
253     asn1_get_octet_der (const unsigned char *der, int der_len,
254                         int *ret_len, unsigned char *str,
255                         int str_size, int *str_len);
256
257   extern ASN1_API void asn1_bit_der (const unsigned char *str, int bit_len,
258                                      unsigned char *der, int *der_len);
259
260   extern ASN1_API asn1_retCode
261     asn1_get_bit_der (const unsigned char *der, int der_len,
262                       int *ret_len, unsigned char *str,
263                       int str_size, int *bit_len);
264
265   extern ASN1_API signed long
266     asn1_get_length_der (const unsigned char *der, int der_len, int *len);
267
268   extern ASN1_API signed long
269     asn1_get_length_ber (const unsigned char *ber, int ber_len, int *len);
270
271   extern ASN1_API void
272     asn1_length_der (unsigned long int len, unsigned char *ans, int *ans_len);
273
274   /* Other utility functions. */
275
276   extern ASN1_API ASN1_TYPE
277     asn1_find_node (ASN1_TYPE pointer, const char *name);
278
279   extern ASN1_API asn1_retCode
280     asn1_copy_node (ASN1_TYPE dst, const char *dst_name,
281                     ASN1_TYPE src, const char *src_name);
282
283   /* Deprecated stuff. */
284
285 #ifndef ASN1_DISABLE_DEPRECATED
286
287 #define LIBTASN1_VERSION ASN1_VERSION
288
289 #ifndef MAX_NAME_SIZE
290 # define MAX_NAME_SIZE ASN1_MAX_NAME_SIZE
291 #endif
292
293 #ifndef MAX_ERROR_DESCRIPTION_SIZE
294 # define MAX_ERROR_DESCRIPTION_SIZE ASN1_MAX_ERROR_DESCRIPTION_SIZE
295 #endif
296
297 #ifndef __attribute__
298   /* This feature is available in gcc versions 2.5 and later.  */
299 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
300 #  define __attribute__(Spec)   /* empty */
301 # endif
302 #endif
303
304   /* Use asn1_strerror instead. */
305   extern ASN1_API const char *libtasn1_strerror (asn1_retCode error)
306     __attribute__ ((deprecated));
307
308   /* Use asn1_perror instead. */
309   extern ASN1_API void
310     libtasn1_perror (asn1_retCode error) __attribute__ ((deprecated));
311
312 #endif
313
314 #ifdef __cplusplus
315 }
316 #endif
317
318 #endif                          /* LIBTASN1_H */