|
1 /* |
|
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "pkcs7contentinfo_v2.h" |
|
20 #include "pkcs7asn1.h" |
|
21 |
|
22 EXPORT_C CPKCS7ContentInfo* CPKCS7ContentInfo::NewL(const TDesC8& aRawData) |
|
23 { |
|
24 CPKCS7ContentInfo* self = new (ELeave) CPKCS7ContentInfo(); |
|
25 CleanupStack::PushL(self); |
|
26 self->ConstructL(aRawData); |
|
27 CleanupStack::Pop(self); |
|
28 return self; |
|
29 } |
|
30 |
|
31 CPKCS7ContentInfo::~CPKCS7ContentInfo() |
|
32 { |
|
33 } |
|
34 |
|
35 EXPORT_C CPKCS7ContentInfo::TContentInfoType CPKCS7ContentInfo::ContentType() const |
|
36 { |
|
37 return iContentType; |
|
38 } |
|
39 |
|
40 EXPORT_C const TPtrC8 CPKCS7ContentInfo::ContentData() const |
|
41 { |
|
42 return iContentData; |
|
43 } |
|
44 |
|
45 CPKCS7ContentInfo::CPKCS7ContentInfo(void) |
|
46 { |
|
47 } |
|
48 |
|
49 void CPKCS7ContentInfo::ConstructL(const TDesC8& aRawData) |
|
50 { |
|
51 const TInt minItems = 1; // Must have OID |
|
52 const TInt maxItems = 2; // May have data |
|
53 |
|
54 CArrayPtr<TASN1DecGeneric>* contentInfo = PKCS7ASN1::DecodeSequenceLC(aRawData, minItems, maxItems); |
|
55 |
|
56 const TASN1DecGeneric* contentInfoAt0 = contentInfo->At(0); |
|
57 // Checks its a oid id |
|
58 if(contentInfoAt0->Tag()==EASN1ObjectIdentifier || contentInfoAt0->Class() == EUniversal) |
|
59 { |
|
60 // Gets the oid |
|
61 TASN1DecObjectIdentifier oidDec; |
|
62 HBufC* oidVal = oidDec.DecodeDERL(*contentInfo->At(0)); |
|
63 CleanupStack::PushL(oidVal); |
|
64 // Data itself is optional so make sure its there |
|
65 if(contentInfo->Count() == 2) |
|
66 { |
|
67 const TASN1DecGeneric* contentInfoAt1 = contentInfo->At(1); |
|
68 if ( contentInfoAt1->Tag() == 0 || contentInfoAt1->Class() == EContextSpecific ) |
|
69 { |
|
70 TASN1DecGeneric decGen(contentInfoAt1->GetContentDER()); |
|
71 decGen.InitL(); |
|
72 if(*oidVal == KPkcs7DataOID) |
|
73 { |
|
74 // ContentData is OctetString if ContentType is Data |
|
75 if(decGen.Tag() == EASN1OctetString) |
|
76 { |
|
77 iContentData.Set(decGen.GetContentDER()); |
|
78 } |
|
79 else |
|
80 { |
|
81 User::Leave(KErrArgument); |
|
82 } |
|
83 } |
|
84 else |
|
85 { |
|
86 iContentData.Set(decGen.Encoding()); |
|
87 } |
|
88 } |
|
89 } |
|
90 else |
|
91 { |
|
92 iContentData.Set(KNullDesC8()); |
|
93 } |
|
94 // Checks if it is data OID. |
|
95 if(*oidVal == KPkcs7DataOID) |
|
96 { |
|
97 // The Content Type is indicated by an Integer. |
|
98 // Here if Content Type is equal to Data then,it is represented by 1 |
|
99 // 1 indicates the numeric value of last element in the PKCS7 Data OID. |
|
100 iContentType = EContentTypeData; |
|
101 } |
|
102 else if(*oidVal == KPkcs7SignedDataOID) |
|
103 { |
|
104 // The Content Type is indicated by an Integer. |
|
105 // Here if Content Type is equal to SignedData then,it is represented by 2 |
|
106 // 2 indicates the numeric value of last element in the PKCS7 SignedData OID. |
|
107 iContentType = EContentTypeSignedData; |
|
108 } |
|
109 else if(*oidVal == KPkcs7EnvelopedDataOID) |
|
110 { |
|
111 // The Content Type is indicated by an Integer. |
|
112 // Here if Content Type is equal to EnvelopedData then,it is represented by 3. |
|
113 // 3 indicates the numeric value of last element in the PKCS7 EnvelopedData OID. |
|
114 iContentType = EContentTypeEnvelopedData; |
|
115 } |
|
116 else if(*oidVal == KPkcs7SignedAndEnvelopedDataOID) |
|
117 { |
|
118 // The Content Type is indicated by an Integer. |
|
119 // Here if Content Type is equal to SignedAndEnvelopedData then,it is represented by 4. |
|
120 // 4 indicates the numeric value of last element in the PKCS7 SignedAndEnvelopedData OID. |
|
121 iContentType = EContentTypeSignedAndEnvelopedData; |
|
122 } |
|
123 else if(*oidVal == KPkcs7DigestedDataOID) |
|
124 { |
|
125 // The Content Type is indicated by an Integer. |
|
126 // Here if Content Type is equal to DigestedData then,it is represented by 5. |
|
127 // 5 indicates the numeric value of last element in the PKCS7 DigestedData OID. |
|
128 iContentType = EContentTypeDigestedData; |
|
129 } |
|
130 else if(*oidVal == KPkcs7EncryptedDataOID) |
|
131 { |
|
132 // The Content Type is indicated by an Integer. |
|
133 // Here if Content Type is equal to EncryptedData then,it is represented by 6 |
|
134 // 6 indicates the numeric value of last element in the PKCS7 EncryptedData OID. |
|
135 iContentType = EContentTypeEncryptedData; |
|
136 } |
|
137 else |
|
138 { |
|
139 User::Leave(KErrNotSupported); |
|
140 } |
|
141 CleanupStack::PopAndDestroy(oidVal); |
|
142 } |
|
143 else |
|
144 { |
|
145 User::Leave(KErrArgument); |
|
146 } |
|
147 CleanupStack::PopAndDestroy(contentInfo); |
|
148 } |