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/*
24 * pkcs7Templates.h
25 */
26
27#ifndef	_PKCS7_TEMPLATES_H_
28#define _PKCS7_TEMPLATES_H_
29
30#include <Security/SecAsn1Types.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/*
37 * DigestInfo ::= SEQUENCE {
38 * 		digestAlgorithm DigestAlgorithmIdentifier,
39 * 		digest Digest
40 * }
41 *
42 * Digest ::= OCTET STRING
43 */
44typedef struct {
45	SecAsn1AlgId	digestAlgorithm;
46	SecAsn1Item		digest;
47} NSS_P7_DigestInfo;
48
49extern const SecAsn1Template NSS_P7_DigestInfoTemplate[];
50
51/*
52 * Uninterpreted ContentInfo, with content stripped from its
53 * EXPLICIT CONTEXT_SPECIFIC wrapper
54 *
55 * ContentInfo ::= SEQUENCE {
56 *  	contentType ContentType,
57 * 		content [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL
58 * }
59 */
60typedef struct {
61	SecAsn1Oid	contentType;
62	SecAsn1Item	content;
63} NSS_P7_RawContentInfo;
64
65extern const SecAsn1Template NSS_P7_RawContentInfoTemplate[];
66
67// MARK: ---- ContentInfo.content types -----
68
69/*
70 * Expand beyond ASN_ANY/CSSM_DATA as needed
71 */
72typedef SecAsn1Item NSS_P7_SignedData;
73typedef SecAsn1Item NSS_P7_EnvelData;
74typedef SecAsn1Item NSS_P7_SignEnvelData;
75typedef SecAsn1Item NSS_P7_DigestedData;
76
77/* EncryptedData */
78
79/*
80 * EncryptedContentInfo ::= SEQUENCE {
81 * 		contentType ContentType,
82 * 		contentEncryptionAlgorithm
83 *   		ContentEncryptionAlgorithmIdentifier,
84 * 		encryptedContent
85 * 			[0] IMPLICIT EncryptedContent OPTIONAL
86 * }
87 *
88 * EncryptedContent ::= OCTET STRING
89 */
90
91typedef struct {
92	SecAsn1Oid						contentType;
93	SecAsn1AlgId                    encrAlg;
94	SecAsn1Item						encrContent;
95} NSS_P7_EncrContentInfo;
96
97/*
98 * EncryptedData ::= SEQUENCE {
99 *  	version Version,
100 * 		encryptedContentInfo EncryptedContentInfo
101 * }
102 */
103typedef struct {
104	SecAsn1Item						version;
105	NSS_P7_EncrContentInfo 			contentInfo;
106} NSS_P7_EncryptedData;
107
108extern const SecAsn1Template NSS_P7_EncrContentInfoTemplate[];
109extern const SecAsn1Template NSS_P7_EncryptedDataTemplate[];
110extern const SecAsn1Template NSS_P7_PtrToEncryptedDataTemplate[];
111
112/* the stub templates for unimplemented contentTypes */
113#define NSS_P7_PtrToSignedDataTemplate		kSecAsn1PointerToAnyTemplate
114#define NSS_P7_PtrToEnvelDataTemplate		kSecAsn1PointerToAnyTemplate
115#define NSS_P7_PtrToSignEnvelDataTemplate	kSecAsn1PointerToAnyTemplate
116#define NSS_P7_PtrToDigestedDataTemplate	kSecAsn1PointerToAnyTemplate
117
118// MARK: ---- decoded ContentInfo -----
119
120/*
121 * For convenience, out dynamic template chooser for ContentInfo.content
122 * drops one of these into the decoded struct. Thus, higher level
123 * code doesn't have to grunge around comparing OIDs to figure out
124 * what's there.
125 */
126typedef enum {
127	CT_None = 0,
128	CT_Data,
129	CT_SignedData,
130	CT_EnvData,
131	CT_SignedEnvData,
132	CT_DigestData,
133	CT_EncryptedData
134} NSS_P7_CI_Type;
135
136/*
137 * Decoded ContentInfo. Decoded via SEC_ASN1_DYNAMIC per contentType.
138 */
139typedef struct {
140	SecAsn1Oid		contentType;
141	NSS_P7_CI_Type	type;
142	union {
143		SecAsn1Item *data;			// CSSMOID_PKCS7_Data
144									//   contents of Octet String
145		NSS_P7_SignedData *signedData;
146									// CSSMOID_PKCS7_SignedData
147		NSS_P7_EnvelData *envData;	// CSSMOID_PKCS7_EnvelopedData
148		NSS_P7_SignEnvelData *signEnvelData;
149									// CSSMOID_PKCS7_SignedAndEnvelopedData
150		NSS_P7_DigestedData *digestedData;
151									// CSSMOID_PKCS7_DigestedData
152		NSS_P7_EncryptedData *encryptData;
153									//CSSMOID_PKCS7_EncryptedData
154
155	} content;
156} NSS_P7_DecodedContentInfo;
157
158extern const SecAsn1Template NSS_P7_DecodedContentInfoTemplate[];
159
160#ifdef __cplusplus
161}
162#endif
163
164#endif	/* _PKCS7_TEMPLATES_H_ */
165
166