blob: a0e290bd891b5bb6b1a85cd622904acdb42794b6 [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;
vlm6611add2005-03-20 14:28:32 +000080 case ACT_CT_CTDBY:
81 return 1;
vlmb5be8c32004-08-18 05:42:05 +000082 case ACT_CA_SET:
83 case ACT_CA_CRC:
84 case ACT_CA_CSV:
85 case ACT_CA_UNI:
86 case ACT_CA_INT:
87 case ACT_CA_EXC:
88 return 1;
89 }
90
91 return -1;
92}
93
94
vlmee8b06f2004-08-25 02:05:28 +000095#define DECL_RANGE(foo, val1, val2, pv) \
vlmb5be8c32004-08-18 05:42:05 +000096 static asn1cnst_range_t range_ ## foo = { \
97 { ARE_VALUE, 0, val1 }, \
98 { ARE_VALUE, 0, val2 }, \
vlmee8b06f2004-08-25 02:05:28 +000099 0, 0, 0, 0, 0, 0, pv }
100
101#define DECL(foo, val1, val2) DECL_RANGE(foo, val1, val2, 0)
102#define DECL_notPV(foo, val1, val2) DECL_RANGE(foo, val1, val2, 1)
vlmb5be8c32004-08-18 05:42:05 +0000103
104asn1cnst_range_t *
105asn1constraint_default_alphabet(asn1p_expr_type_e expr_type) {
vlmee8b06f2004-08-25 02:05:28 +0000106 DECL_notPV(octstr, 0x00, 0xff); /* Not PER-visible */
107 DECL_notPV(utf8, 0x00, 0x7fffffff); /* Not PER-visible */
108 DECL(bmp, 0x00, 65533); /* 64K-2 cells */
vlmb5be8c32004-08-18 05:42:05 +0000109 DECL(uint7, 0x00, 0x7f);
vlmfef925d2004-08-19 13:28:31 +0000110 DECL(uint31, 0x00, 0x7fffffff);
vlmb5be8c32004-08-18 05:42:05 +0000111 DECL(Space, 0x20, 0x20);
112 DECL(ApostropheAndParens, 0x27, 0x29);
113 DECL(PlusTillColon, 0x2b, 0x3a);
114 DECL(Equal, 0x3d, 0x3d);
115 DECL(QuestionMark, 0x3f, 0x3f);
116 DECL(Digits, 0x30, 0x39);
117 DECL(AlphaCap, 0x41, 0x5a);
118 DECL(AlphaLow, 0x61, 0x7a);
119 DECL(PlusCommaMinusDot, 0x2b, 0x2e);
120 DECL(Plus, 0x2b, 0x2b);
121 DECL(MinusDot, 0x2d, 0x2e);
122 DECL(Z, 0x5a, 0x5a);
123 static asn1cnst_range_t *range_NumericString_array[] = {
124 &range_Space, &range_Digits };
125 static asn1cnst_range_t *range_PrintableString_array[] = {
126 &range_Space,
127 &range_ApostropheAndParens,
128 &range_PlusTillColon,
129 &range_Equal,
130 &range_QuestionMark,
131 &range_AlphaCap,
132 &range_AlphaLow
133 };
134 static asn1cnst_range_t *range_UTCTime_array[] = {
135 &range_Plus, &range_MinusDot, &range_Digits, &range_Z };
136 static asn1cnst_range_t *range_GeneralizedTime_array[] = {
137 &range_PlusCommaMinusDot, &range_Digits, &range_Z };
vlmee8b06f2004-08-25 02:05:28 +0000138
139 static asn1cnst_range_t range_notPERVisible = {
140 { ARE_MIN, 0, 0 },
141 { ARE_MAX, 0, 0 },
142 0, 0, 0, 0, 0, 0, 1 };
vlmb5be8c32004-08-18 05:42:05 +0000143 static asn1cnst_range_t range_NumericString = {
144 { ARE_VALUE, 0, 0x20 },
145 { ARE_VALUE, 0, 0x39 },
146 range_NumericString_array,
147 sizeof(range_NumericString_array)
148 /sizeof(range_NumericString_array[0]),
vlmee8b06f2004-08-25 02:05:28 +0000149 0, 0, 0, 0, 0 };
vlmb5be8c32004-08-18 05:42:05 +0000150 static asn1cnst_range_t range_PrintableString = {
151 { ARE_VALUE, 0, 0x20 },
152 { ARE_VALUE, 0, 0x7a },
153 range_PrintableString_array,
154 sizeof(range_PrintableString_array)
155 /sizeof(range_PrintableString_array[0]),
vlmee8b06f2004-08-25 02:05:28 +0000156 0, 0, 0, 0, 0 };
vlmb5be8c32004-08-18 05:42:05 +0000157 static asn1cnst_range_t range_VisibleString = {
158 { ARE_VALUE, 0, 0x20 },
159 { ARE_VALUE, 0, 0x7e },
vlmee8b06f2004-08-25 02:05:28 +0000160 0, 0, 0, 0, 0, 0, 0 };
vlmb5be8c32004-08-18 05:42:05 +0000161 static asn1cnst_range_t range_UTCTime = {
162 { ARE_VALUE, 0, 0x2b },
163 { ARE_VALUE, 0, 0x5a },
164 range_UTCTime_array,
165 sizeof(range_UTCTime_array)
166 /sizeof(range_UTCTime_array[0]),
vlmee8b06f2004-08-25 02:05:28 +0000167 0, 0, 0, 0, 1 };
vlmb5be8c32004-08-18 05:42:05 +0000168 static asn1cnst_range_t range_GeneralizedTime = {
169 { ARE_VALUE, 0, 0x2b },
170 { ARE_VALUE, 0, 0x5a },
171 range_GeneralizedTime_array,
172 sizeof(range_GeneralizedTime_array)
173 /sizeof(range_GeneralizedTime_array[0]),
vlmee8b06f2004-08-25 02:05:28 +0000174 0, 0, 0, 0, 1 };
vlmb5be8c32004-08-18 05:42:05 +0000175
176 switch(expr_type) {
177 case ASN_STRING_NumericString:
178 return &range_NumericString;
179 case ASN_STRING_PrintableString:
180 return &range_PrintableString;
181 case ASN_STRING_VisibleString:
182 return &range_VisibleString;
183 case ASN_STRING_IA5String:
184 return &range_uint7;
vlmfef925d2004-08-19 13:28:31 +0000185 case ASN_STRING_BMPString:
vlmee8b06f2004-08-25 02:05:28 +0000186 return &range_bmp;
vlmfef925d2004-08-19 13:28:31 +0000187 case ASN_STRING_UTF8String:
vlmee8b06f2004-08-25 02:05:28 +0000188 /*
189 * X.691, #9.3.6
190 * Not a known-multipler character string type.
191 */
192 assert(range_utf8.not_PER_visible);
193 return &range_utf8;
194 case ASN_STRING_UniversalString:
vlmfef925d2004-08-19 13:28:31 +0000195 return &range_uint31;
vlmb5be8c32004-08-18 05:42:05 +0000196 case ASN_BASIC_UTCTime:
vlmee8b06f2004-08-25 02:05:28 +0000197 /* Permitted alphabet constraint is not applicable */
198 assert(range_UTCTime.not_PER_visible);
vlmb5be8c32004-08-18 05:42:05 +0000199 return &range_UTCTime;
200 case ASN_BASIC_GeneralizedTime:
vlmee8b06f2004-08-25 02:05:28 +0000201 /* Permitted alphabet constraint is not applicable */
202 assert(range_GeneralizedTime.not_PER_visible);
vlmb5be8c32004-08-18 05:42:05 +0000203 return &range_GeneralizedTime;
vlmee8b06f2004-08-25 02:05:28 +0000204 case ASN_BASIC_OCTET_STRING:
205 /*
206 * Permitted alphabet constraint is not applicable
207 * to this type. However, we support it, albeit not
208 * in a strict PER mode.
209 */
210 assert(range_octstr.not_PER_visible);
211 return &range_octstr;
vlmb5be8c32004-08-18 05:42:05 +0000212 default:
vlmee8b06f2004-08-25 02:05:28 +0000213 if(!(expr_type & ASN_STRING_MASK))
214 break;
215 assert(expr_type & ASN_STRING_NKM_MASK);
216 /*
217 * X.691, 9.3.6
218 * Not a known-multiplier character string.
219 */
220 return &range_notPERVisible;
vlmb5be8c32004-08-18 05:42:05 +0000221 }
222
223 return NULL;
224}