os/security/cryptoservices/filebasedcertificateandkeystores/test/certtool/certtool_remove.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/filebasedcertificateandkeystores/test/certtool/certtool_remove.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,118 @@
1.4 +/*
1.5 +* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include "certtool_commands.h"
1.23 +#include "certtool_controller.h"
1.24 +
1.25 +/*static*/ CCertToolRemove* CCertToolRemove::NewLC(CCertToolController* aController)
1.26 + {
1.27 + CCertToolRemove* self = new (ELeave) CCertToolRemove(aController);
1.28 + CleanupStack::PushL(self);
1.29 + self->ConstructL();
1.30 + return self;
1.31 + }
1.32 +
1.33 +/*static*/ CCertToolRemove* CCertToolRemove::NewL(CCertToolController* aController)
1.34 + {
1.35 + CCertToolRemove* self = CCertToolRemove::NewLC(aController);
1.36 + CleanupStack::Pop(self);
1.37 + return self;
1.38 + }
1.39 +
1.40 +CCertToolRemove::CCertToolRemove(CCertToolController* aController) : CCertToolList(aController)
1.41 + {
1.42 +
1.43 + }
1.44 +
1.45 +CCertToolRemove::~CCertToolRemove()
1.46 + {
1.47 + Cancel();
1.48 + }
1.49 +
1.50 +void CCertToolRemove::RunL()
1.51 + {
1.52 + if (iStatus.Int() != KErrNone)
1.53 + {
1.54 + User::Leave(iStatus.Int());
1.55 + }
1.56 + switch (iState)
1.57 + {
1.58 + case EListCerts:
1.59 + {
1.60 + // Look for a specific certificate
1.61 + TInt certIndex = -1;
1.62 + for (TInt j = 0; j < iCertInfos.Count(); j++)
1.63 + {
1.64 + if (iCertInfos[j]->Label() == *iParams->iDefault)
1.65 + {
1.66 + certIndex = j;
1.67 + break;
1.68 + }
1.69 + }
1.70 +
1.71 + if (certIndex != -1)
1.72 + {
1.73 + iState = EFinished;
1.74 + SetActive();
1.75 + iCertStore->Remove(*iCertInfos[certIndex], iStatus);
1.76 + }
1.77 + else
1.78 + {
1.79 + User::Leave(KErrNotFound);
1.80 + }
1.81 + }
1.82 + break;
1.83 + case EFinished:
1.84 + {
1.85 +
1.86 + User::LeaveIfError(iStatus.Int());
1.87 +
1.88 + // We are done!
1.89 + iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_REMOVE_SUCCESS);
1.90 +
1.91 + CActiveScheduler::Stop();
1.92 + }
1.93 + break;
1.94 + default:
1.95 + {
1.96 + User::Panic(_L("REMOVE action: Illegal state."), 1);
1.97 + }
1.98 + }
1.99 + }
1.100 +
1.101 +TInt CCertToolRemove::RunError(TInt aError)
1.102 + {
1.103 + CActiveScheduler::Stop();
1.104 +
1.105 + switch (aError)
1.106 + {
1.107 + case KErrNotFound :
1.108 + {
1.109 + TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_NOTFOUND));
1.110 + }
1.111 + break;
1.112 + default:
1.113 + {
1.114 + TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_REMOVE_FAILURE, aError));
1.115 + }
1.116 + }
1.117 +
1.118 + TRAP_IGNORE(iController->DisplayErrorL(_L("\n"), iParams->iPageWise));
1.119 + return KErrNone;
1.120 + }
1.121 +