os/security/cryptoservices/filebasedcertificateandkeystores/test/keytool/keytool_engine.cpp
First public contribution.
2 * Copyright (c) 2004-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 "keytool_engine.h"
20 #include "keytool_controller.h"
21 #include "keytool_commands.h"
23 #include <keytool.rsg>
26 /*static*/ CKeyToolEngine* CKeyToolEngine::NewLC(CKeyToolController* aController)
28 CKeyToolEngine* self = new (ELeave) CKeyToolEngine(aController);
29 CleanupStack::PushL(self);
34 /* static */ CKeyToolEngine* CKeyToolEngine::NewL(CKeyToolController* aController)
36 CKeyToolEngine* self = CKeyToolEngine::NewLC(aController);
37 CleanupStack::Pop(self);
41 CKeyToolEngine::CKeyToolEngine(CKeyToolController* aController) : CActive(EPriorityNormal)
43 iCurrentAction = EIdle;
44 iController = aController;
45 iInitialized = EFalse;
48 CKeyToolEngine::~CKeyToolEngine()
58 iInitialized = EFalse;
60 delete iMigrateStoreHandler;
64 void CKeyToolEngine::ConstructL()
66 iActiveStarted = EFalse;
67 iScheduler = CActiveScheduler::Current();
70 iActiveStarted = ETrue;
71 iScheduler = new(ELeave) CActiveScheduler;
72 CActiveScheduler::Install(iScheduler);
75 User::LeaveIfError(iFs.Connect());
77 iKeyStore = CUnifiedKeyStore::NewL(iFs);
79 CActiveScheduler::Add(this);
82 void CKeyToolEngine::RunL()
84 if (iStatus.Int() != KErrNone)
86 User::Leave(iStatus.Int());
94 iHandler->DoCommandL(*iKeyStore, iParam);
104 User::Panic(_L("Keytool Engine - Illegal state"), 0);
109 TInt CKeyToolEngine::RunError(TInt aError)
111 CActiveScheduler::Stop();
113 switch (iCurrentAction)
117 TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_LIST, aError));
122 TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_IMPORT, aError));
127 TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_UNKNOWN, aError));
134 void CKeyToolEngine::DoCancel()
136 CActiveScheduler::Stop();
140 //\\//\\//\\//\\////\\//\\//\\//\\////\\//\\//\\//\\//
141 //\\//\\//\\//\\// Business methods //\\//\\//\\//\\//
142 //\\//\\//\\//\\////\\//\\//\\//\\////\\//\\//\\//\\//
144 void CKeyToolEngine::InitializeL()
148 iState = EInitialise;
149 iKeyStore->Initialize(iStatus);
154 iHandler->DoCommandL(*iKeyStore, iParam);
160 void CKeyToolEngine::ListL(CKeyToolParameters* aParam)
164 iCurrentAction = EList;
167 iHandler = CKeytoolList::NewL(iController);
171 void CKeyToolEngine::ImportL(CKeyToolParameters* aParam)
175 if (!aParam->iDefault)
177 iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_KEYFILE);
178 User::Leave(KErrArgument);
182 iCurrentAction = EImport;
183 delete iHandler; // Reentrant call
185 iHandler = CKeytoolImport::NewL(iController);
189 void CKeyToolEngine::RemoveL(CKeyToolParameters* aParam)
193 if (!aParam->iDefault)
195 iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_REMOVE);
196 User::Leave(KErrArgument);
200 iCurrentAction = ERemove;
201 iHandler = CKeytoolRemove::NewL(iController);
206 void CKeyToolEngine::DisplayUsageL(CKeyToolParameters* aParam)
208 iHandler = CKeytoolUsage::NewL(iController);
209 iHandler->DoCommandL(*iKeyStore, aParam);
212 void CKeyToolEngine::ListStoresL(CKeyToolParameters* aParam)
216 iCurrentAction = EList;
217 iHandler = CKeyToolListStores::NewL(iController);
221 void CKeyToolEngine::SetPolicyL(CKeyToolParameters* aParam)
225 if (!aParam->iDefault)
227 iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_SUSERFAIL);
228 User::Leave(KErrArgument);
232 iCurrentAction = ESetPolicy;
233 iHandler = CKeytoolSetPolicy::NewL(iController);
239 void CKeyToolEngine::MigrateStoreL(CKeyToolParameters* aParams)
242 iMigrateStoreHandler = CKeytoolMigrateStore::NewL(aParams);
243 iMigrateStoreHandler->DoCommandL();