sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <cmscontentinfo.h>
|
sl@0
|
20 |
#include <asn1dec.h>
|
sl@0
|
21 |
#include <asn1enc.h>
|
sl@0
|
22 |
#include "pkcs7asn1.h"
|
sl@0
|
23 |
#include "cmsutils.h"
|
sl@0
|
24 |
|
sl@0
|
25 |
//
|
sl@0
|
26 |
//Implementation of CMS ContentInfo Identity
|
sl@0
|
27 |
//
|
sl@0
|
28 |
|
sl@0
|
29 |
EXPORT_C CCmsContentInfo* CCmsContentInfo::NewLC(const TDesC8& aRawData)
|
sl@0
|
30 |
{
|
sl@0
|
31 |
CCmsContentInfo* self = new (ELeave) CCmsContentInfo();
|
sl@0
|
32 |
CleanupStack::PushL(self);
|
sl@0
|
33 |
self->ConstructL(aRawData);
|
sl@0
|
34 |
return self;
|
sl@0
|
35 |
}
|
sl@0
|
36 |
|
sl@0
|
37 |
EXPORT_C CCmsContentInfo* CCmsContentInfo::NewL(const TDesC8& aRawData)
|
sl@0
|
38 |
{
|
sl@0
|
39 |
CCmsContentInfo* self = NewLC(aRawData);
|
sl@0
|
40 |
CleanupStack::Pop(self);
|
sl@0
|
41 |
return self;
|
sl@0
|
42 |
}
|
sl@0
|
43 |
|
sl@0
|
44 |
EXPORT_C CCmsContentInfo* CCmsContentInfo::NewL(TCmsContentInfoType aContentInfoType, const TDesC8& aContentData)
|
sl@0
|
45 |
{
|
sl@0
|
46 |
CCmsContentInfo* self = NewLC(aContentInfoType, aContentData);
|
sl@0
|
47 |
CleanupStack::Pop(self);
|
sl@0
|
48 |
return self;
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
EXPORT_C CCmsContentInfo* CCmsContentInfo::NewLC(TCmsContentInfoType aContentInfoType, const TDesC8& aContentData)
|
sl@0
|
52 |
{
|
sl@0
|
53 |
CCmsContentInfo* self = new (ELeave) CCmsContentInfo(aContentInfoType, aContentData);
|
sl@0
|
54 |
CleanupStack::PushL(self);
|
sl@0
|
55 |
return self;
|
sl@0
|
56 |
}
|
sl@0
|
57 |
|
sl@0
|
58 |
EXPORT_C CCmsContentInfo::~CCmsContentInfo()
|
sl@0
|
59 |
{
|
sl@0
|
60 |
|
sl@0
|
61 |
}
|
sl@0
|
62 |
CCmsContentInfo::CCmsContentInfo()
|
sl@0
|
63 |
{
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
CCmsContentInfo::CCmsContentInfo(TCmsContentInfoType aContentInfoType, const TDesC8& aContentData)
|
sl@0
|
67 |
:iContentType(aContentInfoType)
|
sl@0
|
68 |
{
|
sl@0
|
69 |
iContentData.Set(aContentData);
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
void CCmsContentInfo::ConstructL(const TDesC8& aRawData)
|
sl@0
|
73 |
{
|
sl@0
|
74 |
const TInt minItems = 2; // Must have OID
|
sl@0
|
75 |
const TInt maxItems = 2; // Must have data
|
sl@0
|
76 |
CArrayPtr<TASN1DecGeneric>* contentInfo = PKCS7ASN1::DecodeSequenceLC(aRawData, minItems, maxItems);
|
sl@0
|
77 |
|
sl@0
|
78 |
//Decode Content Type
|
sl@0
|
79 |
iContentType=(TCmsContentInfoType)(CmsUtils::DecodeContentTypeL(contentInfo->At(0)));
|
sl@0
|
80 |
|
sl@0
|
81 |
//Decode Content Data
|
sl@0
|
82 |
const TASN1DecGeneric* contentInfoAt1 = contentInfo->At(1);
|
sl@0
|
83 |
if ( contentInfoAt1->Tag() == 0 || contentInfoAt1->Class() == EContextSpecific )
|
sl@0
|
84 |
{
|
sl@0
|
85 |
TASN1DecGeneric decGen(contentInfoAt1->GetContentDER());
|
sl@0
|
86 |
decGen.InitL();
|
sl@0
|
87 |
if (iContentType==EContentTypeData)
|
sl@0
|
88 |
{
|
sl@0
|
89 |
if (decGen.Tag()!=EASN1OctetString || decGen.Class()!=EUniversal)
|
sl@0
|
90 |
{
|
sl@0
|
91 |
User::Leave(KErrArgument);
|
sl@0
|
92 |
}
|
sl@0
|
93 |
else
|
sl@0
|
94 |
{
|
sl@0
|
95 |
iContentData.Set(decGen.GetContentDER());
|
sl@0
|
96 |
}
|
sl@0
|
97 |
}
|
sl@0
|
98 |
else
|
sl@0
|
99 |
{
|
sl@0
|
100 |
iContentData.Set(decGen.Encoding());
|
sl@0
|
101 |
}
|
sl@0
|
102 |
}
|
sl@0
|
103 |
else
|
sl@0
|
104 |
{
|
sl@0
|
105 |
User::Leave(KErrArgument);
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
CleanupStack::PopAndDestroy(contentInfo);
|
sl@0
|
109 |
}
|
sl@0
|
110 |
|
sl@0
|
111 |
EXPORT_C CASN1EncSequence* CCmsContentInfo::EncodeASN1DERLC() const
|
sl@0
|
112 |
{
|
sl@0
|
113 |
// the root sequence contains the OID and the content data
|
sl@0
|
114 |
CASN1EncSequence* root = CASN1EncSequence::NewLC();
|
sl@0
|
115 |
|
sl@0
|
116 |
//Encode the OID
|
sl@0
|
117 |
CASN1EncObjectIdentifier* oid = CmsUtils::EncodeContentTypeLC(iContentType);
|
sl@0
|
118 |
root->AddAndPopChildL(oid);
|
sl@0
|
119 |
|
sl@0
|
120 |
CASN1EncBase* enc(NULL);
|
sl@0
|
121 |
if (iContentType==EContentTypeData)
|
sl@0
|
122 |
{
|
sl@0
|
123 |
enc=CASN1EncOctetString::NewL(iContentData);
|
sl@0
|
124 |
}
|
sl@0
|
125 |
else
|
sl@0
|
126 |
{
|
sl@0
|
127 |
//Encode the Content
|
sl@0
|
128 |
//iContentData already encoded in sequence
|
sl@0
|
129 |
//so just rebuild the structure
|
sl@0
|
130 |
enc = CASN1EncEncoding::NewL(iContentData);
|
sl@0
|
131 |
}
|
sl@0
|
132 |
// Add [0] EXPLICT
|
sl@0
|
133 |
CASN1EncExplicitTag* Enc=CASN1EncExplicitTag::NewLC(enc, 0);
|
sl@0
|
134 |
root->AddAndPopChildL(Enc);
|
sl@0
|
135 |
|
sl@0
|
136 |
return root;
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
EXPORT_C const TPtrC8 CCmsContentInfo::ContentData() const
|
sl@0
|
140 |
{
|
sl@0
|
141 |
return iContentData;
|
sl@0
|
142 |
}
|
sl@0
|
143 |
|
sl@0
|
144 |
EXPORT_C TCmsContentInfoType CCmsContentInfo::ContentType() const
|
sl@0
|
145 |
{
|
sl@0
|
146 |
return iContentType;
|
sl@0
|
147 |
}
|
sl@0
|
148 |
|
sl@0
|
149 |
|
sl@0
|
150 |
//
|
sl@0
|
151 |
//Implementation of CMS EncapsulatedContentInfo Identity
|
sl@0
|
152 |
//
|
sl@0
|
153 |
CEncapsulatedContentInfo* CEncapsulatedContentInfo::NewLC(const TDesC8& aRawData)
|
sl@0
|
154 |
{
|
sl@0
|
155 |
CEncapsulatedContentInfo* self = new (ELeave) CEncapsulatedContentInfo();
|
sl@0
|
156 |
CleanupStack::PushL(self);
|
sl@0
|
157 |
self->ConstructL(aRawData);
|
sl@0
|
158 |
return self;
|
sl@0
|
159 |
}
|
sl@0
|
160 |
|
sl@0
|
161 |
CEncapsulatedContentInfo* CEncapsulatedContentInfo::NewL(const TDesC8& aRawData)
|
sl@0
|
162 |
{
|
sl@0
|
163 |
CEncapsulatedContentInfo* self = NewLC(aRawData);
|
sl@0
|
164 |
CleanupStack::Pop(self);
|
sl@0
|
165 |
return self;
|
sl@0
|
166 |
}
|
sl@0
|
167 |
|
sl@0
|
168 |
CEncapsulatedContentInfo* CEncapsulatedContentInfo::NewLC(TCmsContentInfoType aContentInfoType, TBool aIsEContentDataPresent, const TDesC8& aContentData)
|
sl@0
|
169 |
{
|
sl@0
|
170 |
CEncapsulatedContentInfo* self = new (ELeave) CEncapsulatedContentInfo(aContentInfoType, aIsEContentDataPresent, aContentData);
|
sl@0
|
171 |
CleanupStack::PushL(self);
|
sl@0
|
172 |
return self;
|
sl@0
|
173 |
}
|
sl@0
|
174 |
|
sl@0
|
175 |
CEncapsulatedContentInfo* CEncapsulatedContentInfo::NewL(TCmsContentInfoType aContentInfoType, TBool aIsEContentDataPresent, const TDesC8& aContentData)
|
sl@0
|
176 |
{
|
sl@0
|
177 |
CEncapsulatedContentInfo* self = NewLC(aContentInfoType, aIsEContentDataPresent, aContentData);
|
sl@0
|
178 |
CleanupStack::Pop(self);
|
sl@0
|
179 |
return self;
|
sl@0
|
180 |
}
|
sl@0
|
181 |
|
sl@0
|
182 |
CEncapsulatedContentInfo::CEncapsulatedContentInfo()
|
sl@0
|
183 |
{
|
sl@0
|
184 |
}
|
sl@0
|
185 |
|
sl@0
|
186 |
CEncapsulatedContentInfo::CEncapsulatedContentInfo(TCmsContentInfoType aContentInfoType, TBool aIsEContentDataPresent, const TDesC8& aContentData)
|
sl@0
|
187 |
:iContentType(aContentInfoType),
|
sl@0
|
188 |
iIsContentDataPresent(aIsEContentDataPresent)
|
sl@0
|
189 |
{
|
sl@0
|
190 |
if (aIsEContentDataPresent)
|
sl@0
|
191 |
{
|
sl@0
|
192 |
iContentData.Set(aContentData);
|
sl@0
|
193 |
}
|
sl@0
|
194 |
}
|
sl@0
|
195 |
|
sl@0
|
196 |
void CEncapsulatedContentInfo::ConstructL(const TDesC8& aRawData)
|
sl@0
|
197 |
{
|
sl@0
|
198 |
const TInt minItems = 1; // Must have OID
|
sl@0
|
199 |
const TInt maxItems = 2; // Must have data
|
sl@0
|
200 |
CArrayPtr<TASN1DecGeneric>* contentInfo = PKCS7ASN1::DecodeSequenceLC(aRawData, minItems, maxItems);
|
sl@0
|
201 |
|
sl@0
|
202 |
//Decode Content Type
|
sl@0
|
203 |
iContentType=(TCmsContentInfoType)(CmsUtils::DecodeContentTypeL(contentInfo->At(0)));
|
sl@0
|
204 |
|
sl@0
|
205 |
//Decode Content Data
|
sl@0
|
206 |
if(contentInfo->Count() == 2)
|
sl@0
|
207 |
{
|
sl@0
|
208 |
iIsContentDataPresent=ETrue;
|
sl@0
|
209 |
const TASN1DecGeneric* contentInfoAt1 = contentInfo->At(1);
|
sl@0
|
210 |
|
sl@0
|
211 |
//Decode [0] Explicit
|
sl@0
|
212 |
if ( contentInfoAt1->Tag() == 0 || contentInfoAt1->Class() == EContextSpecific )
|
sl@0
|
213 |
{
|
sl@0
|
214 |
//Decode Wrapper Octet string
|
sl@0
|
215 |
TASN1DecGeneric decGen(contentInfoAt1->GetContentDER());
|
sl@0
|
216 |
decGen.InitL();
|
sl@0
|
217 |
if(decGen.Tag() == EASN1OctetString && decGen.Class() == EUniversal)
|
sl@0
|
218 |
{
|
sl@0
|
219 |
iContentData.Set(decGen.GetContentDER());
|
sl@0
|
220 |
}
|
sl@0
|
221 |
else
|
sl@0
|
222 |
{
|
sl@0
|
223 |
//Wrapper is not an Octect String
|
sl@0
|
224 |
User::Leave(KErrArgument);
|
sl@0
|
225 |
}
|
sl@0
|
226 |
}
|
sl@0
|
227 |
else
|
sl@0
|
228 |
{
|
sl@0
|
229 |
//Not [0] Explicit
|
sl@0
|
230 |
User::Leave(KErrArgument);
|
sl@0
|
231 |
}
|
sl@0
|
232 |
}
|
sl@0
|
233 |
else
|
sl@0
|
234 |
{
|
sl@0
|
235 |
//No optional data
|
sl@0
|
236 |
iContentData.Set(KNullDesC8());
|
sl@0
|
237 |
}
|
sl@0
|
238 |
CleanupStack::PopAndDestroy(contentInfo);
|
sl@0
|
239 |
}
|
sl@0
|
240 |
|
sl@0
|
241 |
|
sl@0
|
242 |
CASN1EncSequence* CEncapsulatedContentInfo::EncodeASN1DERLC() const
|
sl@0
|
243 |
{
|
sl@0
|
244 |
// the root sequence contains the OID and the content data
|
sl@0
|
245 |
CASN1EncSequence* root = CASN1EncSequence::NewLC();
|
sl@0
|
246 |
|
sl@0
|
247 |
//Encode the OID
|
sl@0
|
248 |
CASN1EncObjectIdentifier* oid = CmsUtils::EncodeContentTypeLC(iContentType);
|
sl@0
|
249 |
root->AddAndPopChildL(oid);
|
sl@0
|
250 |
|
sl@0
|
251 |
//Encode the Content
|
sl@0
|
252 |
if (iIsContentDataPresent)
|
sl@0
|
253 |
{
|
sl@0
|
254 |
//Wrapper Octect String
|
sl@0
|
255 |
CASN1EncOctetString* octetString=CASN1EncOctetString::NewL(iContentData);
|
sl@0
|
256 |
|
sl@0
|
257 |
// Add [0] EXPLICT
|
sl@0
|
258 |
CASN1EncExplicitTag* Enc=CASN1EncExplicitTag::NewLC(octetString, 0);
|
sl@0
|
259 |
root->AddAndPopChildL(Enc);
|
sl@0
|
260 |
}
|
sl@0
|
261 |
|
sl@0
|
262 |
return root;
|
sl@0
|
263 |
}
|
sl@0
|
264 |
|
sl@0
|
265 |
|
sl@0
|
266 |
EXPORT_C TBool CEncapsulatedContentInfo::IsContentDataPresent() const
|
sl@0
|
267 |
{
|
sl@0
|
268 |
return iIsContentDataPresent;
|
sl@0
|
269 |
}
|
sl@0
|
270 |
|
sl@0
|
271 |
EXPORT_C const TPtrC8 CEncapsulatedContentInfo::ContentData() const
|
sl@0
|
272 |
{
|
sl@0
|
273 |
return iContentData;
|
sl@0
|
274 |
}
|
sl@0
|
275 |
|
sl@0
|
276 |
EXPORT_C TCmsContentInfoType CEncapsulatedContentInfo::ContentType() const
|
sl@0
|
277 |
{
|
sl@0
|
278 |
return iContentType;
|
sl@0
|
279 |
}
|
sl@0
|
280 |
|
sl@0
|
281 |
|
sl@0
|
282 |
|
sl@0
|
283 |
|
sl@0
|
284 |
|
sl@0
|
285 |
|
sl@0
|
286 |
|
sl@0
|
287 |
|
sl@0
|
288 |
|
sl@0
|
289 |
|
sl@0
|
290 |
|
sl@0
|
291 |
|
sl@0
|
292 |
|
sl@0
|
293 |
|
sl@0
|
294 |
|