blob: effa0ad57947406d4a866ac50dcd4ec8f0e279ae [file] [log] [blame]
vlmb5be8c32004-08-18 05:42:05 +00001#include <asn1fix_internal.h>
2#include <asn1fix_crange.h>
3
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;
19 case ACT_EL_VALUE:
20 return 1;
21 case ACT_EL_RANGE:
22 case ACT_EL_LLRANGE:
23 case ACT_EL_RLRANGE:
24 case ACT_EL_ULRANGE:
25 switch(expr_type) {
26 case ASN_BASIC_ENUMERATED:
27 case ASN_BASIC_BOOLEAN:
28 /*
29 * The ValueRange constraint is not formally
30 * applicable to the above types. However, we
31 * support it just fine.
32 */
33 /* Fall through */
34 case ASN_BASIC_INTEGER:
35 case ASN_BASIC_REAL:
36 return 1;
37 default:
38 if(expr_type & ASN_STRING_MASK)
39 return 1;
40 }
41 return 0;
42 case ACT_EL_EXT:
43 return -1;
44 case ACT_CT_FROM:
45 if(expr_type & ASN_STRING_MASK)
46 return 1;
47 return 0;
48 case ACT_CT_SIZE:
49 switch(expr_type) {
50 case ASN_BASIC_BIT_STRING:
51 case ASN_BASIC_OCTET_STRING:
52 case ASN_BASIC_CHARACTER_STRING:
53 case ASN_CONSTR_SEQUENCE_OF:
54 case ASN_CONSTR_SET_OF:
55 return 1;
56 default:
57 if(expr_type & ASN_STRING_MASK)
58 return 1;
59 }
60 return 0;
61 case ACT_CT_WCOMP:
62 case ACT_CT_WCOMPS:
63 switch(expr_type) {
64 case A1TC_INSTANCE:
65 case ASN_BASIC_EXTERNAL:
66 case ASN_BASIC_EMBEDDED_PDV:
67 case ASN_BASIC_REAL:
68 case ASN_BASIC_CHARACTER_STRING:
69 case ASN_CONSTR_CHOICE:
70 case ASN_CONSTR_SEQUENCE:
71 case ASN_CONSTR_SEQUENCE_OF:
72 case ASN_CONSTR_SET:
73 case ASN_CONSTR_SET_OF:
74 return 1;
75 default: break;
76 }
77 return 0;
78 case ACT_CA_SET:
79 case ACT_CA_CRC:
80 case ACT_CA_CSV:
81 case ACT_CA_UNI:
82 case ACT_CA_INT:
83 case ACT_CA_EXC:
84 return 1;
85 }
86
87 return -1;
88}
89
90
vlmee8b06f2004-08-25 02:05:28 +000091#define DECL_RANGE(foo, val1, val2, pv) \
vlmb5be8c32004-08-18 05:42:05 +000092 static asn1cnst_range_t range_ ## foo = { \
93 { ARE_VALUE, 0, val1 }, \
94 { ARE_VALUE, 0, val2 }, \
vlmee8b06f2004-08-25 02:05:28 +000095 0, 0, 0, 0, 0, 0, pv }
96
97#define DECL(foo, val1, val2) DECL_RANGE(foo, val1, val2, 0)
98#define DECL_notPV(foo, val1, val2) DECL_RANGE(foo, val1, val2, 1)
vlmb5be8c32004-08-18 05:42:05 +000099
100asn1cnst_range_t *
101asn1constraint_default_alphabet(asn1p_expr_type_e expr_type) {
vlmee8b06f2004-08-25 02:05:28 +0000102 DECL_notPV(octstr, 0x00, 0xff); /* Not PER-visible */
103 DECL_notPV(utf8, 0x00, 0x7fffffff); /* Not PER-visible */
104 DECL(bmp, 0x00, 65533); /* 64K-2 cells */
vlmb5be8c32004-08-18 05:42:05 +0000105 DECL(uint7, 0x00, 0x7f);
vlmfef925d2004-08-19 13:28:31 +0000106 DECL(uint31, 0x00, 0x7fffffff);
vlmb5be8c32004-08-18 05:42:05 +0000107 DECL(Space, 0x20, 0x20);
108 DECL(ApostropheAndParens, 0x27, 0x29);
109 DECL(PlusTillColon, 0x2b, 0x3a);
110 DECL(Equal, 0x3d, 0x3d);
111 DECL(QuestionMark, 0x3f, 0x3f);
112 DECL(Digits, 0x30, 0x39);
113 DECL(AlphaCap, 0x41, 0x5a);
114 DECL(AlphaLow, 0x61, 0x7a);
115 DECL(PlusCommaMinusDot, 0x2b, 0x2e);
116 DECL(Plus, 0x2b, 0x2b);
117 DECL(MinusDot, 0x2d, 0x2e);
118 DECL(Z, 0x5a, 0x5a);
119 static asn1cnst_range_t *range_NumericString_array[] = {
120 &range_Space, &range_Digits };
121 static asn1cnst_range_t *range_PrintableString_array[] = {
122 &range_Space,
123 &range_ApostropheAndParens,
124 &range_PlusTillColon,
125 &range_Equal,
126 &range_QuestionMark,
127 &range_AlphaCap,
128 &range_AlphaLow
129 };
130 static asn1cnst_range_t *range_UTCTime_array[] = {
131 &range_Plus, &range_MinusDot, &range_Digits, &range_Z };
132 static asn1cnst_range_t *range_GeneralizedTime_array[] = {
133 &range_PlusCommaMinusDot, &range_Digits, &range_Z };
vlmee8b06f2004-08-25 02:05:28 +0000134
135 static asn1cnst_range_t range_notPERVisible = {
136 { ARE_MIN, 0, 0 },
137 { ARE_MAX, 0, 0 },
138 0, 0, 0, 0, 0, 0, 1 };
vlmb5be8c32004-08-18 05:42:05 +0000139 static asn1cnst_range_t range_NumericString = {
140 { ARE_VALUE, 0, 0x20 },
141 { ARE_VALUE, 0, 0x39 },
142 range_NumericString_array,
143 sizeof(range_NumericString_array)
144 /sizeof(range_NumericString_array[0]),
vlmee8b06f2004-08-25 02:05:28 +0000145 0, 0, 0, 0, 0 };
vlmb5be8c32004-08-18 05:42:05 +0000146 static asn1cnst_range_t range_PrintableString = {
147 { ARE_VALUE, 0, 0x20 },
148 { ARE_VALUE, 0, 0x7a },
149 range_PrintableString_array,
150 sizeof(range_PrintableString_array)
151 /sizeof(range_PrintableString_array[0]),
vlmee8b06f2004-08-25 02:05:28 +0000152 0, 0, 0, 0, 0 };
vlmb5be8c32004-08-18 05:42:05 +0000153 static asn1cnst_range_t range_VisibleString = {
154 { ARE_VALUE, 0, 0x20 },
155 { ARE_VALUE, 0, 0x7e },
vlmee8b06f2004-08-25 02:05:28 +0000156 0, 0, 0, 0, 0, 0, 0 };
vlmb5be8c32004-08-18 05:42:05 +0000157 static asn1cnst_range_t range_UTCTime = {
158 { ARE_VALUE, 0, 0x2b },
159 { ARE_VALUE, 0, 0x5a },
160 range_UTCTime_array,
161 sizeof(range_UTCTime_array)
162 /sizeof(range_UTCTime_array[0]),
vlmee8b06f2004-08-25 02:05:28 +0000163 0, 0, 0, 0, 1 };
vlmb5be8c32004-08-18 05:42:05 +0000164 static asn1cnst_range_t range_GeneralizedTime = {
165 { ARE_VALUE, 0, 0x2b },
166 { ARE_VALUE, 0, 0x5a },
167 range_GeneralizedTime_array,
168 sizeof(range_GeneralizedTime_array)
169 /sizeof(range_GeneralizedTime_array[0]),
vlmee8b06f2004-08-25 02:05:28 +0000170 0, 0, 0, 0, 1 };
vlmb5be8c32004-08-18 05:42:05 +0000171
172 switch(expr_type) {
173 case ASN_STRING_NumericString:
174 return &range_NumericString;
175 case ASN_STRING_PrintableString:
176 return &range_PrintableString;
177 case ASN_STRING_VisibleString:
178 return &range_VisibleString;
179 case ASN_STRING_IA5String:
180 return &range_uint7;
vlmfef925d2004-08-19 13:28:31 +0000181 case ASN_STRING_BMPString:
vlmee8b06f2004-08-25 02:05:28 +0000182 return &range_bmp;
vlmfef925d2004-08-19 13:28:31 +0000183 case ASN_STRING_UTF8String:
vlmee8b06f2004-08-25 02:05:28 +0000184 /*
185 * X.691, #9.3.6
186 * Not a known-multipler character string type.
187 */
188 assert(range_utf8.not_PER_visible);
189 return &range_utf8;
190 case ASN_STRING_UniversalString:
vlmfef925d2004-08-19 13:28:31 +0000191 return &range_uint31;
vlmb5be8c32004-08-18 05:42:05 +0000192 case ASN_BASIC_UTCTime:
vlmee8b06f2004-08-25 02:05:28 +0000193 /* Permitted alphabet constraint is not applicable */
194 assert(range_UTCTime.not_PER_visible);
vlmb5be8c32004-08-18 05:42:05 +0000195 return &range_UTCTime;
196 case ASN_BASIC_GeneralizedTime:
vlmee8b06f2004-08-25 02:05:28 +0000197 /* Permitted alphabet constraint is not applicable */
198 assert(range_GeneralizedTime.not_PER_visible);
vlmb5be8c32004-08-18 05:42:05 +0000199 return &range_GeneralizedTime;
vlmee8b06f2004-08-25 02:05:28 +0000200 case ASN_BASIC_OCTET_STRING:
201 /*
202 * Permitted alphabet constraint is not applicable
203 * to this type. However, we support it, albeit not
204 * in a strict PER mode.
205 */
206 assert(range_octstr.not_PER_visible);
207 return &range_octstr;
vlmb5be8c32004-08-18 05:42:05 +0000208 default:
vlmee8b06f2004-08-25 02:05:28 +0000209 if(!(expr_type & ASN_STRING_MASK))
210 break;
211 assert(expr_type & ASN_STRING_NKM_MASK);
212 /*
213 * X.691, 9.3.6
214 * Not a known-multiplier character string.
215 */
216 return &range_notPERVisible;
vlmb5be8c32004-08-18 05:42:05 +0000217 }
218
219 return NULL;
220}