First public contribution.
2 * Copyright (c) 2005-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 "pkcs7digestinfo.h"
20 #include "pkcs7asn1.h"
22 EXPORT_C CPKCS7DigestInfo* CPKCS7DigestInfo::NewL(const TDesC8& aRawData)
24 CPKCS7DigestInfo* self = new (ELeave) CPKCS7DigestInfo();
25 CleanupStack::PushL(self);
26 self->ConstructL(aRawData);
27 CleanupStack::Pop(self);
31 CPKCS7DigestInfo::~CPKCS7DigestInfo()
35 CPKCS7DigestInfo::CPKCS7DigestInfo()
39 EXPORT_C const TDesC8& CPKCS7DigestInfo::Digest() const
44 EXPORT_C TAlgorithmId CPKCS7DigestInfo::Algorithm() const
49 EXPORT_C const TPtrC8& CPKCS7DigestInfo::EncodedParams() const
51 return iEncodedParams;
54 void CPKCS7DigestInfo::ConstructL(const TDesC8& aDigestData)
56 CArrayPtr<TASN1DecGeneric>* digestInfo = PKCS7ASN1::DecodeSequenceLC(aDigestData);
58 // Check if both the digestAlgorithm and the Digest are present.
59 if ( digestInfo->Count() != 2 )
61 User::Leave(KErrArgument);
65 // Get the algorithm identifier and the encoded parameters present in the sequence.
66 const TASN1DecGeneric* digestInfoAt0 = digestInfo->At(0);
67 if(digestInfoAt0->Tag() != EASN1Sequence || digestInfoAt0->Class() != EUniversal)
69 User::Leave(KErrArgument);
71 CX509AlgorithmIdentifier* digestAlg = CX509AlgorithmIdentifier::NewLC(digestInfo->At(0)->Encoding());
72 TAlgorithmId algorithmId = digestAlg->Algorithm();
91 User::Leave(KErrNotSupported);
94 iEncodedParams.Set(digestAlg->EncodedParams());
97 const TASN1DecGeneric* digestInfoAt1 = digestInfo->At(1);
98 if(digestInfoAt1->Tag() != EASN1OctetString || digestInfoAt1->Class() != EUniversal)
100 User::Leave(KErrArgument);
102 TASN1DecGeneric octetStringDecoder(*(digestInfo->At(1)));
103 octetStringDecoder.InitL();
104 iDigest.Set(octetStringDecoder.GetContentDER());
106 CleanupStack::PopAndDestroy(2,digestInfo);// digestInfo, digestAlg