libtommath: Fix possible integer overflow CVE-2023-36328
[heimdal.git] / lib / asn1 / gen_locl.h
blobf37f1490320b869ae87e5d293c76600416e580a2
1 /*
2 * Copyright (c) 1997-2005 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 /* $Id$ */
36 #ifndef __GEN_LOCL_H__
37 #define __GEN_LOCL_H__
39 #include <config.h>
41 #include <assert.h>
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
45 #include <limits.h>
46 #include <ctype.h>
47 #include <time.h>
48 #include <errno.h>
49 #include <err.h>
50 #include <roken.h>
51 #include <getarg.h>
52 #include "hash.h"
53 #include "symbol.h"
54 #include "asn1-common.h"
55 #include "der.h"
56 #include "der-private.h"
59 * XXX We need to move all module state out of globals and into a struct that
60 * we pass around when parsing and compiling a module, and also that we keep on
61 * a linked list of parsed modules.
63 * This is needed to:
65 * - implement IMPORTS correctly, because we need to know the type of a symbol
66 * in order to emit an extern declaration of it
67 * - implement value parsing
68 * - implement an ASN.1 library that does value parsing
70 * Value parsing, in particular, would be fantastic. We could then have
71 * options in hxtool(1) to load arbitrary ASN.1 modules and then parse SAN
72 * values given in ASN.1 value syntax on the command-line or in files. Eat
73 * your heart out OpenSSL if we do this!
75 * As well we'll need a `-I' option to the compiler so it knows where to find
76 * modules to IMPORT FROM.
78 typedef struct asn1_module {
79 /* Name of ASN.1 module file: */
80 const char *orig_filename;
81 /* Name of file to always include for common type definitions: */
82 const char *type_file_string;
83 /* Name of public header file for module: */
84 const char *header;
85 /* Name of private header file for module: */
86 const char *privheader;
87 /* Basename of module: */
88 const char *headerbase;
89 /* Open stdio file handles for output: */
90 FILE *jsonfile;
91 FILE *privheaderfile;
92 FILE *headerfile;
93 FILE *oidsfile;
94 FILE *codefile;
95 FILE *logfile;
96 FILE *templatefile;
97 /* Module contents: */
98 struct sexport *exports;
99 struct import *imports;
100 Hashtab *htab; /* symbols */
101 /* Template state: */
102 struct templatehead *template;
103 struct tlisthead *tlistmaster;
104 /* CLI options and flags needed everywhere: */
105 getarg_strings preserve;
106 getarg_strings seq;
107 const char *enum_prefix;
108 unsigned int one_code_file:1;
109 unsigned int support_ber:1;
110 unsigned int parse_units_flag:1;
111 unsigned int prefix_enum:1; /* Should be a getarg_strings of bitrsting types to do this for */
112 unsigned int rfc1510_bitstring:1; /* Should be a getarg_strings of bitrsting types to do this for */
113 } *asn1_module;
115 void generate_type (const Symbol *);
116 void generate_type_header_forwards(const Symbol *);
117 void generate_constant (const Symbol *);
118 void generate_type_encode (const Symbol *);
119 void generate_type_decode (const Symbol *);
120 void generate_type_free (const Symbol *);
121 void generate_type_length (const Symbol *);
122 void generate_type_print_stub(const Symbol *);
123 void generate_type_copy (const Symbol *);
124 void generate_type_seq (const Symbol *);
125 void generate_glue (const Type *, const char*);
127 const char *classname(Der_class);
128 const char *valuename(Der_class, int);
130 void gen_compare_defval(const char *, struct value *);
131 void gen_assign_defval(const char *, struct value *);
133 int objid_cmp(struct objid *, struct objid *);
135 void init_generate (const char *, const char *);
136 const char *get_filename (void);
137 void close_generate(void);
138 void add_import(const char *);
139 void add_export(const char *);
140 int is_export(const char *);
141 int yyparse(void);
142 int is_primitive_type(const Type *);
143 int is_tagged_type(const Type *);
145 int preserve_type(const char *);
146 int seq_type(const char *);
148 struct decoration {
149 char *field_type; /* C type name */
150 char *field_name; /* C struct field name */
151 char *copy_function_name; /* copy constructor function name */
152 char *free_function_name; /* destructor function name */
153 char *header_name; /* header name */
154 unsigned int decorated:1;
155 unsigned int first:1; /* optional */
156 unsigned int opt:1; /* optional */
157 unsigned int ext:1; /* external */
158 unsigned int ptr:1; /* external, pointer */
159 unsigned int void_star:1; /* external, void * */
160 unsigned int struct_star:1; /* external, struct foo * */
162 int decorate_type(const char *, struct decoration *, ssize_t *);
164 void generate_header_of_codefile(const char *);
165 void close_codefile(void);
167 void get_open_type_defn_fields(const Type *, Member **, Member **, Field **,
168 Field **, int *);
169 void sort_object_set(IOSObjectSet *, Field *, IOSObject ***, size_t *);
170 int object_cmp(const void *, const void *);
172 int is_template_compat (const Symbol *);
173 void generate_template(const Symbol *);
174 void generate_template_type_forward(const char *);
175 void generate_template_objectset_forwards(const Symbol *);
176 void gen_template_import(const Symbol *);
178 struct objid **objid2list(struct objid *);
180 extern FILE *jsonfile, *privheaderfile, *headerfile, *codefile, *logfile, *templatefile;
181 extern const char *fuzzer_string;
182 extern int support_ber;
183 extern int template_flag;
184 extern int rfc1510_bitstring;
185 extern int one_code_file;
186 extern int original_order;
187 extern int parse_units_flag;
188 extern char *type_file_string;
190 extern int error_flag;
192 #endif /* __GEN_LOCL_H__ */