This commit was generated by cvs2svn to track changes on a CVS vendor
[openssl.git] / crypto / asn1 / asn1.h
1 /* crypto/asn1/asn1.h */
2 /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3  * All rights reserved.
4  *
5  * This package is an SSL implementation written
6  * by Eric Young (eay@cryptsoft.com).
7  * The implementation was written so as to conform with Netscapes SSL.
8  * 
9  * This library is free for commercial and non-commercial use as long as
10  * the following conditions are aheared to.  The following conditions
11  * apply to all code found in this distribution, be it the RC4, RSA,
12  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13  * included with this distribution is covered by the same copyright terms
14  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15  * 
16  * Copyright remains Eric Young's, and as such any Copyright notices in
17  * the code are not to be removed.
18  * If this package is used in a product, Eric Young should be given attribution
19  * as the author of the parts of the library used.
20  * This can be in the form of a textual message at program startup or
21  * in documentation (online or textual) provided with the package.
22  * 
23  * Redistribution and use in source and binary forms, with or without
24  * modification, are permitted provided that the following conditions
25  * are met:
26  * 1. Redistributions of source code must retain the copyright
27  *    notice, this list of conditions and the following disclaimer.
28  * 2. Redistributions in binary form must reproduce the above copyright
29  *    notice, this list of conditions and the following disclaimer in the
30  *    documentation and/or other materials provided with the distribution.
31  * 3. All advertising materials mentioning features or use of this software
32  *    must display the following acknowledgement:
33  *    "This product includes cryptographic software written by
34  *     Eric Young (eay@cryptsoft.com)"
35  *    The word 'cryptographic' can be left out if the rouines from the library
36  *    being used are not cryptographic related :-).
37  * 4. If you include any Windows specific code (or a derivative thereof) from 
38  *    the apps directory (application code) you must include an acknowledgement:
39  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40  * 
41  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  * 
53  * The licence and distribution terms for any publically available version or
54  * derivative of this code cannot be changed.  i.e. this code cannot simply be
55  * copied and put under another distribution licence
56  * [including the GNU Public Licence.]
57  */
58
59 #ifndef HEADER_ASN1_H
60 #define HEADER_ASN1_H
61
62 #ifdef  __cplusplus
63 extern "C" {
64 #endif
65
66 #include <time.h>
67 #include "bn.h"
68 #include "stack.h"
69
70 #define V_ASN1_UNIVERSAL                0x00
71 #define V_ASN1_APPLICATION              0x40
72 #define V_ASN1_CONTEXT_SPECIFIC         0x80
73 #define V_ASN1_PRIVATE                  0xc0
74
75 #define V_ASN1_CONSTRUCTED              0x20
76 #define V_ASN1_PRIMATIVE_TAG            0x1f
77
78 #define V_ASN1_APP_CHOOSE               -2      /* let the recipent choose */
79
80 #define V_ASN1_UNDEF                    -1
81 #define V_ASN1_EOC                      0
82 #define V_ASN1_BOOLEAN                  1       /**/
83 #define V_ASN1_INTEGER                  2
84 #define V_ASN1_NEG_INTEGER              (2+0x100)
85 #define V_ASN1_BIT_STRING               3
86 #define V_ASN1_OCTET_STRING             4
87 #define V_ASN1_NULL                     5
88 #define V_ASN1_OBJECT                   6
89 #define V_ASN1_REAL                     9
90 #define V_ASN1_ENUMERATED               10      /* microsoft weirdness */
91 #define V_ASN1_SEQUENCE                 16
92 #define V_ASN1_SET                      17
93 #define V_ASN1_NUMERICSTRING            18      /**/
94 #define V_ASN1_PRINTABLESTRING          19
95 #define V_ASN1_T61STRING                20
96 #define V_ASN1_TELETEXSTRING            20      /* alias */
97 #define V_ASN1_VIDEOTEXSTRING           21      /**/
98 #define V_ASN1_IA5STRING                22
99 #define V_ASN1_UTCTIME                  23
100 #define V_ASN1_GENERALIZEDTIME          24      /**/
101 #define V_ASN1_GRAPHICSTRING            25      /**/
102 #define V_ASN1_ISO64STRING              26      /**/
103 #define V_ASN1_VISIBLESTRING            26      /* alias */
104 #define V_ASN1_GENERALSTRING            27      /**/
105 #define V_ASN1_UNIVERSALSTRING          28      /**/
106
107 /* For use with d2i_ASN1_type_bytes() */
108 #define B_ASN1_NUMERICSTRING    0x0001
109 #define B_ASN1_PRINTABLESTRING  0x0002
110 #define B_ASN1_T61STRING        0x0004
111 #define B_ASN1_VIDEOTEXSTRING   0x0008
112 #define B_ASN1_IA5STRING        0x0010
113 #define B_ASN1_GRAPHICSTRING    0x0020
114 #define B_ASN1_ISO64STRING      0x0040
115 #define B_ASN1_GENERALSTRING    0x0080
116 #define B_ASN1_UNIVERSALSTRING  0x0100
117 #define B_ASN1_OCTET_STRING     0x0200
118 #define B_ASN1_UNKNOWN          0x1000
119
120 #ifndef DEBUG
121
122 #define ASN1_INTEGER            ASN1_STRING
123 #define ASN1_BIT_STRING         ASN1_STRING
124 #define ASN1_OCTET_STRING       ASN1_STRING
125 #define ASN1_PRINTABLESTRING    ASN1_STRING
126 #define ASN1_T61STRING          ASN1_STRING
127 #define ASN1_IA5STRING          ASN1_STRING
128 #define ASN1_UTCTIME            ASN1_STRING
129 #define ASN1_GENERALSTRING      ASN1_STRING
130 #define ASN1_UNIVERSALSTRING    ASN1_STRING
131
132 #else
133
134 typedef struct asn1_integer_st
135         {
136         int length;
137         int type;
138         unsigned char *data;
139         } ASN1_INTEGER;
140
141 typedef struct asn1_bit_string_st
142         {
143         int length;
144         int type;
145         unsigned char *data;
146         } ASN1_BIT_STRING;
147
148 typedef struct asn1_octet_string_st
149         {
150         int length;
151         int type;
152         unsigned char *data;
153         } ASN1_OCTET_STRING;
154
155 typedef struct asn1_printablestring_st
156         {
157         int length;
158         int type;
159         unsigned char *data;
160         } ASN1_PRINTABLESTRING;
161
162 typedef struct asn1_t61string_st
163         {
164         int length;
165         int type;
166         unsigned char *data;
167         } ASN1_T61STRING;
168
169 typedef struct asn1_ia5string_st
170         {
171         int length;
172         int type;
173         unsigned char *data;
174         } ASN1_IA5STRING;
175
176 typedef struct asn1_generalstring_st
177         {
178         int length;
179         int type;
180         unsigned char *data;
181         } ASN1_GENERALSTRING;
182
183 typedef struct asn1_universalstring_st
184         {
185         int length;
186         int type;
187         unsigned char *data;
188         } ASN1_UNIVERSALSTRING;
189
190 typedef struct asn1_utctime_st
191         {
192         int length;
193         int type;
194         unsigned char *data;
195         } ASN1_UTCTIME;
196
197 #endif
198
199 typedef struct asn1_ctx_st
200         {
201         unsigned char *p;/* work char pointer */
202         int eos;        /* end of sequence read for indefinite encoding */
203         int error;      /* error code to use when returning an error */
204         int inf;        /* constructed if 0x20, indefinite is 0x21 */
205         int tag;        /* tag from last 'get object' */
206         int xclass;     /* class from last 'get object' */
207         long slen;      /* length of last 'get object' */
208         unsigned char *max; /* largest value of p alowed */
209         unsigned char *q;/* temporary variable */
210         unsigned char **pp;/* variable */
211         } ASN1_CTX;
212
213 /* These are used internally in the ASN1_OBJECT to keep track of
214  * whether the names and data need to be free()ed */
215 #define ASN1_OBJECT_FLAG_DYNAMIC         0x01   /* internal use */
216 #define ASN1_OBJECT_FLAG_CRITICAL        0x02   /* critical x509v3 object id */
217 #define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04   /* internal use */
218 #define ASN1_OBJECT_FLAG_DYNAMIC_DATA    0x08   /* internal use */
219 typedef struct asn1_object_st
220         {
221         char *sn,*ln;
222         int nid;
223         int length;
224         unsigned char *data;
225         int flags;      /* Should we free this one */
226         } ASN1_OBJECT;
227
228 /* This is the base type that holds just about everything :-) */
229 typedef struct asn1_string_st
230         {
231         int length;
232         int type;
233         unsigned char *data;
234         } ASN1_STRING;
235
236 typedef struct asn1_type_st
237         {
238         int type;
239         union   {
240                 char *ptr;
241                 ASN1_STRING *           asn1_string;
242                 ASN1_OBJECT *           object;
243                 ASN1_INTEGER *          integer;
244                 ASN1_BIT_STRING *       bit_string;
245                 ASN1_OCTET_STRING *     octet_string;
246                 ASN1_PRINTABLESTRING *  printablestring;
247                 ASN1_T61STRING *        t61string;
248                 ASN1_IA5STRING *        ia5string;
249                 ASN1_GENERALSTRING *    generalstring;
250                 ASN1_UNIVERSALSTRING *  universalstring;
251                 ASN1_UTCTIME *          utctime;
252                 /* set and sequence are left complete and still
253                  * contain the set or sequence bytes */
254                 ASN1_STRING *           set;
255                 ASN1_STRING *           sequence;
256                 } value;
257         } ASN1_TYPE;
258
259 typedef struct asn1_method_st
260         {
261         int (*i2d)();
262         char *(*d2i)();
263         char *(*create)();
264         void (*destroy)();
265         } ASN1_METHOD;
266
267 /* This is used when parsing some Netscape objects */
268 typedef struct asn1_header_st
269         {
270         ASN1_OCTET_STRING *header;
271         char *data;
272         ASN1_METHOD *meth;
273         } ASN1_HEADER;
274
275 #define ASN1_STRING_type(x)     ((x)->type)
276 #define ASN1_STRING_data(x)     ((x)->data)
277
278 /* Macros for string operations */
279 #define ASN1_BIT_STRING_new()   (ASN1_BIT_STRING *)\
280                 ASN1_STRING_type_new(V_ASN1_BIT_STRING)
281 #define ASN1_BIT_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
282 #define ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\
283                 ASN1_STRING_dup((ASN1_STRING *)a)
284 #define ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\
285                 (ASN1_STRING *)a,(ASN1_STRING *)b)
286 #define ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
287 /* i2d_ASN1_BIT_STRING() is a function */
288 /* d2i_ASN1_BIT_STRING() is a function */
289
290 #define ASN1_INTEGER_new()      (ASN1_INTEGER *)\
291                 ASN1_STRING_type_new(V_ASN1_INTEGER)
292 #define ASN1_INTEGER_free(a)            ASN1_STRING_free((ASN1_STRING *)a)
293 #define ASN1_INTEGER_dup(a) (ASN1_INTEGER *)ASN1_STRING_dup((ASN1_STRING *)a)
294 #define ASN1_INTEGER_cmp(a,b)   ASN1_STRING_cmp(\
295                 (ASN1_STRING *)a,(ASN1_STRING *)b)
296 /* ASN1_INTEGER_set() is a function, also see BN_to_ASN1_INTEGER() */
297 /* ASN1_INTEGER_get() is a function, also see ASN1_INTEGER_to_BN() */
298 /* i2d_ASN1_INTEGER() is a function */
299 /* d2i_ASN1_INTEGER() is a function */
300
301 #define ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\
302                 ASN1_STRING_type_new(V_ASN1_OCTET_STRING)
303 #define ASN1_OCTET_STRING_free(a)       ASN1_STRING_free((ASN1_STRING *)a)
304 #define ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\
305                 ASN1_STRING_dup((ASN1_STRING *)a)
306 #define ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\
307                 (ASN1_STRING *)a,(ASN1_STRING *)b)
308 #define ASN1_OCTET_STRING_set(a,b,c)    ASN1_STRING_set((ASN1_STRING *)a,b,c)
309 #define ASN1_OCTET_STRING_print(a,b)    ASN1_STRING_print(a,(ASN1_STRING *)b)
310 #define M_i2d_ASN1_OCTET_STRING(a,pp) \
311                 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\
312                 V_ASN1_OCTET_STRING)
313 /* d2i_ASN1_OCTET_STRING() is a function */
314
315 #define ASN1_PRINTABLE_new()    ASN1_STRING_type_new(V_ASN1_T61STRING)
316 #define ASN1_PRINTABLE_free(a)  ASN1_STRING_free((ASN1_STRING *)a)
317 #define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
318                 pp,a->type,V_ASN1_UNIVERSAL)
319 #define M_d2i_ASN1_PRINTABLE(a,pp,l) \
320                 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
321                         B_ASN1_PRINTABLESTRING| \
322                         B_ASN1_T61STRING| \
323                         B_ASN1_IA5STRING| \
324                         B_ASN1_UNIVERSALSTRING|\
325                         B_ASN1_UNKNOWN)
326
327 #define ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING_STRING *)\
328                 ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
329 #define ASN1_PRINTABLESTRING_free(a)    ASN1_STRING_free((ASN1_STRING *)a)
330 #define M_i2d_ASN1_PRINTABLESTRING(a,pp) \
331                 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\
332                 V_ASN1_UNIVERSAL)
333 #define M_d2i_ASN1_PRINTABLESTRING(a,pp,l) \
334                 (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\
335                 ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING)
336
337 #define ASN1_T61STRING_new()    (ASN1_T61STRING_STRING *)\
338                 ASN1_STRING_type_new(V_ASN1_T61STRING)
339 #define ASN1_T61STRING_free(a)  ASN1_STRING_free((ASN1_STRING *)a)
340 #define M_i2d_ASN1_T61STRING(a,pp) \
341                 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\
342                 V_ASN1_UNIVERSAL)
343 #define M_d2i_ASN1_T61STRING(a,pp,l) \
344                 (ASN1_T61STRING *)d2i_ASN1_type_bytes\
345                 ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING)
346
347 #define ASN1_IA5STRING_new()    (ASN1_IA5STRING *)\
348                 ASN1_STRING_type_new(V_ASN1_IA5STRING)
349 #define ASN1_IA5STRING_free(a)  ASN1_STRING_free((ASN1_STRING *)a)
350 #define M_i2d_ASN1_IA5STRING(a,pp) \
351                 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\
352                         V_ASN1_UNIVERSAL)
353 #define M_d2i_ASN1_IA5STRING(a,pp,l) \
354                 (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\
355                         B_ASN1_IA5STRING)
356
357 #define ASN1_UTCTIME_new()      (ASN1_UTCTIME *)\
358                 ASN1_STRING_type_new(V_ASN1_UTCTIME)
359 #define ASN1_UTCTIME_free(a)    ASN1_STRING_free((ASN1_STRING *)a)
360 #define ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup((ASN1_STRING *)a)
361 /* i2d_ASN1_UTCTIME() is a function */
362 /* d2i_ASN1_UTCTIME() is a function */
363 /* ASN1_UTCTIME_set() is a function */
364 /* ASN1_UTCTIME_check() is a function */
365 /* ASN1_UTCTIME_set() is a function */
366
367 #define ASN1_GENERALSTRING_new()        (ASN1_GENERALSTRING *)\
368                 ASN1_STRING_type_new(V_ASN1_GENERALSTRING)
369 #define ASN1_GENERALSTRING_free(a)      ASN1_STRING_free((ASN1_STRING *)a)
370 #define M_i2d_ASN1_GENERALSTRING(a,pp) \
371                 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\
372                         V_ASN1_UNIVERSAL)
373 #define M_d2i_ASN1_GENERALSTRING(a,pp,l) \
374                 (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\
375                 ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING)
376
377 #define ASN1_UNIVERSALSTRING_new()      (ASN1_UNIVERSALSTRING *)\
378                 ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING)
379 #define ASN1_UNIVERSALSTRING_free(a)    ASN1_STRING_free((ASN1_STRING *)a)
380 #define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \
381                 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\
382                         V_ASN1_UNIVERSAL)
383 #define M_d2i_ASN1_UNIVERSALSTRING(a,pp,l) \
384                 (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\
385                 ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING)
386
387 #ifndef NOPROTO
388 ASN1_TYPE *     ASN1_TYPE_new(void );
389 void            ASN1_TYPE_free(ASN1_TYPE *a);
390 int             i2d_ASN1_TYPE(ASN1_TYPE *a,unsigned char **pp);
391 ASN1_TYPE *     d2i_ASN1_TYPE(ASN1_TYPE **a,unsigned char **pp,long length);
392 int ASN1_TYPE_get(ASN1_TYPE *a);
393 void ASN1_TYPE_set(ASN1_TYPE *a, int type, char *value);
394
395 ASN1_OBJECT *   ASN1_OBJECT_new(void );
396 void            ASN1_OBJECT_free(ASN1_OBJECT *a);
397 int             i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp);
398 ASN1_OBJECT *   d2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
399                         long length);
400
401 ASN1_STRING *   ASN1_STRING_new(void );
402 void            ASN1_STRING_free(ASN1_STRING *a);
403 ASN1_STRING *   ASN1_STRING_dup(ASN1_STRING *a);
404 ASN1_STRING *   ASN1_STRING_type_new(int type );
405 int             ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b);
406 int             ASN1_STRING_set(ASN1_STRING *str,unsigned char *data, int len);
407
408 int             i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp);
409 ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp,
410                         long length);
411
412 int             i2d_ASN1_BOOLEAN(int a,unsigned char **pp);
413 int             d2i_ASN1_BOOLEAN(int *a,unsigned char **pp,long length);
414
415 int             i2d_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
416 ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,
417                         long length);
418
419 int ASN1_UTCTIME_check(ASN1_UTCTIME *a);
420 ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t);
421
422 int             i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a,unsigned char **pp);
423 ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a,
424                         unsigned char **pp,long length);
425
426 int i2d_ASN1_PRINTABLE(ASN1_STRING *a,unsigned char **pp);
427 ASN1_STRING *d2i_ASN1_PRINTABLE(ASN1_STRING **a,
428         unsigned char **pp, long l);
429 ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a,
430         unsigned char **pp, long l);
431
432 ASN1_T61STRING *d2i_ASN1_T61STRING(ASN1_T61STRING **a,
433         unsigned char **pp, long l);
434 int i2d_ASN1_IA5STRING(ASN1_IA5STRING *a,unsigned char **pp);
435 ASN1_IA5STRING *d2i_ASN1_IA5STRING(ASN1_IA5STRING **a,
436         unsigned char **pp, long l);
437
438 int             i2d_ASN1_UTCTIME(ASN1_UTCTIME *a,unsigned char **pp);
439 ASN1_UTCTIME *  d2i_ASN1_UTCTIME(ASN1_UTCTIME **a,unsigned char **pp,
440                         long length);
441
442 int             i2d_ASN1_SET(STACK *a, unsigned char **pp,
443                         int (*func)(), int ex_tag, int ex_class);
444 STACK *         d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
445                         char *(*func)(), int ex_tag, int ex_class);
446
447 #ifdef HEADER_BIO_H
448 int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
449 int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size);
450 int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a);
451 int a2i_ASN1_STRING(BIO *bp,ASN1_STRING *bs,char *buf,int size);
452 int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type);
453 #endif
454
455 int a2d_ASN1_OBJECT(unsigned char *out,int olen, char *buf, int num);
456 ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len,
457         char *sn, char *ln);
458
459 int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
460 long ASN1_INTEGER_get(ASN1_INTEGER *a);
461 ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai);
462 BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn);
463
464 /* General */
465 /* given a string, return the correct type, max is the maximum length */
466 int ASN1_PRINTABLE_type(unsigned char *s, int max);
467
468 int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass);
469 ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp,
470         long length, int Ptag, int Pclass);
471 /* type is one or more of the B_ASN1_ values. */
472 ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a,unsigned char **pp,
473                 long length,int type);
474
475 /* PARSING */
476 int asn1_Finish(ASN1_CTX *c);
477
478 /* SPECIALS */
479 int ASN1_get_object(unsigned char **pp, long *plength, int *ptag,
480         int *pclass, long omax);
481 int ASN1_check_infinite_end(unsigned char **p,long len);
482 void ASN1_put_object(unsigned char **pp, int constructed, int length,
483         int tag, int xclass);
484 int ASN1_object_size(int constructed, int length, int tag);
485
486 /* Used to implement other functions */
487 char *ASN1_dup(int (*i2d)(),char *(*d2i)(),char *x);
488
489 #ifndef WIN16
490 char *ASN1_d2i_fp(char *(*xnew)(),char *(*d2i)(),FILE *fp,unsigned char **x);
491 int ASN1_i2d_fp(int (*i2d)(),FILE *out,unsigned char *x);
492 #endif
493
494 #ifdef HEADER_BIO_H
495 char *ASN1_d2i_bio(char *(*xnew)(),char *(*d2i)(),BIO *bp,unsigned char **x);
496 int ASN1_i2d_bio(int (*i2d)(),BIO *out,unsigned char *x);
497 int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a);
498 int ASN1_STRING_print(BIO *bp,ASN1_STRING *v);
499 int ASN1_parse(BIO *bp,unsigned char *pp,long len,int indent);
500 #endif
501
502 /* Used to load and write netscape format cert/key */
503 int i2d_ASN1_HEADER(ASN1_HEADER *a,unsigned char **pp);
504 ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a,unsigned char **pp, long length);
505 ASN1_HEADER *ASN1_HEADER_new(void );
506 void ASN1_HEADER_free(ASN1_HEADER *a);
507
508 int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s);
509
510 void ERR_load_ASN1_strings(void);
511
512 /* Not used that much at this point, except for the first two */
513 ASN1_METHOD *X509_asn1_meth(void);
514 ASN1_METHOD *RSAPrivateKey_asn1_meth(void);
515 ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void);
516 ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void);
517
518 #else
519
520 ASN1_TYPE *     ASN1_TYPE_new();
521 void            ASN1_TYPE_free();
522 int             i2d_ASN1_TYPE();
523 ASN1_TYPE *     d2i_ASN1_TYPE();
524 int ASN1_TYPE_get();
525 void ASN1_TYPE_set();
526
527 ASN1_OBJECT *   ASN1_OBJECT_new();
528 void            ASN1_OBJECT_free();
529 int             i2d_ASN1_OBJECT();
530 ASN1_OBJECT *   d2i_ASN1_OBJECT();
531 ASN1_STRING *   ASN1_STRING_new();
532 void            ASN1_STRING_free();
533 ASN1_STRING *   ASN1_STRING_dup();
534 ASN1_STRING *   ASN1_STRING_type_new();
535 int             ASN1_STRING_cmp();
536 int             ASN1_STRING_set();
537 int             i2d_ASN1_BIT_STRING();
538 ASN1_BIT_STRING *d2i_ASN1_BIT_STRING();
539 int             i2d_ASN1_BOOLEAN();
540 int             d2i_ASN1_BOOLEAN();
541 int             i2d_ASN1_INTEGER();
542 ASN1_INTEGER *d2i_ASN1_INTEGER();
543 int ASN1_UTCTIME_check();
544 ASN1_UTCTIME *ASN1_UTCTIME_set();
545 int             i2d_ASN1_OCTET_STRING();
546 ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING();
547 int i2d_ASN1_PRINTABLE();
548 ASN1_STRING *d2i_ASN1_PRINTABLE();
549 ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING();
550 ASN1_T61STRING *d2i_ASN1_T61STRING();
551 int i2d_ASN1_IA5STRING();
552 ASN1_IA5STRING *d2i_ASN1_IA5STRING();
553 int             i2d_ASN1_UTCTIME();
554 ASN1_UTCTIME *  d2i_ASN1_UTCTIME();
555 int             i2d_ASN1_SET();
556 STACK *         d2i_ASN1_SET();
557 int a2d_ASN1_OBJECT();
558 ASN1_OBJECT *ASN1_OBJECT_create();
559 int ASN1_INTEGER_set();
560 long ASN1_INTEGER_get();
561 ASN1_INTEGER *BN_to_ASN1_INTEGER();
562 BIGNUM *ASN1_INTEGER_to_BN();
563 int ASN1_PRINTABLE_type();
564 int i2d_ASN1_bytes();
565 ASN1_STRING *d2i_ASN1_bytes();
566 ASN1_STRING *d2i_ASN1_type_bytes();
567 int asn1_Finish();
568 int ASN1_get_object();
569 int ASN1_check_infinite_end();
570 void ASN1_put_object();
571 int ASN1_object_size();
572 char *ASN1_dup();
573 #ifndef WIN16
574 char *ASN1_d2i_fp();
575 int ASN1_i2d_fp();
576 #endif
577
578 char *ASN1_d2i_bio();
579 int ASN1_i2d_bio();
580 int ASN1_UTCTIME_print();
581 int ASN1_STRING_print();
582 int ASN1_parse();
583 int i2a_ASN1_INTEGER();
584 int a2i_ASN1_INTEGER();
585 int i2a_ASN1_OBJECT();
586 int a2i_ASN1_STRING();
587 int i2a_ASN1_STRING();
588
589 int i2d_ASN1_HEADER();
590 ASN1_HEADER *d2i_ASN1_HEADER();
591 ASN1_HEADER *ASN1_HEADER_new();
592 void ASN1_HEADER_free();
593 void ERR_load_ASN1_strings();
594 ASN1_METHOD *X509_asn1_meth();
595 ASN1_METHOD *RSAPrivateKey_asn1_meth();
596 ASN1_METHOD *ASN1_IA5STRING_asn1_meth();
597 ASN1_METHOD *ASN1_BIT_STRING_asn1_meth();
598
599 int ASN1_UNIVERSALSTRING_to_string();
600 #endif
601
602 /* BEGIN ERROR CODES */
603 /* Error codes for the ASN1 functions. */
604
605 /* Function codes. */
606 #define ASN1_F_A2D_ASN1_OBJECT                           100
607 #define ASN1_F_A2I_ASN1_INTEGER                          101
608 #define ASN1_F_A2I_ASN1_STRING                           102
609 #define ASN1_F_ASN1_COLLATE_PRIMATIVE                    103
610 #define ASN1_F_ASN1_D2I_BIO                              104
611 #define ASN1_F_ASN1_D2I_FP                               105
612 #define ASN1_F_ASN1_DUP                                  106
613 #define ASN1_F_ASN1_GET_OBJECT                           107
614 #define ASN1_F_ASN1_HEADER_NEW                           108
615 #define ASN1_F_ASN1_I2D_BIO                              109
616 #define ASN1_F_ASN1_I2D_FP                               110
617 #define ASN1_F_ASN1_INTEGER_SET                          111
618 #define ASN1_F_ASN1_INTEGER_TO_BN                        112
619 #define ASN1_F_ASN1_OBJECT_NEW                           113
620 #define ASN1_F_ASN1_SIGN                                 114
621 #define ASN1_F_ASN1_STRING_NEW                           115
622 #define ASN1_F_ASN1_STRING_TYPE_NEW                      116
623 #define ASN1_F_ASN1_TYPE_NEW                             117
624 #define ASN1_F_ASN1_UTCTIME_NEW                          118
625 #define ASN1_F_ASN1_VERIFY                               119
626 #define ASN1_F_BN_TO_ASN1_INTEGER                        120
627 #define ASN1_F_D2I_ASN1_BIT_STRING                       121
628 #define ASN1_F_D2I_ASN1_BOOLEAN                          122
629 #define ASN1_F_D2I_ASN1_BYTES                            123
630 #define ASN1_F_D2I_ASN1_HEADER                           124
631 #define ASN1_F_D2I_ASN1_INTEGER                          125
632 #define ASN1_F_D2I_ASN1_OBJECT                           126
633 #define ASN1_F_D2I_ASN1_OCTET_STRING                     127
634 #define ASN1_F_D2I_ASN1_PRINT_TYPE                       128
635 #define ASN1_F_D2I_ASN1_SET                              129
636 #define ASN1_F_D2I_ASN1_TYPE                             130
637 #define ASN1_F_D2I_ASN1_TYPE_BYTES                       131
638 #define ASN1_F_D2I_ASN1_UTCTIME                          132
639 #define ASN1_F_D2I_DHPARAMS                              133
640 #define ASN1_F_D2I_DSAPARAMS                             134
641 #define ASN1_F_D2I_DSAPRIVATEKEY                         135
642 #define ASN1_F_D2I_DSAPUBLICKEY                          136
643 #define ASN1_F_D2I_NETSCAPE_PKEY                         137
644 #define ASN1_F_D2I_NETSCAPE_RSA                          138
645 #define ASN1_F_D2I_NETSCAPE_RSA_2                        139
646 #define ASN1_F_D2I_NETSCAPE_SPKAC                        140
647 #define ASN1_F_D2I_NETSCAPE_SPKI                         141
648 #define ASN1_F_D2I_PKCS7                                 142
649 #define ASN1_F_D2I_PKCS7_DIGEST                          143
650 #define ASN1_F_D2I_PKCS7_ENCRYPT                         144
651 #define ASN1_F_D2I_PKCS7_ENC_CONTENT                     145
652 #define ASN1_F_D2I_PKCS7_ENVELOPE                        146
653 #define ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL               147
654 #define ASN1_F_D2I_PKCS7_RECIP_INFO                      148
655 #define ASN1_F_D2I_PKCS7_SIGNED                          149
656 #define ASN1_F_D2I_PKCS7_SIGNER_INFO                     150
657 #define ASN1_F_D2I_PKCS7_SIGN_ENVELOPE                   151
658 #define ASN1_F_D2I_PRIVATEKEY                            152
659 #define ASN1_F_D2I_PUBLICKEY                             153
660 #define ASN1_F_D2I_RSAPRIVATEKEY                         154
661 #define ASN1_F_D2I_RSAPUBLICKEY                          155
662 #define ASN1_F_D2I_X509                                  156
663 #define ASN1_F_D2I_X509_ALGOR                            157
664 #define ASN1_F_D2I_X509_ATTRIBUTE                        158
665 #define ASN1_F_D2I_X509_CINF                             159
666 #define ASN1_F_D2I_X509_CRL                              160
667 #define ASN1_F_D2I_X509_CRL_INFO                         161
668 #define ASN1_F_D2I_X509_EXTENSION                        162
669 #define ASN1_F_D2I_X509_KEY                              163
670 #define ASN1_F_D2I_X509_NAME                             164
671 #define ASN1_F_D2I_X509_NAME_ENTRY                       165
672 #define ASN1_F_D2I_X509_PKEY                             166
673 #define ASN1_F_D2I_X509_PUBKEY                           167
674 #define ASN1_F_D2I_X509_REQ                              168
675 #define ASN1_F_D2I_X509_REQ_INFO                         169
676 #define ASN1_F_D2I_X509_REVOKED                          170
677 #define ASN1_F_D2I_X509_SIG                              171
678 #define ASN1_F_D2I_X509_VAL                              172
679 #define ASN1_F_I2A_ASN1_OBJECT                           173
680 #define ASN1_F_I2D_ASN1_HEADER                           174
681 #define ASN1_F_I2D_DHPARAMS                              175
682 #define ASN1_F_I2D_DSAPARAMS                             176
683 #define ASN1_F_I2D_DSAPRIVATEKEY                         177
684 #define ASN1_F_I2D_DSAPUBLICKEY                          178
685 #define ASN1_F_I2D_NETSCAPE_RSA                          179
686 #define ASN1_F_I2D_PKCS7                                 180
687 #define ASN1_F_I2D_PRIVATEKEY                            181
688 #define ASN1_F_I2D_PUBLICKEY                             182
689 #define ASN1_F_I2D_RSAPRIVATEKEY                         183
690 #define ASN1_F_I2D_RSAPUBLICKEY                          184
691 #define ASN1_F_I2D_X509_ATTRIBUTE                        185
692 #define ASN1_F_NETSCAPE_PKEY_NEW                         186
693 #define ASN1_F_NETSCAPE_SPKAC_NEW                        187
694 #define ASN1_F_NETSCAPE_SPKI_NEW                         188
695 #define ASN1_F_PKCS7_DIGEST_NEW                          189
696 #define ASN1_F_PKCS7_ENCRYPT_NEW                         190
697 #define ASN1_F_PKCS7_ENC_CONTENT_NEW                     191
698 #define ASN1_F_PKCS7_ENVELOPE_NEW                        192
699 #define ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW               193
700 #define ASN1_F_PKCS7_NEW                                 194
701 #define ASN1_F_PKCS7_RECIP_INFO_NEW                      195
702 #define ASN1_F_PKCS7_SIGNED_NEW                          196
703 #define ASN1_F_PKCS7_SIGNER_INFO_NEW                     197
704 #define ASN1_F_PKCS7_SIGN_ENVELOPE_NEW                   198
705 #define ASN1_F_X509_ALGOR_NEW                            199
706 #define ASN1_F_X509_ATTRIBUTE_NEW                        200
707 #define ASN1_F_X509_CINF_NEW                             201
708 #define ASN1_F_X509_CRL_INFO_NEW                         202
709 #define ASN1_F_X509_CRL_NEW                              203
710 #define ASN1_F_X509_DHPARAMS_NEW                         204
711 #define ASN1_F_X509_EXTENSION_NEW                        205
712 #define ASN1_F_X509_INFO_NEW                             206
713 #define ASN1_F_X509_KEY_NEW                              207
714 #define ASN1_F_X509_NAME_ENTRY_NEW                       208
715 #define ASN1_F_X509_NAME_NEW                             209
716 #define ASN1_F_X509_NEW                                  210
717 #define ASN1_F_X509_PKEY_NEW                             211
718 #define ASN1_F_X509_PUBKEY_NEW                           212
719 #define ASN1_F_X509_REQ_INFO_NEW                         213
720 #define ASN1_F_X509_REQ_NEW                              214
721 #define ASN1_F_X509_REVOKED_NEW                          215
722 #define ASN1_F_X509_SIG_NEW                              216
723 #define ASN1_F_X509_VAL_FREE                             217
724 #define ASN1_F_X509_VAL_NEW                              218
725
726 /* Reason codes. */
727 #define ASN1_R_BAD_CLASS                                 100
728 #define ASN1_R_BAD_GET_OBJECT                            101
729 #define ASN1_R_BAD_OBJECT_HEADER                         102
730 #define ASN1_R_BAD_PASSWORD_READ                         103
731 #define ASN1_R_BAD_PKCS7_CONTENT                         104
732 #define ASN1_R_BAD_PKCS7_TYPE                            105
733 #define ASN1_R_BAD_TAG                                   106
734 #define ASN1_R_BAD_TYPE                                  107
735 #define ASN1_R_BN_LIB                                    108
736 #define ASN1_R_BOOLEAN_IS_WRONG_LENGTH                   109
737 #define ASN1_R_BUFFER_TOO_SMALL                          110
738 #define ASN1_R_DECODING_ERROR                            111
739 #define ASN1_R_ERROR_STACK                               112
740 #define ASN1_R_EXPECTING_AN_INTEGER                      113
741 #define ASN1_R_EXPECTING_AN_OBJECT                       114
742 #define ASN1_R_EXPECTING_AN_OCTET_STRING                 115
743 #define ASN1_R_EXPECTING_A_BIT_STRING                    116
744 #define ASN1_R_EXPECTING_A_BOOLEAN                       117
745 #define ASN1_R_EXPECTING_A_SEQUENCE                      118
746 #define ASN1_R_EXPECTING_A_UTCTIME                       119
747 #define ASN1_R_FIRST_NUM_TOO_LARGE                       120
748 #define ASN1_R_HEADER_TOO_LONG                           121
749 #define ASN1_R_INVALID_DIGIT                             122
750 #define ASN1_R_INVALID_SEPARATOR                         123
751 #define ASN1_R_INVALID_TIME_FORMAT                       124
752 #define ASN1_R_IV_TOO_LARGE                              125
753 #define ASN1_R_LENGTH_ERROR                              126
754 #define ASN1_R_LENGTH_MISMATCH                           127
755 #define ASN1_R_MISSING_EOS                               128
756 #define ASN1_R_MISSING_SECOND_NUMBER                     129
757 #define ASN1_R_NON_HEX_CHARACTERS                        130
758 #define ASN1_R_NOT_ENOUGH_DATA                           131
759 #define ASN1_R_ODD_NUMBER_OF_CHARS                       132
760 #define ASN1_R_PARSING                                   133
761 #define ASN1_R_PRIVATE_KEY_HEADER_MISSING                134
762 #define ASN1_R_SECOND_NUMBER_TOO_LARGE                   135
763 #define ASN1_R_SHORT_LINE                                136
764 #define ASN1_R_STRING_TOO_SHORT                          137
765 #define ASN1_R_TAG_VALUE_TOO_HIGH                        138
766 #define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 139
767 #define ASN1_R_TOO_LONG                                  140
768 #define ASN1_R_UNABLE_TO_DECODE_RSA_KEY                  141
769 #define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY          142
770 #define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE                    143
771 #define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM          144
772 #define ASN1_R_UNKNOWN_OBJECT_TYPE                       145
773 #define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE                   146
774 #define ASN1_R_UNSUPPORTED_CIPHER                        147
775 #define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM          148
776 #define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE               149
777 #define ASN1_R_UTCTIME_TOO_LONG                          150
778 #define ASN1_R_WRONG_PRINTABLE_TYPE                      151
779 #define ASN1_R_WRONG_TAG                                 152
780 #define ASN1_R_WRONG_TYPE                                153
781  
782 #ifdef  __cplusplus
783 }
784 #endif
785 #endif
786