no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / security / nss / lib / smime / cmsasn1.c
blob8ba95d044e69593dcca7fff06d0061f464ca3820
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /*
6 * CMS ASN.1 templates
7 */
9 #include "cmslocal.h"
11 #include "cert.h"
12 #include "keyhi.h"
13 #include "secasn1.h"
14 #include "secitem.h"
15 #include "secoid.h"
16 #include "prtime.h"
17 #include "secerr.h"
19 extern const SEC_ASN1Template nss_cms_set_of_attribute_template[];
21 SEC_ASN1_MKSUB(CERT_IssuerAndSNTemplate)
22 SEC_ASN1_MKSUB(CERT_SetOfSignedCrlTemplate)
23 SEC_ASN1_MKSUB(SECOID_AlgorithmIDTemplate)
24 SEC_ASN1_MKSUB(SEC_BitStringTemplate)
25 SEC_ASN1_MKSUB(SEC_OctetStringTemplate)
26 SEC_ASN1_MKSUB(SEC_PointerToOctetStringTemplate)
27 SEC_ASN1_MKSUB(SEC_SetOfAnyTemplate)
29 /* -----------------------------------------------------------------------------
30 * MESSAGE
31 * (uses NSSCMSContentInfo)
34 /* forward declaration */
35 static const SEC_ASN1Template *
36 nss_cms_choose_content_template(void *src_or_dest, PRBool encoding);
38 static const SEC_ASN1TemplateChooserPtr nss_cms_chooser = nss_cms_choose_content_template;
40 const SEC_ASN1Template NSSCMSMessageTemplate[] = {
41 { SEC_ASN1_SEQUENCE | SEC_ASN1_MAY_STREAM,
42 0, NULL, sizeof(NSSCMSMessage) },
43 { SEC_ASN1_OBJECT_ID,
44 offsetof(NSSCMSMessage, contentInfo.contentType) },
45 { SEC_ASN1_OPTIONAL | SEC_ASN1_DYNAMIC | SEC_ASN1_MAY_STREAM |
46 SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 0,
47 offsetof(NSSCMSMessage, contentInfo.content),
48 &nss_cms_chooser },
49 { 0 }
52 /* -----------------------------------------------------------------------------
53 * ENCAPSULATED & ENCRYPTED CONTENTINFO
54 * (both use a NSSCMSContentInfo)
56 static const SEC_ASN1Template NSSCMSEncapsulatedContentInfoTemplate[] = {
57 { SEC_ASN1_SEQUENCE | SEC_ASN1_MAY_STREAM,
58 0, NULL, sizeof(NSSCMSContentInfo) },
59 { SEC_ASN1_OBJECT_ID,
60 offsetof(NSSCMSContentInfo, contentType) },
61 { SEC_ASN1_OPTIONAL | SEC_ASN1_EXPLICIT | SEC_ASN1_MAY_STREAM |
62 SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 0,
63 offsetof(NSSCMSContentInfo, rawContent),
64 SEC_ASN1_SUB(SEC_PointerToOctetStringTemplate) },
65 { 0 }
68 static const SEC_ASN1Template NSSCMSEncryptedContentInfoTemplate[] = {
69 { SEC_ASN1_SEQUENCE | SEC_ASN1_MAY_STREAM,
70 0, NULL, sizeof(NSSCMSContentInfo) },
71 { SEC_ASN1_OBJECT_ID,
72 offsetof(NSSCMSContentInfo, contentType) },
73 { SEC_ASN1_INLINE | SEC_ASN1_XTRN,
74 offsetof(NSSCMSContentInfo, contentEncAlg),
75 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
76 { SEC_ASN1_OPTIONAL | SEC_ASN1_POINTER | SEC_ASN1_MAY_STREAM |
77 SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 0,
78 offsetof(NSSCMSContentInfo, rawContent),
79 SEC_ASN1_SUB(SEC_OctetStringTemplate) },
80 { 0 }
83 /* -----------------------------------------------------------------------------
84 * SIGNED DATA
87 const SEC_ASN1Template NSSCMSSignerInfoTemplate[];
89 const SEC_ASN1Template NSSCMSSignedDataTemplate[] = {
90 { SEC_ASN1_SEQUENCE | SEC_ASN1_MAY_STREAM,
91 0, NULL, sizeof(NSSCMSSignedData) },
92 { SEC_ASN1_INTEGER,
93 offsetof(NSSCMSSignedData, version) },
94 { SEC_ASN1_SET_OF | SEC_ASN1_XTRN,
95 offsetof(NSSCMSSignedData, digestAlgorithms),
96 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
97 { SEC_ASN1_INLINE,
98 offsetof(NSSCMSSignedData, contentInfo),
99 NSSCMSEncapsulatedContentInfoTemplate },
100 { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC |
101 SEC_ASN1_XTRN | 0,
102 offsetof(NSSCMSSignedData, rawCerts),
103 SEC_ASN1_SUB(SEC_SetOfAnyTemplate) },
104 { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC |
105 SEC_ASN1_XTRN | 1,
106 offsetof(NSSCMSSignedData, crls),
107 SEC_ASN1_SUB(CERT_SetOfSignedCrlTemplate) },
108 { SEC_ASN1_SET_OF,
109 offsetof(NSSCMSSignedData, signerInfos),
110 NSSCMSSignerInfoTemplate },
111 { 0 }
114 const SEC_ASN1Template NSS_PointerToCMSSignedDataTemplate[] = {
115 { SEC_ASN1_POINTER, 0, NSSCMSSignedDataTemplate }
118 /* -----------------------------------------------------------------------------
119 * signeridentifier
122 static const SEC_ASN1Template NSSCMSSignerIdentifierTemplate[] = {
123 { SEC_ASN1_CHOICE,
124 offsetof(NSSCMSSignerIdentifier, identifierType), NULL,
125 sizeof(NSSCMSSignerIdentifier) },
126 { SEC_ASN1_POINTER | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 0,
127 offsetof(NSSCMSSignerIdentifier, id.subjectKeyID),
128 SEC_ASN1_SUB(SEC_OctetStringTemplate),
129 NSSCMSRecipientID_SubjectKeyID },
130 { SEC_ASN1_POINTER | SEC_ASN1_XTRN,
131 offsetof(NSSCMSSignerIdentifier, id.issuerAndSN),
132 SEC_ASN1_SUB(CERT_IssuerAndSNTemplate),
133 NSSCMSRecipientID_IssuerSN },
134 { 0 }
137 /* -----------------------------------------------------------------------------
138 * signerinfo
141 const SEC_ASN1Template NSSCMSSignerInfoTemplate[] = {
142 { SEC_ASN1_SEQUENCE,
143 0, NULL, sizeof(NSSCMSSignerInfo) },
144 { SEC_ASN1_INTEGER,
145 offsetof(NSSCMSSignerInfo, version) },
146 { SEC_ASN1_INLINE,
147 offsetof(NSSCMSSignerInfo, signerIdentifier),
148 NSSCMSSignerIdentifierTemplate },
149 { SEC_ASN1_INLINE | SEC_ASN1_XTRN,
150 offsetof(NSSCMSSignerInfo, digestAlg),
151 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
152 { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 0,
153 offsetof(NSSCMSSignerInfo, authAttr),
154 nss_cms_set_of_attribute_template },
155 { SEC_ASN1_INLINE | SEC_ASN1_XTRN,
156 offsetof(NSSCMSSignerInfo, digestEncAlg),
157 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
158 { SEC_ASN1_OCTET_STRING,
159 offsetof(NSSCMSSignerInfo, encDigest) },
160 { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 1,
161 offsetof(NSSCMSSignerInfo, unAuthAttr),
162 nss_cms_set_of_attribute_template },
163 { 0 }
166 /* -----------------------------------------------------------------------------
167 * ENVELOPED DATA
170 static const SEC_ASN1Template NSSCMSOriginatorInfoTemplate[] = {
171 { SEC_ASN1_SEQUENCE,
172 0, NULL, sizeof(NSSCMSOriginatorInfo) },
173 { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC |
174 SEC_ASN1_XTRN | 0,
175 offsetof(NSSCMSOriginatorInfo, rawCerts),
176 SEC_ASN1_SUB(SEC_SetOfAnyTemplate) },
177 { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC |
178 SEC_ASN1_XTRN | 1,
179 offsetof(NSSCMSOriginatorInfo, crls),
180 SEC_ASN1_SUB(CERT_SetOfSignedCrlTemplate) },
181 { 0 }
184 const SEC_ASN1Template NSSCMSRecipientInfoTemplate[];
186 const SEC_ASN1Template NSSCMSEnvelopedDataTemplate[] = {
187 { SEC_ASN1_SEQUENCE | SEC_ASN1_MAY_STREAM,
188 0, NULL, sizeof(NSSCMSEnvelopedData) },
189 { SEC_ASN1_INTEGER,
190 offsetof(NSSCMSEnvelopedData, version) },
191 { SEC_ASN1_OPTIONAL | SEC_ASN1_POINTER | SEC_ASN1_CONSTRUCTED |
192 SEC_ASN1_CONTEXT_SPECIFIC | 0,
193 offsetof(NSSCMSEnvelopedData, originatorInfo),
194 NSSCMSOriginatorInfoTemplate },
195 { SEC_ASN1_SET_OF,
196 offsetof(NSSCMSEnvelopedData, recipientInfos),
197 NSSCMSRecipientInfoTemplate },
198 { SEC_ASN1_INLINE,
199 offsetof(NSSCMSEnvelopedData, contentInfo),
200 NSSCMSEncryptedContentInfoTemplate },
201 { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 1,
202 offsetof(NSSCMSEnvelopedData, unprotectedAttr),
203 nss_cms_set_of_attribute_template },
204 { 0 }
207 const SEC_ASN1Template NSS_PointerToCMSEnvelopedDataTemplate[] = {
208 { SEC_ASN1_POINTER, 0, NSSCMSEnvelopedDataTemplate }
211 /* here come the 15 gazillion templates for all the v3 varieties of RecipientInfo */
213 /* -----------------------------------------------------------------------------
214 * key transport recipient info
217 static const SEC_ASN1Template NSSCMSRecipientIdentifierTemplate[] = {
218 { SEC_ASN1_CHOICE,
219 offsetof(NSSCMSRecipientIdentifier, identifierType), NULL,
220 sizeof(NSSCMSRecipientIdentifier) },
221 { SEC_ASN1_POINTER | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 0,
222 offsetof(NSSCMSRecipientIdentifier, id.subjectKeyID),
223 SEC_ASN1_SUB(SEC_OctetStringTemplate),
224 NSSCMSRecipientID_SubjectKeyID },
225 { SEC_ASN1_POINTER | SEC_ASN1_XTRN,
226 offsetof(NSSCMSRecipientIdentifier, id.issuerAndSN),
227 SEC_ASN1_SUB(CERT_IssuerAndSNTemplate),
228 NSSCMSRecipientID_IssuerSN },
229 { 0 }
232 static const SEC_ASN1Template NSSCMSKeyTransRecipientInfoTemplate[] = {
233 { SEC_ASN1_SEQUENCE,
234 0, NULL, sizeof(NSSCMSKeyTransRecipientInfo) },
235 { SEC_ASN1_INTEGER,
236 offsetof(NSSCMSKeyTransRecipientInfo, version) },
237 { SEC_ASN1_INLINE,
238 offsetof(NSSCMSKeyTransRecipientInfo, recipientIdentifier),
239 NSSCMSRecipientIdentifierTemplate },
240 { SEC_ASN1_INLINE | SEC_ASN1_XTRN,
241 offsetof(NSSCMSKeyTransRecipientInfo, keyEncAlg),
242 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
243 { SEC_ASN1_OCTET_STRING,
244 offsetof(NSSCMSKeyTransRecipientInfo, encKey) },
245 { 0 }
248 /* -----------------------------------------------------------------------------
249 * key agreement recipient info
252 static const SEC_ASN1Template NSSCMSOriginatorPublicKeyTemplate[] = {
253 { SEC_ASN1_SEQUENCE,
254 0, NULL, sizeof(NSSCMSOriginatorPublicKey) },
255 { SEC_ASN1_INLINE | SEC_ASN1_XTRN,
256 offsetof(NSSCMSOriginatorPublicKey, algorithmIdentifier),
257 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
258 { SEC_ASN1_INLINE | SEC_ASN1_XTRN,
259 offsetof(NSSCMSOriginatorPublicKey, publicKey),
260 SEC_ASN1_SUB(SEC_BitStringTemplate) },
261 { 0 }
264 static const SEC_ASN1Template NSSCMSOriginatorIdentifierOrKeyTemplate[] = {
265 { SEC_ASN1_CHOICE,
266 offsetof(NSSCMSOriginatorIdentifierOrKey, identifierType), NULL,
267 sizeof(NSSCMSOriginatorIdentifierOrKey) },
268 { SEC_ASN1_POINTER | SEC_ASN1_XTRN,
269 offsetof(NSSCMSOriginatorIdentifierOrKey, id.issuerAndSN),
270 SEC_ASN1_SUB(CERT_IssuerAndSNTemplate),
271 NSSCMSOriginatorIDOrKey_IssuerSN },
272 { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC |
273 SEC_ASN1_XTRN | 1,
274 offsetof(NSSCMSOriginatorIdentifierOrKey, id.subjectKeyID),
275 SEC_ASN1_SUB(SEC_PointerToOctetStringTemplate),
276 NSSCMSOriginatorIDOrKey_SubjectKeyID },
277 { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 2,
278 offsetof(NSSCMSOriginatorIdentifierOrKey, id.originatorPublicKey),
279 NSSCMSOriginatorPublicKeyTemplate,
280 NSSCMSOriginatorIDOrKey_OriginatorPublicKey },
281 { 0 }
284 const SEC_ASN1Template NSSCMSRecipientKeyIdentifierTemplate[] = {
285 { SEC_ASN1_SEQUENCE,
286 0, NULL, sizeof(NSSCMSRecipientKeyIdentifier) },
287 { SEC_ASN1_OCTET_STRING,
288 offsetof(NSSCMSRecipientKeyIdentifier, subjectKeyIdentifier) },
289 { SEC_ASN1_OPTIONAL | SEC_ASN1_OCTET_STRING,
290 offsetof(NSSCMSRecipientKeyIdentifier, date) },
291 { SEC_ASN1_OPTIONAL | SEC_ASN1_OCTET_STRING,
292 offsetof(NSSCMSRecipientKeyIdentifier, other) },
293 { 0 }
296 static const SEC_ASN1Template NSSCMSKeyAgreeRecipientIdentifierTemplate[] = {
297 { SEC_ASN1_CHOICE,
298 offsetof(NSSCMSKeyAgreeRecipientIdentifier, identifierType), NULL,
299 sizeof(NSSCMSKeyAgreeRecipientIdentifier) },
300 { SEC_ASN1_POINTER | SEC_ASN1_XTRN,
301 offsetof(NSSCMSKeyAgreeRecipientIdentifier, id.issuerAndSN),
302 SEC_ASN1_SUB(CERT_IssuerAndSNTemplate),
303 NSSCMSKeyAgreeRecipientID_IssuerSN },
304 { SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 0,
305 offsetof(NSSCMSKeyAgreeRecipientIdentifier, id.recipientKeyIdentifier),
306 NSSCMSRecipientKeyIdentifierTemplate,
307 NSSCMSKeyAgreeRecipientID_RKeyID },
308 { 0 }
311 static const SEC_ASN1Template NSSCMSRecipientEncryptedKeyTemplate[] = {
312 { SEC_ASN1_SEQUENCE,
313 0, NULL, sizeof(NSSCMSRecipientEncryptedKey) },
314 { SEC_ASN1_INLINE,
315 offsetof(NSSCMSRecipientEncryptedKey, recipientIdentifier),
316 NSSCMSKeyAgreeRecipientIdentifierTemplate },
317 { SEC_ASN1_INLINE | SEC_ASN1_XTRN,
318 offsetof(NSSCMSRecipientEncryptedKey, encKey),
319 SEC_ASN1_SUB(SEC_BitStringTemplate) },
320 { 0 }
323 static const SEC_ASN1Template NSSCMSKeyAgreeRecipientInfoTemplate[] = {
324 { SEC_ASN1_SEQUENCE,
325 0, NULL, sizeof(NSSCMSKeyAgreeRecipientInfo) },
326 { SEC_ASN1_INTEGER,
327 offsetof(NSSCMSKeyAgreeRecipientInfo, version) },
328 { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 0,
329 offsetof(NSSCMSKeyAgreeRecipientInfo, originatorIdentifierOrKey),
330 NSSCMSOriginatorIdentifierOrKeyTemplate },
331 { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_EXPLICIT |
332 SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 1,
333 offsetof(NSSCMSKeyAgreeRecipientInfo, ukm),
334 SEC_ASN1_SUB(SEC_OctetStringTemplate) },
335 { SEC_ASN1_INLINE | SEC_ASN1_XTRN,
336 offsetof(NSSCMSKeyAgreeRecipientInfo, keyEncAlg),
337 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
338 { SEC_ASN1_SEQUENCE_OF,
339 offsetof(NSSCMSKeyAgreeRecipientInfo, recipientEncryptedKeys),
340 NSSCMSRecipientEncryptedKeyTemplate },
341 { 0 }
344 /* -----------------------------------------------------------------------------
345 * KEK recipient info
348 static const SEC_ASN1Template NSSCMSKEKIdentifierTemplate[] = {
349 { SEC_ASN1_SEQUENCE,
350 0, NULL, sizeof(NSSCMSKEKIdentifier) },
351 { SEC_ASN1_OCTET_STRING,
352 offsetof(NSSCMSKEKIdentifier, keyIdentifier) },
353 { SEC_ASN1_OPTIONAL | SEC_ASN1_OCTET_STRING,
354 offsetof(NSSCMSKEKIdentifier, date) },
355 { SEC_ASN1_OPTIONAL | SEC_ASN1_OCTET_STRING,
356 offsetof(NSSCMSKEKIdentifier, other) },
357 { 0 }
360 static const SEC_ASN1Template NSSCMSKEKRecipientInfoTemplate[] = {
361 { SEC_ASN1_SEQUENCE,
362 0, NULL, sizeof(NSSCMSKEKRecipientInfo) },
363 { SEC_ASN1_INTEGER,
364 offsetof(NSSCMSKEKRecipientInfo, version) },
365 { SEC_ASN1_INLINE,
366 offsetof(NSSCMSKEKRecipientInfo, kekIdentifier),
367 NSSCMSKEKIdentifierTemplate },
368 { SEC_ASN1_INLINE | SEC_ASN1_XTRN,
369 offsetof(NSSCMSKEKRecipientInfo, keyEncAlg),
370 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
371 { SEC_ASN1_OCTET_STRING,
372 offsetof(NSSCMSKEKRecipientInfo, encKey) },
373 { 0 }
376 /* -----------------------------------------------------------------------------
377 * recipient info
379 const SEC_ASN1Template NSSCMSRecipientInfoTemplate[] = {
380 { SEC_ASN1_CHOICE,
381 offsetof(NSSCMSRecipientInfo, recipientInfoType), NULL,
382 sizeof(NSSCMSRecipientInfo) },
383 { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 1,
384 offsetof(NSSCMSRecipientInfo, ri.keyAgreeRecipientInfo),
385 NSSCMSKeyAgreeRecipientInfoTemplate,
386 NSSCMSRecipientInfoID_KeyAgree },
387 { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 2,
388 offsetof(NSSCMSRecipientInfo, ri.kekRecipientInfo),
389 NSSCMSKEKRecipientInfoTemplate,
390 NSSCMSRecipientInfoID_KEK },
391 { SEC_ASN1_INLINE,
392 offsetof(NSSCMSRecipientInfo, ri.keyTransRecipientInfo),
393 NSSCMSKeyTransRecipientInfoTemplate,
394 NSSCMSRecipientInfoID_KeyTrans },
395 { 0 }
398 /* -----------------------------------------------------------------------------
402 const SEC_ASN1Template NSSCMSDigestedDataTemplate[] = {
403 { SEC_ASN1_SEQUENCE | SEC_ASN1_MAY_STREAM,
404 0, NULL, sizeof(NSSCMSDigestedData) },
405 { SEC_ASN1_INTEGER,
406 offsetof(NSSCMSDigestedData, version) },
407 { SEC_ASN1_INLINE | SEC_ASN1_XTRN,
408 offsetof(NSSCMSDigestedData, digestAlg),
409 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
410 { SEC_ASN1_INLINE,
411 offsetof(NSSCMSDigestedData, contentInfo),
412 NSSCMSEncapsulatedContentInfoTemplate },
413 { SEC_ASN1_OCTET_STRING,
414 offsetof(NSSCMSDigestedData, digest) },
415 { 0 }
418 const SEC_ASN1Template NSS_PointerToCMSDigestedDataTemplate[] = {
419 { SEC_ASN1_POINTER, 0, NSSCMSDigestedDataTemplate }
422 const SEC_ASN1Template NSSCMSEncryptedDataTemplate[] = {
423 { SEC_ASN1_SEQUENCE | SEC_ASN1_MAY_STREAM,
424 0, NULL, sizeof(NSSCMSEncryptedData) },
425 { SEC_ASN1_INTEGER,
426 offsetof(NSSCMSEncryptedData, version) },
427 { SEC_ASN1_INLINE,
428 offsetof(NSSCMSEncryptedData, contentInfo),
429 NSSCMSEncryptedContentInfoTemplate },
430 { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 1,
431 offsetof(NSSCMSEncryptedData, unprotectedAttr),
432 nss_cms_set_of_attribute_template },
433 { 0 }
436 const SEC_ASN1Template NSS_PointerToCMSEncryptedDataTemplate[] = {
437 { SEC_ASN1_POINTER, 0, NSSCMSEncryptedDataTemplate }
440 const SEC_ASN1Template NSSCMSGenericWrapperDataTemplate[] = {
441 { SEC_ASN1_INLINE,
442 offsetof(NSSCMSGenericWrapperData, contentInfo),
443 NSSCMSEncapsulatedContentInfoTemplate },
446 SEC_ASN1_CHOOSER_IMPLEMENT(NSSCMSGenericWrapperDataTemplate)
448 const SEC_ASN1Template NSS_PointerToCMSGenericWrapperDataTemplate[] = {
449 { SEC_ASN1_POINTER, 0, NSSCMSGenericWrapperDataTemplate }
452 SEC_ASN1_CHOOSER_IMPLEMENT(NSS_PointerToCMSGenericWrapperDataTemplate)
454 /* -----------------------------------------------------------------------------
457 static const SEC_ASN1Template *
458 nss_cms_choose_content_template(void *src_or_dest, PRBool encoding)
460 const SEC_ASN1Template *theTemplate;
461 NSSCMSContentInfo *cinfo;
462 SECOidTag type;
464 PORT_Assert(src_or_dest != NULL);
465 if (src_or_dest == NULL)
466 return NULL;
468 cinfo = (NSSCMSContentInfo *)src_or_dest;
469 type = NSS_CMSContentInfo_GetContentTypeTag(cinfo);
470 switch (type) {
471 default:
472 theTemplate = NSS_CMSType_GetTemplate(type);
473 break;
474 case SEC_OID_PKCS7_DATA:
475 theTemplate = SEC_ASN1_GET(SEC_PointerToOctetStringTemplate);
476 break;
477 case SEC_OID_PKCS7_SIGNED_DATA:
478 theTemplate = NSS_PointerToCMSSignedDataTemplate;
479 break;
480 case SEC_OID_PKCS7_ENVELOPED_DATA:
481 theTemplate = NSS_PointerToCMSEnvelopedDataTemplate;
482 break;
483 case SEC_OID_PKCS7_DIGESTED_DATA:
484 theTemplate = NSS_PointerToCMSDigestedDataTemplate;
485 break;
486 case SEC_OID_PKCS7_ENCRYPTED_DATA:
487 theTemplate = NSS_PointerToCMSEncryptedDataTemplate;
488 break;
490 return theTemplate;