First public contribution.
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include "pkcs7contentinfo_v2.h"
20 #include "pkcs7asn1.h"
22 EXPORT_C CPKCS7ContentInfo* CPKCS7ContentInfo::NewL(const TDesC8& aRawData)
24 CPKCS7ContentInfo* self = new (ELeave) CPKCS7ContentInfo();
25 CleanupStack::PushL(self);
26 self->ConstructL(aRawData);
27 CleanupStack::Pop(self);
31 CPKCS7ContentInfo::~CPKCS7ContentInfo()
35 EXPORT_C CPKCS7ContentInfo::TContentInfoType CPKCS7ContentInfo::ContentType() const
40 EXPORT_C const TPtrC8 CPKCS7ContentInfo::ContentData() const
45 CPKCS7ContentInfo::CPKCS7ContentInfo(void)
49 void CPKCS7ContentInfo::ConstructL(const TDesC8& aRawData)
51 const TInt minItems = 1; // Must have OID
52 const TInt maxItems = 2; // May have data
54 CArrayPtr<TASN1DecGeneric>* contentInfo = PKCS7ASN1::DecodeSequenceLC(aRawData, minItems, maxItems);
56 const TASN1DecGeneric* contentInfoAt0 = contentInfo->At(0);
57 // Checks its a oid id
58 if(contentInfoAt0->Tag()==EASN1ObjectIdentifier || contentInfoAt0->Class() == EUniversal)
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)
67 const TASN1DecGeneric* contentInfoAt1 = contentInfo->At(1);
68 if ( contentInfoAt1->Tag() == 0 || contentInfoAt1->Class() == EContextSpecific )
70 TASN1DecGeneric decGen(contentInfoAt1->GetContentDER());
72 if(*oidVal == KPkcs7DataOID)
74 // ContentData is OctetString if ContentType is Data
75 if(decGen.Tag() == EASN1OctetString)
77 iContentData.Set(decGen.GetContentDER());
81 User::Leave(KErrArgument);
86 iContentData.Set(decGen.Encoding());
92 iContentData.Set(KNullDesC8());
94 // Checks if it is data OID.
95 if(*oidVal == KPkcs7DataOID)
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;
102 else if(*oidVal == KPkcs7SignedDataOID)
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;
109 else if(*oidVal == KPkcs7EnvelopedDataOID)
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;
116 else if(*oidVal == KPkcs7SignedAndEnvelopedDataOID)
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;
123 else if(*oidVal == KPkcs7DigestedDataOID)
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;
130 else if(*oidVal == KPkcs7EncryptedDataOID)
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;
139 User::Leave(KErrNotSupported);
141 CleanupStack::PopAndDestroy(oidVal);
145 User::Leave(KErrArgument);
147 CleanupStack::PopAndDestroy(contentInfo);