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@
28 #include "pkcs7Templates.h"
29 #include "keyTemplates.h" /* NSS_AlgorithmIDTemplate */
30 #include "SecAsn1Templates.h"
34 const SecAsn1Template NSS_P7_DigestInfoTemplate
[] = {
36 0, NULL
, sizeof(NSS_P7_DigestInfo
) },
38 offsetof(NSS_P7_DigestInfo
,digestAlgorithm
),
39 kSecAsn1AlgorithmIDTemplate
},
40 { SEC_ASN1_OCTET_STRING
,
41 offsetof(NSS_P7_DigestInfo
,digest
) },
46 * Uninterpreted ContentInfo, with content stripped from its
47 * EXPLICIT CONTEXT_SPECIFIC wrapper
49 const SecAsn1Template NSS_P7_RawContentInfoTemplate
[] = {
51 0, NULL
, sizeof(NSS_P7_RawContentInfo
) },
53 offsetof(NSS_P7_RawContentInfo
,contentType
) },
54 { SEC_ASN1_CONTEXT_SPECIFIC
| SEC_ASN1_EXPLICIT
|
55 SEC_ASN1_CONSTRUCTED
| SEC_ASN1_OPTIONAL
| 0,
56 offsetof(NSS_P7_RawContentInfo
,content
),
57 kSecAsn1AnyTemplate
},
62 * Individual ContentInfo.content templates
64 const SecAsn1Template NSS_P7_EncrContentInfoTemplate
[] = {
66 0, NULL
, sizeof(NSS_P7_EncrContentInfo
) },
68 offsetof(NSS_P7_EncrContentInfo
,contentType
) },
70 offsetof(NSS_P7_EncrContentInfo
,encrAlg
),
71 kSecAsn1AlgorithmIDTemplate
},
72 { SEC_ASN1_CONTEXT_SPECIFIC
| SEC_ASN1_OPTIONAL
| 0,
73 offsetof(NSS_P7_EncrContentInfo
,encrContent
),
74 kSecAsn1OctetStringTemplate
},
78 const SecAsn1Template NSS_P7_EncryptedDataTemplate
[] = {
80 0, NULL
, sizeof(NSS_P7_EncryptedData
) },
82 offsetof(NSS_P7_EncryptedData
,version
) },
84 offsetof(NSS_P7_EncryptedData
,contentInfo
),
85 NSS_P7_EncrContentInfoTemplate
},
89 const SecAsn1Template NSS_P7_PtrToEncryptedDataTemplate
[] = {
90 { SEC_ASN1_POINTER
, 0, NSS_P7_EncryptedDataTemplate
}
94 * Decoded ContentInfo via SEC_ASN1_DYNAMIC
97 static const SecAsn1Template
* NSS_P7_ContentInfoChooser(
98 void *arg
, // --> NSS_P7_DecodedContentInfo
100 const char *buf
, // on decode, tag byte
101 void *dest
) // --> NSS_P7_DecodedContentInfo.content
103 NSS_P7_DecodedContentInfo
*dci
=
104 (NSS_P7_DecodedContentInfo
*)arg
;
105 const SecAsn1Template
*templ
= NULL
;
106 NSS_P7_CI_Type type
= CT_None
;
108 if(nssCompareSecAsn1Items(&dci
->contentType
,
109 &CSSMOID_PKCS7_Data
)) {
110 templ
= kSecAsn1PointerToOctetStringTemplate
;
113 else if(nssCompareSecAsn1Items(&dci
->contentType
,
114 &CSSMOID_PKCS7_EncryptedData
)) {
115 templ
= NSS_P7_PtrToEncryptedDataTemplate
;
116 type
= CT_EncryptedData
;
118 else if(nssCompareSecAsn1Items(&dci
->contentType
,
119 &CSSMOID_PKCS7_SignedData
)) {
120 templ
= NSS_P7_PtrToSignedDataTemplate
;
121 type
= CT_SignedData
;
123 else if(nssCompareSecAsn1Items(&dci
->contentType
,
124 &CSSMOID_PKCS7_EnvelopedData
)) {
125 templ
= NSS_P7_PtrToEnvelDataTemplate
;
128 else if(nssCompareSecAsn1Items(&dci
->contentType
,
129 &CSSMOID_PKCS7_SignedAndEnvelopedData
)) {
130 templ
= NSS_P7_PtrToSignEnvelDataTemplate
;
131 type
= CT_SignedEnvData
;
133 else if(nssCompareSecAsn1Items(&dci
->contentType
,
134 &CSSMOID_PKCS7_DigestedData
)) {
135 templ
= NSS_P7_PtrToDigestedDataTemplate
;
136 type
= CT_DigestData
;
138 /* add more here when we implement them */
140 return kSecAsn1PointerToAnyTemplate
;
148 static const SecAsn1TemplateChooserPtr NSS_P7_ContentInfoChooserPtr
=
149 NSS_P7_ContentInfoChooser
;
151 const SecAsn1Template NSS_P7_DecodedContentInfoTemplate
[] = {
153 0, NULL
, sizeof(NSS_P7_DecodedContentInfo
) },
154 { SEC_ASN1_OBJECT_ID
,
155 offsetof(NSS_P7_DecodedContentInfo
,contentType
) },
156 { SEC_ASN1_OPTIONAL
| SEC_ASN1_DYNAMIC
|
157 SEC_ASN1_EXPLICIT
| SEC_ASN1_CONSTRUCTED
|
158 SEC_ASN1_CONTEXT_SPECIFIC
| 0,
159 offsetof(NSS_P7_DecodedContentInfo
,content
),
160 &NSS_P7_ContentInfoChooserPtr
},