]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_asn1/Security/SecAsn1Templates.c
Security-57336.1.9.tar.gz
[apple/security.git] / OSX / libsecurity_asn1 / Security / SecAsn1Templates.c
1 /*
2 * Copyright (c) 2003-2004,2008,2010-2012 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 *
23 * SecAsn1Templates.c - Common ASN1 templates for use with libsecurity_asn1.
24 */
25
26 #include "secasn1t.h"
27 #include "seccomon.h"
28 #include <stddef.h>
29
30 /*
31 * Generic templates for individual/simple items and pointers to
32 * and sets of same.
33 *
34 * If you need to add a new one, please note the following:
35 * - For each new basic type you should add *four* templates:
36 * one plain, one PointerTo, one SequenceOf and one SetOf.
37 * - If the new type can be constructed (meaning, it is a
38 * *string* type according to BER/DER rules), then you should
39 * or-in SEC_ASN1_MAY_STREAM to the type in the basic template.
40 * See the definition of the OctetString template for an example.
41 * - It may not be obvious, but these are in *alphabetical*
42 * order based on the SEC_ASN1_XXX name; so put new ones in
43 * the appropriate place.
44 */
45
46 const SecAsn1Template kSecAsn1AnyTemplate[] = {
47 { SEC_ASN1_ANY | SEC_ASN1_MAY_STREAM, 0, NULL, sizeof(SecAsn1Item) }
48 };
49
50 const SecAsn1Template kSecAsn1PointerToAnyTemplate[] = {
51 { SEC_ASN1_POINTER, 0, kSecAsn1AnyTemplate }
52 };
53
54 const SecAsn1Template kSecAsn1SequenceOfAnyTemplate[] = {
55 { SEC_ASN1_SEQUENCE_OF, 0, kSecAsn1AnyTemplate }
56 };
57
58 const SecAsn1Template kSecAsn1SetOfAnyTemplate[] = {
59 { SEC_ASN1_SET_OF, 0, kSecAsn1AnyTemplate }
60 };
61
62 const SecAsn1Template kSecAsn1BitStringTemplate[] = {
63 { SEC_ASN1_BIT_STRING | SEC_ASN1_MAY_STREAM, 0, NULL, sizeof(SecAsn1Item) }
64 };
65
66 const SecAsn1Template kSecAsn1PointerToBitStringTemplate[] = {
67 { SEC_ASN1_POINTER, 0, kSecAsn1BitStringTemplate }
68 };
69
70 const SecAsn1Template kSecAsn1SequenceOfBitStringTemplate[] = {
71 { SEC_ASN1_SEQUENCE_OF, 0, kSecAsn1BitStringTemplate }
72 };
73
74 const SecAsn1Template kSecAsn1SetOfBitStringTemplate[] = {
75 { SEC_ASN1_SET_OF, 0, kSecAsn1BitStringTemplate }
76 };
77
78 const SecAsn1Template kSecAsn1BMPStringTemplate[] = {
79 { SEC_ASN1_BMP_STRING | SEC_ASN1_MAY_STREAM, 0, NULL, sizeof(SecAsn1Item) }
80 };
81
82 const SecAsn1Template kSecAsn1PointerToBMPStringTemplate[] = {
83 { SEC_ASN1_POINTER, 0, kSecAsn1BMPStringTemplate }
84 };
85
86 const SecAsn1Template kSecAsn1SequenceOfBMPStringTemplate[] = {
87 { SEC_ASN1_SEQUENCE_OF, 0, kSecAsn1BMPStringTemplate }
88 };
89
90 const SecAsn1Template kSecAsn1SetOfBMPStringTemplate[] = {
91 { SEC_ASN1_SET_OF, 0, kSecAsn1BMPStringTemplate }
92 };
93
94 const SecAsn1Template kSecAsn1BooleanTemplate[] = {
95 { SEC_ASN1_BOOLEAN, 0, NULL, sizeof(SecAsn1Item) }
96 };
97
98 const SecAsn1Template kSecAsn1PointerToBooleanTemplate[] = {
99 { SEC_ASN1_POINTER, 0, kSecAsn1BooleanTemplate }
100 };
101
102 const SecAsn1Template kSecAsn1SequenceOfBooleanTemplate[] = {
103 { SEC_ASN1_SEQUENCE_OF, 0, kSecAsn1BooleanTemplate }
104 };
105
106 const SecAsn1Template kSecAsn1SetOfBooleanTemplate[] = {
107 { SEC_ASN1_SET_OF, 0, kSecAsn1BooleanTemplate }
108 };
109
110 const SecAsn1Template kSecAsn1EnumeratedTemplate[] = {
111 { SEC_ASN1_ENUMERATED, 0, NULL, sizeof(SecAsn1Item) }
112 };
113
114 const SecAsn1Template kSecAsn1PointerToEnumeratedTemplate[] = {
115 { SEC_ASN1_POINTER, 0, kSecAsn1EnumeratedTemplate }
116 };
117
118 const SecAsn1Template kSecAsn1SequenceOfEnumeratedTemplate[] = {
119 { SEC_ASN1_SEQUENCE_OF, 0, kSecAsn1EnumeratedTemplate }
120 };
121
122 const SecAsn1Template kSecAsn1SetOfEnumeratedTemplate[] = {
123 { SEC_ASN1_SET_OF, 0, kSecAsn1EnumeratedTemplate }
124 };
125
126 const SecAsn1Template kSecAsn1GeneralizedTimeTemplate[] = {
127 { SEC_ASN1_GENERALIZED_TIME | SEC_ASN1_MAY_STREAM, 0, NULL, sizeof(SecAsn1Item)}
128 };
129
130 const SecAsn1Template kSecAsn1PointerToGeneralizedTimeTemplate[] = {
131 { SEC_ASN1_POINTER, 0, kSecAsn1GeneralizedTimeTemplate }
132 };
133
134 const SecAsn1Template kSecAsn1SequenceOfGeneralizedTimeTemplate[] = {
135 { SEC_ASN1_SEQUENCE_OF, 0, kSecAsn1GeneralizedTimeTemplate }
136 };
137
138 const SecAsn1Template kSecAsn1SetOfGeneralizedTimeTemplate[] = {
139 { SEC_ASN1_SET_OF, 0, kSecAsn1GeneralizedTimeTemplate }
140 };
141
142 const SecAsn1Template kSecAsn1IA5StringTemplate[] = {
143 { SEC_ASN1_IA5_STRING | SEC_ASN1_MAY_STREAM, 0, NULL, sizeof(SecAsn1Item) }
144 };
145
146 const SecAsn1Template kSecAsn1PointerToIA5StringTemplate[] = {
147 { SEC_ASN1_POINTER, 0, kSecAsn1IA5StringTemplate }
148 };
149
150 const SecAsn1Template kSecAsn1SequenceOfIA5StringTemplate[] = {
151 { SEC_ASN1_SEQUENCE_OF, 0, kSecAsn1IA5StringTemplate }
152 };
153
154 const SecAsn1Template kSecAsn1SetOfIA5StringTemplate[] = {
155 { SEC_ASN1_SET_OF, 0, kSecAsn1IA5StringTemplate }
156 };
157
158 const SecAsn1Template kSecAsn1IntegerTemplate[] = {
159 { SEC_ASN1_INTEGER | SEC_ASN1_SIGNED_INT, 0, NULL, sizeof(SecAsn1Item) }
160 };
161
162 const SecAsn1Template kSecAsn1UnsignedIntegerTemplate[] = {
163 { SEC_ASN1_INTEGER, 0, NULL, sizeof(SecAsn1Item) }
164 };
165
166 const SecAsn1Template kSecAsn1PointerToIntegerTemplate[] = {
167 { SEC_ASN1_POINTER, 0, kSecAsn1IntegerTemplate }
168 };
169
170 const SecAsn1Template kSecAsn1SequenceOfIntegerTemplate[] = {
171 { SEC_ASN1_SEQUENCE_OF, 0, kSecAsn1IntegerTemplate }
172 };
173
174 const SecAsn1Template kSecAsn1SetOfIntegerTemplate[] = {
175 { SEC_ASN1_SET_OF, 0, kSecAsn1IntegerTemplate }
176 };
177
178 const SecAsn1Template kSecAsn1NullTemplate[] = {
179 { SEC_ASN1_NULL, 0, NULL, sizeof(SecAsn1Item) }
180 };
181
182 const SecAsn1Template kSecAsn1PointerToNullTemplate[] = {
183 { SEC_ASN1_POINTER, 0, kSecAsn1NullTemplate }
184 };
185
186 const SecAsn1Template kSecAsn1SequenceOfNullTemplate[] = {
187 { SEC_ASN1_SEQUENCE_OF, 0, kSecAsn1NullTemplate }
188 };
189
190 const SecAsn1Template kSecAsn1SetOfNullTemplate[] = {
191 { SEC_ASN1_SET_OF, 0, kSecAsn1NullTemplate }
192 };
193
194 const SecAsn1Template kSecAsn1ObjectIDTemplate[] = {
195 { SEC_ASN1_OBJECT_ID, 0, NULL, sizeof(SecAsn1Item) }
196 };
197
198 const SecAsn1Template kSecAsn1PointerToObjectIDTemplate[] = {
199 { SEC_ASN1_POINTER, 0, kSecAsn1ObjectIDTemplate }
200 };
201
202 const SecAsn1Template kSecAsn1SequenceOfObjectIDTemplate[] = {
203 { SEC_ASN1_SEQUENCE_OF, 0, kSecAsn1ObjectIDTemplate }
204 };
205
206 const SecAsn1Template kSecAsn1SetOfObjectIDTemplate[] = {
207 { SEC_ASN1_SET_OF, 0, kSecAsn1ObjectIDTemplate }
208 };
209
210 const SecAsn1Template kSecAsn1OctetStringTemplate[] = {
211 { SEC_ASN1_OCTET_STRING | SEC_ASN1_MAY_STREAM, 0, NULL, sizeof(SecAsn1Item) }
212 };
213
214 const SecAsn1Template kSecAsn1PointerToOctetStringTemplate[] = {
215 { SEC_ASN1_POINTER | SEC_ASN1_MAY_STREAM, 0, kSecAsn1OctetStringTemplate }
216 };
217
218 const SecAsn1Template kSecAsn1SequenceOfOctetStringTemplate[] = {
219 { SEC_ASN1_SEQUENCE_OF, 0, kSecAsn1OctetStringTemplate }
220 };
221
222 const SecAsn1Template kSecAsn1SetOfOctetStringTemplate[] = {
223 { SEC_ASN1_SET_OF, 0, kSecAsn1OctetStringTemplate }
224 };
225
226 const SecAsn1Template kSecAsn1PrintableStringTemplate[] = {
227 { SEC_ASN1_PRINTABLE_STRING | SEC_ASN1_MAY_STREAM, 0, NULL, sizeof(SecAsn1Item)}
228 };
229
230 const SecAsn1Template kSecAsn1PointerToPrintableStringTemplate[] = {
231 { SEC_ASN1_POINTER, 0, kSecAsn1PrintableStringTemplate }
232 };
233
234 const SecAsn1Template kSecAsn1SequenceOfPrintableStringTemplate[] = {
235 { SEC_ASN1_SEQUENCE_OF, 0, kSecAsn1PrintableStringTemplate }
236 };
237
238 const SecAsn1Template kSecAsn1SetOfPrintableStringTemplate[] = {
239 { SEC_ASN1_SET_OF, 0, kSecAsn1PrintableStringTemplate }
240 };
241
242 #ifdef __APPLE__
243 const SecAsn1Template kSecAsn1TeletexStringTemplate[] = {
244 { SEC_ASN1_TELETEX_STRING | SEC_ASN1_MAY_STREAM, 0, NULL, sizeof(SecAsn1Item)}
245 };
246
247 const SecAsn1Template kSecAsn1PointerToTeletexStringTemplate[] = {
248 { SEC_ASN1_POINTER, 0, kSecAsn1TeletexStringTemplate }
249 };
250
251 const SecAsn1Template kSecAsn1SequenceOfTeletexStringTemplate[] = {
252 { SEC_ASN1_SEQUENCE_OF, 0, kSecAsn1TeletexStringTemplate }
253 };
254
255 const SecAsn1Template kSecAsn1SetOfTeletexStringTemplate[] = {
256 { SEC_ASN1_SET_OF, 0, kSecAsn1TeletexStringTemplate }
257 };
258 #endif /* __APPLE__ */
259
260 const SecAsn1Template kSecAsn1T61StringTemplate[] = {
261 { SEC_ASN1_T61_STRING | SEC_ASN1_MAY_STREAM, 0, NULL, sizeof(SecAsn1Item) }
262 };
263
264 const SecAsn1Template kSecAsn1PointerToT61StringTemplate[] = {
265 { SEC_ASN1_POINTER, 0, kSecAsn1T61StringTemplate }
266 };
267
268 const SecAsn1Template kSecAsn1SequenceOfT61StringTemplate[] = {
269 { SEC_ASN1_SEQUENCE_OF, 0, kSecAsn1T61StringTemplate }
270 };
271
272 const SecAsn1Template kSecAsn1SetOfT61StringTemplate[] = {
273 { SEC_ASN1_SET_OF, 0, kSecAsn1T61StringTemplate }
274 };
275
276 const SecAsn1Template kSecAsn1UniversalStringTemplate[] = {
277 { SEC_ASN1_UNIVERSAL_STRING | SEC_ASN1_MAY_STREAM, 0, NULL, sizeof(SecAsn1Item)}
278 };
279
280 const SecAsn1Template kSecAsn1PointerToUniversalStringTemplate[] = {
281 { SEC_ASN1_POINTER, 0, kSecAsn1UniversalStringTemplate }
282 };
283
284 const SecAsn1Template kSecAsn1SequenceOfUniversalStringTemplate[] = {
285 { SEC_ASN1_SEQUENCE_OF, 0, kSecAsn1UniversalStringTemplate }
286 };
287
288 const SecAsn1Template kSecAsn1SetOfUniversalStringTemplate[] = {
289 { SEC_ASN1_SET_OF, 0, kSecAsn1UniversalStringTemplate }
290 };
291
292 const SecAsn1Template kSecAsn1UTCTimeTemplate[] = {
293 { SEC_ASN1_UTC_TIME | SEC_ASN1_MAY_STREAM, 0, NULL, sizeof(SecAsn1Item) }
294 };
295
296 const SecAsn1Template kSecAsn1PointerToUTCTimeTemplate[] = {
297 { SEC_ASN1_POINTER, 0, kSecAsn1UTCTimeTemplate }
298 };
299
300 const SecAsn1Template kSecAsn1SequenceOfUTCTimeTemplate[] = {
301 { SEC_ASN1_SEQUENCE_OF, 0, kSecAsn1UTCTimeTemplate }
302 };
303
304 const SecAsn1Template kSecAsn1SetOfUTCTimeTemplate[] = {
305 { SEC_ASN1_SET_OF, 0, kSecAsn1UTCTimeTemplate }
306 };
307
308 const SecAsn1Template kSecAsn1UTF8StringTemplate[] = {
309 { SEC_ASN1_UTF8_STRING | SEC_ASN1_MAY_STREAM, 0, NULL, sizeof(SecAsn1Item)}
310 };
311
312 const SecAsn1Template kSecAsn1PointerToUTF8StringTemplate[] = {
313 { SEC_ASN1_POINTER, 0, kSecAsn1UTF8StringTemplate }
314 };
315
316 const SecAsn1Template kSecAsn1SequenceOfUTF8StringTemplate[] = {
317 { SEC_ASN1_SEQUENCE_OF, 0, kSecAsn1UTF8StringTemplate }
318 };
319
320 const SecAsn1Template kSecAsn1SetOfUTF8StringTemplate[] = {
321 { SEC_ASN1_SET_OF, 0, kSecAsn1UTF8StringTemplate }
322 };
323
324 const SecAsn1Template kSecAsn1VisibleStringTemplate[] = {
325 { SEC_ASN1_VISIBLE_STRING | SEC_ASN1_MAY_STREAM, 0, NULL, sizeof(SecAsn1Item) }
326 };
327
328 const SecAsn1Template kSecAsn1PointerToVisibleStringTemplate[] = {
329 { SEC_ASN1_POINTER, 0, kSecAsn1VisibleStringTemplate }
330 };
331
332 const SecAsn1Template kSecAsn1SequenceOfVisibleStringTemplate[] = {
333 { SEC_ASN1_SEQUENCE_OF, 0, kSecAsn1VisibleStringTemplate }
334 };
335
336 const SecAsn1Template kSecAsn1SetOfVisibleStringTemplate[] = {
337 { SEC_ASN1_SET_OF, 0, kSecAsn1VisibleStringTemplate }
338 };
339
340
341 /*
342 * Template for skipping a subitem.
343 *
344 * Note that it only makes sense to use this for decoding (when you want
345 * to decode something where you are only interested in one or two of
346 * the fields); you cannot encode a SKIP!
347 */
348 const SecAsn1Template kSecAsn1SkipTemplate[] = {
349 { SEC_ASN1_SKIP }
350 };
351
352 #ifndef __APPLE__
353
354 /* These functions simply return the address of the above-declared templates.
355 ** This is necessary for Windows DLLs. Sigh.
356 */
357 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_AnyTemplate)
358 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_BMPStringTemplate)
359 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_BooleanTemplate)
360 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_BitStringTemplate)
361 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_IA5StringTemplate)
362 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_GeneralizedTimeTemplate)
363 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_IntegerTemplate)
364 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_NullTemplate)
365 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_ObjectIDTemplate)
366 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_OctetStringTemplate)
367 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_PointerToAnyTemplate)
368 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_PointerToOctetStringTemplate)
369 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_SetOfAnyTemplate)
370 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_UTCTimeTemplate)
371 SEC_ASN1_CHOOSER_IMPLEMENT(SEC_UTF8StringTemplate)
372
373 #endif /* __APPLE__ */