2 * Copyright (c) 2003-2004,2008,2010-2012 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
23 * SecAsn1Templates.c - Common ASN1 templates for use with libsecurity_asn1.
31 * Generic templates for individual/simple items and pointers to
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.
46 const SecAsn1Template kSecAsn1AnyTemplate
[] = {
47 { SEC_ASN1_ANY
| SEC_ASN1_MAY_STREAM
, 0, NULL
, sizeof(SecAsn1Item
) }
50 const SecAsn1Template kSecAsn1PointerToAnyTemplate
[] = {
51 { SEC_ASN1_POINTER
, 0, kSecAsn1AnyTemplate
}
54 const SecAsn1Template kSecAsn1SequenceOfAnyTemplate
[] = {
55 { SEC_ASN1_SEQUENCE_OF
, 0, kSecAsn1AnyTemplate
}
58 const SecAsn1Template kSecAsn1SetOfAnyTemplate
[] = {
59 { SEC_ASN1_SET_OF
, 0, kSecAsn1AnyTemplate
}
62 const SecAsn1Template kSecAsn1BitStringTemplate
[] = {
63 { SEC_ASN1_BIT_STRING
| SEC_ASN1_MAY_STREAM
, 0, NULL
, sizeof(SecAsn1Item
) }
66 const SecAsn1Template kSecAsn1PointerToBitStringTemplate
[] = {
67 { SEC_ASN1_POINTER
, 0, kSecAsn1BitStringTemplate
}
70 const SecAsn1Template kSecAsn1SequenceOfBitStringTemplate
[] = {
71 { SEC_ASN1_SEQUENCE_OF
, 0, kSecAsn1BitStringTemplate
}
74 const SecAsn1Template kSecAsn1SetOfBitStringTemplate
[] = {
75 { SEC_ASN1_SET_OF
, 0, kSecAsn1BitStringTemplate
}
78 const SecAsn1Template kSecAsn1BMPStringTemplate
[] = {
79 { SEC_ASN1_BMP_STRING
| SEC_ASN1_MAY_STREAM
, 0, NULL
, sizeof(SecAsn1Item
) }
82 const SecAsn1Template kSecAsn1PointerToBMPStringTemplate
[] = {
83 { SEC_ASN1_POINTER
, 0, kSecAsn1BMPStringTemplate
}
86 const SecAsn1Template kSecAsn1SequenceOfBMPStringTemplate
[] = {
87 { SEC_ASN1_SEQUENCE_OF
, 0, kSecAsn1BMPStringTemplate
}
90 const SecAsn1Template kSecAsn1SetOfBMPStringTemplate
[] = {
91 { SEC_ASN1_SET_OF
, 0, kSecAsn1BMPStringTemplate
}
94 const SecAsn1Template kSecAsn1BooleanTemplate
[] = {
95 { SEC_ASN1_BOOLEAN
, 0, NULL
, sizeof(SecAsn1Item
) }
98 const SecAsn1Template kSecAsn1PointerToBooleanTemplate
[] = {
99 { SEC_ASN1_POINTER
, 0, kSecAsn1BooleanTemplate
}
102 const SecAsn1Template kSecAsn1SequenceOfBooleanTemplate
[] = {
103 { SEC_ASN1_SEQUENCE_OF
, 0, kSecAsn1BooleanTemplate
}
106 const SecAsn1Template kSecAsn1SetOfBooleanTemplate
[] = {
107 { SEC_ASN1_SET_OF
, 0, kSecAsn1BooleanTemplate
}
110 const SecAsn1Template kSecAsn1EnumeratedTemplate
[] = {
111 { SEC_ASN1_ENUMERATED
, 0, NULL
, sizeof(SecAsn1Item
) }
114 const SecAsn1Template kSecAsn1PointerToEnumeratedTemplate
[] = {
115 { SEC_ASN1_POINTER
, 0, kSecAsn1EnumeratedTemplate
}
118 const SecAsn1Template kSecAsn1SequenceOfEnumeratedTemplate
[] = {
119 { SEC_ASN1_SEQUENCE_OF
, 0, kSecAsn1EnumeratedTemplate
}
122 const SecAsn1Template kSecAsn1SetOfEnumeratedTemplate
[] = {
123 { SEC_ASN1_SET_OF
, 0, kSecAsn1EnumeratedTemplate
}
126 const SecAsn1Template kSecAsn1GeneralizedTimeTemplate
[] = {
127 { SEC_ASN1_GENERALIZED_TIME
| SEC_ASN1_MAY_STREAM
, 0, NULL
, sizeof(SecAsn1Item
)}
130 const SecAsn1Template kSecAsn1PointerToGeneralizedTimeTemplate
[] = {
131 { SEC_ASN1_POINTER
, 0, kSecAsn1GeneralizedTimeTemplate
}
134 const SecAsn1Template kSecAsn1SequenceOfGeneralizedTimeTemplate
[] = {
135 { SEC_ASN1_SEQUENCE_OF
, 0, kSecAsn1GeneralizedTimeTemplate
}
138 const SecAsn1Template kSecAsn1SetOfGeneralizedTimeTemplate
[] = {
139 { SEC_ASN1_SET_OF
, 0, kSecAsn1GeneralizedTimeTemplate
}
142 const SecAsn1Template kSecAsn1IA5StringTemplate
[] = {
143 { SEC_ASN1_IA5_STRING
| SEC_ASN1_MAY_STREAM
, 0, NULL
, sizeof(SecAsn1Item
) }
146 const SecAsn1Template kSecAsn1PointerToIA5StringTemplate
[] = {
147 { SEC_ASN1_POINTER
, 0, kSecAsn1IA5StringTemplate
}
150 const SecAsn1Template kSecAsn1SequenceOfIA5StringTemplate
[] = {
151 { SEC_ASN1_SEQUENCE_OF
, 0, kSecAsn1IA5StringTemplate
}
154 const SecAsn1Template kSecAsn1SetOfIA5StringTemplate
[] = {
155 { SEC_ASN1_SET_OF
, 0, kSecAsn1IA5StringTemplate
}
158 const SecAsn1Template kSecAsn1IntegerTemplate
[] = {
159 { SEC_ASN1_INTEGER
| SEC_ASN1_SIGNED_INT
, 0, NULL
, sizeof(SecAsn1Item
) }
162 const SecAsn1Template kSecAsn1UnsignedIntegerTemplate
[] = {
163 { SEC_ASN1_INTEGER
, 0, NULL
, sizeof(SecAsn1Item
) }
166 const SecAsn1Template kSecAsn1PointerToIntegerTemplate
[] = {
167 { SEC_ASN1_POINTER
, 0, kSecAsn1IntegerTemplate
}
170 const SecAsn1Template kSecAsn1SequenceOfIntegerTemplate
[] = {
171 { SEC_ASN1_SEQUENCE_OF
, 0, kSecAsn1IntegerTemplate
}
174 const SecAsn1Template kSecAsn1SetOfIntegerTemplate
[] = {
175 { SEC_ASN1_SET_OF
, 0, kSecAsn1IntegerTemplate
}
178 const SecAsn1Template kSecAsn1NullTemplate
[] = {
179 { SEC_ASN1_NULL
, 0, NULL
, sizeof(SecAsn1Item
) }
182 const SecAsn1Template kSecAsn1PointerToNullTemplate
[] = {
183 { SEC_ASN1_POINTER
, 0, kSecAsn1NullTemplate
}
186 const SecAsn1Template kSecAsn1SequenceOfNullTemplate
[] = {
187 { SEC_ASN1_SEQUENCE_OF
, 0, kSecAsn1NullTemplate
}
190 const SecAsn1Template kSecAsn1SetOfNullTemplate
[] = {
191 { SEC_ASN1_SET_OF
, 0, kSecAsn1NullTemplate
}
194 const SecAsn1Template kSecAsn1ObjectIDTemplate
[] = {
195 { SEC_ASN1_OBJECT_ID
, 0, NULL
, sizeof(SecAsn1Item
) }
198 const SecAsn1Template kSecAsn1PointerToObjectIDTemplate
[] = {
199 { SEC_ASN1_POINTER
, 0, kSecAsn1ObjectIDTemplate
}
202 const SecAsn1Template kSecAsn1SequenceOfObjectIDTemplate
[] = {
203 { SEC_ASN1_SEQUENCE_OF
, 0, kSecAsn1ObjectIDTemplate
}
206 const SecAsn1Template kSecAsn1SetOfObjectIDTemplate
[] = {
207 { SEC_ASN1_SET_OF
, 0, kSecAsn1ObjectIDTemplate
}
210 const SecAsn1Template kSecAsn1OctetStringTemplate
[] = {
211 { SEC_ASN1_OCTET_STRING
| SEC_ASN1_MAY_STREAM
, 0, NULL
, sizeof(SecAsn1Item
) }
214 const SecAsn1Template kSecAsn1PointerToOctetStringTemplate
[] = {
215 { SEC_ASN1_POINTER
| SEC_ASN1_MAY_STREAM
, 0, kSecAsn1OctetStringTemplate
}
218 const SecAsn1Template kSecAsn1SequenceOfOctetStringTemplate
[] = {
219 { SEC_ASN1_SEQUENCE_OF
, 0, kSecAsn1OctetStringTemplate
}
222 const SecAsn1Template kSecAsn1SetOfOctetStringTemplate
[] = {
223 { SEC_ASN1_SET_OF
, 0, kSecAsn1OctetStringTemplate
}
226 const SecAsn1Template kSecAsn1PrintableStringTemplate
[] = {
227 { SEC_ASN1_PRINTABLE_STRING
| SEC_ASN1_MAY_STREAM
, 0, NULL
, sizeof(SecAsn1Item
)}
230 const SecAsn1Template kSecAsn1PointerToPrintableStringTemplate
[] = {
231 { SEC_ASN1_POINTER
, 0, kSecAsn1PrintableStringTemplate
}
234 const SecAsn1Template kSecAsn1SequenceOfPrintableStringTemplate
[] = {
235 { SEC_ASN1_SEQUENCE_OF
, 0, kSecAsn1PrintableStringTemplate
}
238 const SecAsn1Template kSecAsn1SetOfPrintableStringTemplate
[] = {
239 { SEC_ASN1_SET_OF
, 0, kSecAsn1PrintableStringTemplate
}
243 const SecAsn1Template kSecAsn1TeletexStringTemplate
[] = {
244 { SEC_ASN1_TELETEX_STRING
| SEC_ASN1_MAY_STREAM
, 0, NULL
, sizeof(SecAsn1Item
)}
247 const SecAsn1Template kSecAsn1PointerToTeletexStringTemplate
[] = {
248 { SEC_ASN1_POINTER
, 0, kSecAsn1TeletexStringTemplate
}
251 const SecAsn1Template kSecAsn1SequenceOfTeletexStringTemplate
[] = {
252 { SEC_ASN1_SEQUENCE_OF
, 0, kSecAsn1TeletexStringTemplate
}
255 const SecAsn1Template kSecAsn1SetOfTeletexStringTemplate
[] = {
256 { SEC_ASN1_SET_OF
, 0, kSecAsn1TeletexStringTemplate
}
258 #endif /* __APPLE__ */
260 const SecAsn1Template kSecAsn1T61StringTemplate
[] = {
261 { SEC_ASN1_T61_STRING
| SEC_ASN1_MAY_STREAM
, 0, NULL
, sizeof(SecAsn1Item
) }
264 const SecAsn1Template kSecAsn1PointerToT61StringTemplate
[] = {
265 { SEC_ASN1_POINTER
, 0, kSecAsn1T61StringTemplate
}
268 const SecAsn1Template kSecAsn1SequenceOfT61StringTemplate
[] = {
269 { SEC_ASN1_SEQUENCE_OF
, 0, kSecAsn1T61StringTemplate
}
272 const SecAsn1Template kSecAsn1SetOfT61StringTemplate
[] = {
273 { SEC_ASN1_SET_OF
, 0, kSecAsn1T61StringTemplate
}
276 const SecAsn1Template kSecAsn1UniversalStringTemplate
[] = {
277 { SEC_ASN1_UNIVERSAL_STRING
| SEC_ASN1_MAY_STREAM
, 0, NULL
, sizeof(SecAsn1Item
)}
280 const SecAsn1Template kSecAsn1PointerToUniversalStringTemplate
[] = {
281 { SEC_ASN1_POINTER
, 0, kSecAsn1UniversalStringTemplate
}
284 const SecAsn1Template kSecAsn1SequenceOfUniversalStringTemplate
[] = {
285 { SEC_ASN1_SEQUENCE_OF
, 0, kSecAsn1UniversalStringTemplate
}
288 const SecAsn1Template kSecAsn1SetOfUniversalStringTemplate
[] = {
289 { SEC_ASN1_SET_OF
, 0, kSecAsn1UniversalStringTemplate
}
292 const SecAsn1Template kSecAsn1UTCTimeTemplate
[] = {
293 { SEC_ASN1_UTC_TIME
| SEC_ASN1_MAY_STREAM
, 0, NULL
, sizeof(SecAsn1Item
) }
296 const SecAsn1Template kSecAsn1PointerToUTCTimeTemplate
[] = {
297 { SEC_ASN1_POINTER
, 0, kSecAsn1UTCTimeTemplate
}
300 const SecAsn1Template kSecAsn1SequenceOfUTCTimeTemplate
[] = {
301 { SEC_ASN1_SEQUENCE_OF
, 0, kSecAsn1UTCTimeTemplate
}
304 const SecAsn1Template kSecAsn1SetOfUTCTimeTemplate
[] = {
305 { SEC_ASN1_SET_OF
, 0, kSecAsn1UTCTimeTemplate
}
308 const SecAsn1Template kSecAsn1UTF8StringTemplate
[] = {
309 { SEC_ASN1_UTF8_STRING
| SEC_ASN1_MAY_STREAM
, 0, NULL
, sizeof(SecAsn1Item
)}
312 const SecAsn1Template kSecAsn1PointerToUTF8StringTemplate
[] = {
313 { SEC_ASN1_POINTER
, 0, kSecAsn1UTF8StringTemplate
}
316 const SecAsn1Template kSecAsn1SequenceOfUTF8StringTemplate
[] = {
317 { SEC_ASN1_SEQUENCE_OF
, 0, kSecAsn1UTF8StringTemplate
}
320 const SecAsn1Template kSecAsn1SetOfUTF8StringTemplate
[] = {
321 { SEC_ASN1_SET_OF
, 0, kSecAsn1UTF8StringTemplate
}
324 const SecAsn1Template kSecAsn1VisibleStringTemplate
[] = {
325 { SEC_ASN1_VISIBLE_STRING
| SEC_ASN1_MAY_STREAM
, 0, NULL
, sizeof(SecAsn1Item
) }
328 const SecAsn1Template kSecAsn1PointerToVisibleStringTemplate
[] = {
329 { SEC_ASN1_POINTER
, 0, kSecAsn1VisibleStringTemplate
}
332 const SecAsn1Template kSecAsn1SequenceOfVisibleStringTemplate
[] = {
333 { SEC_ASN1_SEQUENCE_OF
, 0, kSecAsn1VisibleStringTemplate
}
336 const SecAsn1Template kSecAsn1SetOfVisibleStringTemplate
[] = {
337 { SEC_ASN1_SET_OF
, 0, kSecAsn1VisibleStringTemplate
}
342 * Template for skipping a subitem.
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!
348 const SecAsn1Template kSecAsn1SkipTemplate
[] = {
354 /* These functions simply return the address of the above-declared templates.
355 ** This is necessary for Windows DLLs. Sigh.
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
)
373 #endif /* __APPLE__ */