xref: /freebsd/crypto/heimdal/lib/asn1/symbol.h (revision 1b7487592987c91020063a311a14dc15b6e58075)
1b528cefcSMark Murray /*
2ae771770SStanislav Sedov  * Copyright (c) 1997 - 2005 Kungliga Tekniska Högskolan
3b528cefcSMark Murray  * (Royal Institute of Technology, Stockholm, Sweden).
4b528cefcSMark Murray  * All rights reserved.
5b528cefcSMark Murray  *
6b528cefcSMark Murray  * Redistribution and use in source and binary forms, with or without
7b528cefcSMark Murray  * modification, are permitted provided that the following conditions
8b528cefcSMark Murray  * are met:
9b528cefcSMark Murray  *
10b528cefcSMark Murray  * 1. Redistributions of source code must retain the above copyright
11b528cefcSMark Murray  *    notice, this list of conditions and the following disclaimer.
12b528cefcSMark Murray  *
13b528cefcSMark Murray  * 2. Redistributions in binary form must reproduce the above copyright
14b528cefcSMark Murray  *    notice, this list of conditions and the following disclaimer in the
15b528cefcSMark Murray  *    documentation and/or other materials provided with the distribution.
16b528cefcSMark Murray  *
17b528cefcSMark Murray  * 3. Neither the name of the Institute nor the names of its contributors
18b528cefcSMark Murray  *    may be used to endorse or promote products derived from this software
19b528cefcSMark Murray  *    without specific prior written permission.
20b528cefcSMark Murray  *
21b528cefcSMark Murray  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22b528cefcSMark Murray  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23b528cefcSMark Murray  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24b528cefcSMark Murray  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25b528cefcSMark Murray  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26b528cefcSMark Murray  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27b528cefcSMark Murray  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28b528cefcSMark Murray  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29b528cefcSMark Murray  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30b528cefcSMark Murray  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31b528cefcSMark Murray  * SUCH DAMAGE.
32b528cefcSMark Murray  */
33b528cefcSMark Murray 
34ae771770SStanislav Sedov /* $Id$ */
35b528cefcSMark Murray 
36b528cefcSMark Murray #ifndef _SYMBOL_H
37b528cefcSMark Murray #define _SYMBOL_H
38b528cefcSMark Murray 
39c19800e8SDoug Rabson #include "asn1_queue.h"
40c19800e8SDoug Rabson 
41c19800e8SDoug Rabson enum typetype {
42c19800e8SDoug Rabson     TBitString,
43c19800e8SDoug Rabson     TBoolean,
44c19800e8SDoug Rabson     TChoice,
45c19800e8SDoug Rabson     TEnumerated,
46c19800e8SDoug Rabson     TGeneralString,
47ae771770SStanislav Sedov     TTeletexString,
48c19800e8SDoug Rabson     TGeneralizedTime,
49c19800e8SDoug Rabson     TIA5String,
50c19800e8SDoug Rabson     TInteger,
51c19800e8SDoug Rabson     TNull,
52c19800e8SDoug Rabson     TOID,
53c19800e8SDoug Rabson     TOctetString,
54c19800e8SDoug Rabson     TPrintableString,
55c19800e8SDoug Rabson     TSequence,
56c19800e8SDoug Rabson     TSequenceOf,
57c19800e8SDoug Rabson     TSet,
58c19800e8SDoug Rabson     TSetOf,
59c19800e8SDoug Rabson     TTag,
60c19800e8SDoug Rabson     TType,
61c19800e8SDoug Rabson     TUTCTime,
62c19800e8SDoug Rabson     TUTF8String,
63c19800e8SDoug Rabson     TBMPString,
64c19800e8SDoug Rabson     TUniversalString,
65c19800e8SDoug Rabson     TVisibleString
66c19800e8SDoug Rabson };
67b528cefcSMark Murray 
68b528cefcSMark Murray typedef enum typetype Typetype;
69b528cefcSMark Murray 
70b528cefcSMark Murray struct type;
71b528cefcSMark Murray 
72c19800e8SDoug Rabson struct value {
73c19800e8SDoug Rabson     enum { booleanvalue,
74c19800e8SDoug Rabson 	   nullvalue,
75c19800e8SDoug Rabson 	   integervalue,
76c19800e8SDoug Rabson 	   stringvalue,
77c19800e8SDoug Rabson 	   objectidentifiervalue
78c19800e8SDoug Rabson     } type;
79c19800e8SDoug Rabson     union {
80c19800e8SDoug Rabson 	int booleanvalue;
81*1b748759SDimitry Andric 	int64_t integervalue;
82c19800e8SDoug Rabson 	char *stringvalue;
83c19800e8SDoug Rabson 	struct objid *objectidentifiervalue;
84c19800e8SDoug Rabson     } u;
85c19800e8SDoug Rabson };
86c19800e8SDoug Rabson 
87b528cefcSMark Murray struct member {
88b528cefcSMark Murray     char *name;
89b528cefcSMark Murray     char *gen_name;
90c19800e8SDoug Rabson     char *label;
91b528cefcSMark Murray     int val;
92b528cefcSMark Murray     int optional;
93c19800e8SDoug Rabson     int ellipsis;
94b528cefcSMark Murray     struct type *type;
95c19800e8SDoug Rabson     ASN1_TAILQ_ENTRY(member) members;
96c19800e8SDoug Rabson     struct value *defval;
97b528cefcSMark Murray };
98b528cefcSMark Murray 
99b528cefcSMark Murray typedef struct member Member;
100b528cefcSMark Murray 
101c19800e8SDoug Rabson ASN1_TAILQ_HEAD(memhead, member);
102c19800e8SDoug Rabson 
103b528cefcSMark Murray struct symbol;
104b528cefcSMark Murray 
105c19800e8SDoug Rabson struct tagtype {
106c19800e8SDoug Rabson     int tagclass;
107c19800e8SDoug Rabson     int tagvalue;
108c19800e8SDoug Rabson     enum { TE_IMPLICIT, TE_EXPLICIT } tagenv;
109c19800e8SDoug Rabson };
110c19800e8SDoug Rabson 
111c19800e8SDoug Rabson struct range {
112*1b748759SDimitry Andric     /*
113*1b748759SDimitry Andric      * We can't represent unsigned 64-bit ranges because max might be
114*1b748759SDimitry Andric      * negative...
115*1b748759SDimitry Andric      */
116*1b748759SDimitry Andric     int64_t min;
117*1b748759SDimitry Andric     int64_t max;
118c19800e8SDoug Rabson };
119c19800e8SDoug Rabson 
120c19800e8SDoug Rabson enum ctype { CT_CONTENTS, CT_USER } ;
121c19800e8SDoug Rabson 
122c19800e8SDoug Rabson struct constraint_spec;
123c19800e8SDoug Rabson 
124b528cefcSMark Murray struct type {
125b528cefcSMark Murray     Typetype type;
126c19800e8SDoug Rabson     struct memhead *members;
127b528cefcSMark Murray     struct symbol *symbol;
128c19800e8SDoug Rabson     struct type *subtype;
129c19800e8SDoug Rabson     struct tagtype tag;
130c19800e8SDoug Rabson     struct range *range;
131c19800e8SDoug Rabson     struct constraint_spec *constraint;
132b528cefcSMark Murray };
133b528cefcSMark Murray 
134b528cefcSMark Murray typedef struct type Type;
135b528cefcSMark Murray 
136c19800e8SDoug Rabson struct constraint_spec {
137c19800e8SDoug Rabson     enum ctype ctype;
138c19800e8SDoug Rabson     union {
139c19800e8SDoug Rabson 	struct {
140c19800e8SDoug Rabson 	    Type *type;
141c19800e8SDoug Rabson 	    struct value *encoding;
142c19800e8SDoug Rabson 	} content;
143c19800e8SDoug Rabson     } u;
144c19800e8SDoug Rabson };
145c19800e8SDoug Rabson 
146c19800e8SDoug Rabson struct objid {
147c19800e8SDoug Rabson     const char *label;
148c19800e8SDoug Rabson     int value;
149c19800e8SDoug Rabson     struct objid *next;
150c19800e8SDoug Rabson };
151c19800e8SDoug Rabson 
152b528cefcSMark Murray struct symbol {
153b528cefcSMark Murray     char *name;
154b528cefcSMark Murray     char *gen_name;
155c19800e8SDoug Rabson     enum { SUndefined, SValue, Stype } stype;
156c19800e8SDoug Rabson     struct value *value;
157b528cefcSMark Murray     Type *type;
158b528cefcSMark Murray };
159b528cefcSMark Murray 
160b528cefcSMark Murray typedef struct symbol Symbol;
161b528cefcSMark Murray 
162b528cefcSMark Murray void initsym (void);
163b528cefcSMark Murray Symbol *addsym (char *);
164b528cefcSMark Murray void output_name (char *);
165c19800e8SDoug Rabson int checkundefined(void);
166b528cefcSMark Murray #endif
167