First public contribution.
2 * Copyright (c) 1998-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 <wtlscertchain.h>
21 #include "wtlscertchainao.h"
24 EXPORT_C TWTLSValidationStatus::TWTLSValidationStatus(const TValidationError aError,
26 :iReason(aError), iCert(aCert)
32 EXPORT_C CWTLSValidationResult* CWTLSValidationResult::NewLC()
34 CWTLSValidationResult* s = new(ELeave) CWTLSValidationResult;
35 CleanupStack::PushL(s);
40 EXPORT_C CWTLSValidationResult* CWTLSValidationResult::NewL()
42 CWTLSValidationResult* s = CWTLSValidationResult::NewLC();
47 EXPORT_C CWTLSValidationResult::~CWTLSValidationResult()
52 CWTLSValidationResult::CWTLSValidationResult()
53 :iError(EValidatedOK, 0)
57 void CWTLSValidationResult::ConstructL()
59 iWarnings = new(ELeave) CArrayFixFlat<TWTLSValidationStatus> (1);
62 EXPORT_C const TWTLSValidationStatus CWTLSValidationResult::Error() const
67 EXPORT_C const CArrayFixFlat<TWTLSValidationStatus>& CWTLSValidationResult::Warnings() const
72 void CWTLSValidationResult::Reset()
74 iError = TWTLSValidationStatus(EValidatedOK, 0);
78 void CWTLSValidationResult::SetError(const TValidationError aError, const TInt aCert)
80 iError.iReason = aError;
84 void CWTLSValidationResult::AppendWarningL(TWTLSValidationStatus aWarning)
86 iWarnings->AppendL(aWarning);
92 EXPORT_C CWTLSCertChain* CWTLSCertChain::NewL(RFs& aFs,
93 const TPtrC8& aEncodedCerts,
96 CWTLSCertChain* self = CWTLSCertChain::NewLC(aFs, aEncodedCerts, aClient);
97 CleanupStack::Pop(); //self
101 EXPORT_C CWTLSCertChain* CWTLSCertChain::NewLC(RFs& aFs,
102 const TPtrC8& aEncodedCerts,
105 CWTLSCertChain* self = new(ELeave) CWTLSCertChain(aFs);
106 CleanupStack::PushL(self);
107 self->ConstructL(aEncodedCerts, aClient);
111 EXPORT_C CWTLSCertChain* CWTLSCertChain::NewL(RFs& aFs,
112 const TPtrC8& aEncodedCerts,
113 const CArrayPtr<CWTLSCertificate>& aRootCerts)
115 CWTLSCertChain* self = CWTLSCertChain::NewLC(aFs, aEncodedCerts, aRootCerts);
116 CleanupStack::Pop();//self
120 EXPORT_C CWTLSCertChain* CWTLSCertChain::NewLC(RFs& aFs,
121 const TPtrC8& aEncodedCerts,
122 const CArrayPtr<CWTLSCertificate>& aRootCerts)
124 CWTLSCertChain* self = new(ELeave) CWTLSCertChain(aFs);
125 CleanupStack::PushL(self);
126 self->ConstructL(aEncodedCerts, aRootCerts);
131 EXPORT_C CWTLSCertChain::~CWTLSCertChain()
134 iChain->ResetAndDestroy();
136 delete iActiveObject;
140 EXPORT_C void CWTLSCertChain::ValidateL(CWTLSValidationResult& aValidationResult,
141 const TTime& aValidationTime,
142 TRequestStatus& aStatus)
144 __ASSERT_DEBUG(iActiveObject, User::Panic(_L("CWTLSCertChain"), 1));
146 iActiveObject->Validate(aValidationResult, aValidationTime, aStatus);
150 EXPORT_C TInt CWTLSCertChain::Count() const
152 return iChain->Count();
155 EXPORT_C const CWTLSCertificate& CWTLSCertChain::Cert(TInt aIndex) const
157 return *(iChain->At(aIndex));
160 EXPORT_C TBool CWTLSCertChain::ChainHasRoot() const
162 return iChainHasRoot;
165 EXPORT_C void CWTLSCertChain::AppendCertsL(const TPtrC8& aEncodedCerts)
167 for(TInt pos = 0; pos < aEncodedCerts.Size(); )
169 CWTLSCertificate* eeCert = CWTLSCertificate::NewLC(aEncodedCerts, pos);
170 iChain->AppendL(eeCert);
171 CleanupStack::Pop(eeCert);
176 CWTLSCertChain::CWTLSCertChain(RFs& aFs)
177 : iFs(aFs), iChainHasRoot(EFalse)
181 void CWTLSCertChain::ConstructL(const TPtrC8& aEncodedCerts, const TUid aClient)
183 iActiveObject = CWTLSCertChainAO::NewL(iFs, *this, aClient);
184 DoConstructL(aEncodedCerts);
187 void CWTLSCertChain::ConstructL(const TPtrC8& aEncodedCerts, const CArrayPtr<CWTLSCertificate>& aRootCerts)
189 iActiveObject = CWTLSCertChainAO::NewL(iFs, *this, aRootCerts);
190 DoConstructL(aEncodedCerts);
193 void CWTLSCertChain::DoConstructL(const TPtrC8& aEncodedCerts)
195 iChain = new(ELeave) CArrayPtrFlat<CWTLSCertificate> (5);
196 //typical cert chain unlikely to be more than 5
197 AppendCertsL(aEncodedCerts);