blob: 17f398606acdc744dfd148d84e629e735dd4256a [file] [log] [blame]
vlm8a09e0f2005-02-25 14:20:30 +00001#include "asn1fix_internal.h"
2#include "asn1fix_crange.h"
vlmb5be8c32004-08-18 05:42:05 +00003
4/*
5 * Check that a specific constraint is compatible
6 * with the given expression type.
7 */
8int
9asn1constraint_compatible(asn1p_expr_type_e expr_type,
10 enum asn1p_constraint_type_e constr_type) {
11
12 /*
13 * X.680-0207, Table 9.
14 */
15
16 switch(constr_type) {
17 case ACT_INVALID:
18 return 0;
vlm53832f12005-03-20 12:57:21 +000019 case ACT_EL_TYPE:
20 return 1;
vlmb5be8c32004-08-18 05:42:05 +000021 case ACT_EL_VALUE:
22 return 1;
23 case ACT_EL_RANGE:
24 case ACT_EL_LLRANGE:
25 case ACT_EL_RLRANGE:
26 case ACT_EL_ULRANGE:
27 switch(expr_type) {
28 case ASN_BASIC_ENUMERATED:
29 case ASN_BASIC_BOOLEAN:
30 /*
31 * The ValueRange constraint is not formally
32 * applicable to the above types. However, we
33 * support it just fine.
34 */
35 /* Fall through */
36 case ASN_BASIC_INTEGER:
37 case ASN_BASIC_REAL:
38 return 1;
39 default:
40 if(expr_type & ASN_STRING_MASK)
41 return 1;
42 }
43 return 0;
44 case ACT_EL_EXT:
45 return -1;
46 case ACT_CT_FROM:
47 if(expr_type & ASN_STRING_MASK)
48 return 1;
49 return 0;
50 case ACT_CT_SIZE:
51 switch(expr_type) {
52 case ASN_BASIC_BIT_STRING:
53 case ASN_BASIC_OCTET_STRING:
54 case ASN_BASIC_CHARACTER_STRING:
55 case ASN_CONSTR_SEQUENCE_OF:
56 case ASN_CONSTR_SET_OF:
57 return 1;
58 default:
59 if(expr_type & ASN_STRING_MASK)
60 return 1;
61 }
62 return 0;
63 case ACT_CT_WCOMP:
64 case ACT_CT_WCOMPS:
65 switch(expr_type) {
66 case A1TC_INSTANCE:
67 case ASN_BASIC_EXTERNAL:
68 case ASN_BASIC_EMBEDDED_PDV:
69 case ASN_BASIC_REAL:
70 case ASN_BASIC_CHARACTER_STRING:
71 case ASN_CONSTR_CHOICE:
72 case ASN_CONSTR_SEQUENCE:
73 case ASN_CONSTR_SEQUENCE_OF:
74 case ASN_CONSTR_SET:
75 case ASN_CONSTR_SET_OF:
76 return 1;
77 default: break;
78 }
79 return 0;
80 case ACT_CA_SET:
81 case ACT_CA_CRC:
82 case ACT_CA_CSV:
83 case ACT_CA_UNI:
84 case ACT_CA_INT:
85 case ACT_CA_EXC:
86 return 1;
87 }
88
89 return -1;
90}
91
92
vlmee8b06f2004-08-25 02:05:28 +000093#define DECL_RANGE(foo, val1, val2, pv) \
vlmb5be8c32004-08-18 05:42:05 +000094 static asn1cnst_range_t range_ ## foo = { \
95 { ARE_VALUE, 0, val1 }, \
96 { ARE_VALUE, 0, val2 }, \
vlmee8b06f2004-08-25 02:05:28 +000097 0, 0, 0, 0, 0, 0, pv }
98
99#define DECL(foo, val1, val2) DECL_RANGE(foo, val1, val2, 0)
100#define DECL_notPV(foo, val1, val2) DECL_RANGE(foo, val1, val2, 1)
vlmb5be8c32004-08-18 05:42:05 +0000101
102asn1cnst_range_t *
103asn1constraint_default_alphabet(asn1p_expr_type_e expr_type) {
vlmee8b06f2004-08-25 02:05:28 +0000104 DECL_notPV(octstr, 0x00, 0xff); /* Not PER-visible */
105 DECL_notPV(utf8, 0x00, 0x7fffffff); /* Not PER-visible */
106 DECL(bmp, 0x00, 65533); /* 64K-2 cells */
vlmb5be8c32004-08-18 05:42:05 +0000107 DECL(uint7, 0x00, 0x7f);
vlmfef925d2004-08-19 13:28:31 +0000108 DECL(uint31, 0x00, 0x7fffffff);
vlmb5be8c32004-08-18 05:42:05 +0000109 DECL(Space, 0x20, 0x20);
110 DECL(ApostropheAndParens, 0x27, 0x29);
111 DECL(PlusTillColon, 0x2b, 0x3a);
112 DECL(Equal, 0x3d, 0x3d);
113 DECL(QuestionMark, 0x3f, 0x3f);
114 DECL(Digits, 0x30, 0x39);
115 DECL(AlphaCap, 0x41, 0x5a);
116 DECL(AlphaLow, 0x61, 0x7a);
117 DECL(PlusCommaMinusDot, 0x2b, 0x2e);
118 DECL(Plus, 0x2b, 0x2b);
119 DECL(MinusDot, 0x2d, 0x2e);
120 DECL(Z, 0x5a, 0x5a);
121 static asn1cnst_range_t *range_NumericString_array[] = {
122 &range_Space, &range_Digits };
123 static asn1cnst_range_t *range_PrintableString_array[] = {
124 &range_Space,
125 &range_ApostropheAndParens,
126 &range_PlusTillColon,
127 &range_Equal,
128 &range_QuestionMark,
129 &range_AlphaCap,
130 &range_AlphaLow
131 };
132 static asn1cnst_range_t *range_UTCTime_array[] = {
133 &range_Plus, &range_MinusDot, &range_Digits, &range_Z };
134 static asn1cnst_range_t *range_GeneralizedTime_array[] = {
135 &range_PlusCommaMinusDot, &range_Digits, &range_Z };
vlmee8b06f2004-08-25 02:05:28 +0000136
137 static asn1cnst_range_t range_notPERVisible = {
138 { ARE_MIN, 0, 0 },
139 { ARE_MAX, 0, 0 },
140 0, 0, 0, 0, 0, 0, 1 };
vlmb5be8c32004-08-18 05:42:05 +0000141 static asn1cnst_range_t range_NumericString = {
142 { ARE_VALUE, 0, 0x20 },
143 { ARE_VALUE, 0, 0x39 },
144 range_NumericString_array,
145 sizeof(range_NumericString_array)
146 /sizeof(range_NumericString_array[0]),
vlmee8b06f2004-08-25 02:05:28 +0000147 0, 0, 0, 0, 0 };
vlmb5be8c32004-08-18 05:42:05 +0000148 static asn1cnst_range_t range_PrintableString = {
149 { ARE_VALUE, 0, 0x20 },
150 { ARE_VALUE, 0, 0x7a },
151 range_PrintableString_array,
152 sizeof(range_PrintableString_array)
153 /sizeof(range_PrintableString_array[0]),
vlmee8b06f2004-08-25 02:05:28 +0000154 0, 0, 0, 0, 0 };
vlmb5be8c32004-08-18 05:42:05 +0000155 static asn1cnst_range_t range_VisibleString = {
156 { ARE_VALUE, 0, 0x20 },
157 { ARE_VALUE, 0, 0x7e },
vlmee8b06f2004-08-25 02:05:28 +0000158 0, 0, 0, 0, 0, 0, 0 };
vlmb5be8c32004-08-18 05:42:05 +0000159 static asn1cnst_range_t range_UTCTime = {
160 { ARE_VALUE, 0, 0x2b },
161 { ARE_VALUE, 0, 0x5a },
162 range_UTCTime_array,
163 sizeof(range_UTCTime_array)
164 /sizeof(range_UTCTime_array[0]),
vlmee8b06f2004-08-25 02:05:28 +0000165 0, 0, 0, 0, 1 };
vlmb5be8c32004-08-18 05:42:05 +0000166 static asn1cnst_range_t range_GeneralizedTime = {
167 { ARE_VALUE, 0, 0x2b },
168 { ARE_VALUE, 0, 0x5a },
169 range_GeneralizedTime_array,
170 sizeof(range_GeneralizedTime_array)
171 /sizeof(range_GeneralizedTime_array[0]),
vlmee8b06f2004-08-25 02:05:28 +0000172 0, 0, 0, 0, 1 };
vlmb5be8c32004-08-18 05:42:05 +0000173
174 switch(expr_type) {
175 case ASN_STRING_NumericString:
176 return &range_NumericString;
177 case ASN_STRING_PrintableString:
178 return &range_PrintableString;
179 case ASN_STRING_VisibleString:
180 return &range_VisibleString;
181 case ASN_STRING_IA5String:
182 return &range_uint7;
vlmfef925d2004-08-19 13:28:31 +0000183 case ASN_STRING_BMPString:
vlmee8b06f2004-08-25 02:05:28 +0000184 return &range_bmp;
vlmfef925d2004-08-19 13:28:31 +0000185 case ASN_STRING_UTF8String:
vlmee8b06f2004-08-25 02:05:28 +0000186 /*
187 * X.691, #9.3.6
188 * Not a known-multipler character string type.
189 */
190 assert(range_utf8.not_PER_visible);
191 return &range_utf8;
192 case ASN_STRING_UniversalString:
vlmfef925d2004-08-19 13:28:31 +0000193 return &range_uint31;
vlmb5be8c32004-08-18 05:42:05 +0000194 case ASN_BASIC_UTCTime:
vlmee8b06f2004-08-25 02:05:28 +0000195 /* Permitted alphabet constraint is not applicable */
196 assert(range_UTCTime.not_PER_visible);
vlmb5be8c32004-08-18 05:42:05 +0000197 return &range_UTCTime;
198 case ASN_BASIC_GeneralizedTime:
vlmee8b06f2004-08-25 02:05:28 +0000199 /* Permitted alphabet constraint is not applicable */
200 assert(range_GeneralizedTime.not_PER_visible);
vlmb5be8c32004-08-18 05:42:05 +0000201 return &range_GeneralizedTime;
vlmee8b06f2004-08-25 02:05:28 +0000202 case ASN_BASIC_OCTET_STRING:
203 /*
204 * Permitted alphabet constraint is not applicable
205 * to this type. However, we support it, albeit not
206 * in a strict PER mode.
207 */
208 assert(range_octstr.not_PER_visible);
209 return &range_octstr;
vlmb5be8c32004-08-18 05:42:05 +0000210 default:
vlmee8b06f2004-08-25 02:05:28 +0000211 if(!(expr_type & ASN_STRING_MASK))
212 break;
213 assert(expr_type & ASN_STRING_NKM_MASK);
214 /*
215 * X.691, 9.3.6
216 * Not a known-multiplier character string.
217 */
218 return &range_notPERVisible;
vlmb5be8c32004-08-18 05:42:05 +0000219 }
220
221 return NULL;
222}