cpsecplugins/cpadvancedsecplugin/src/advsecsettingssecuritymoduleeraser_symbian.cpp
changeset 63 989397f9511c
equal deleted inserted replaced
62:3255e7d5bd67 63:989397f9511c
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Helper class to remove a security module
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "advsecsettingssecuritymoduleeraser_symbian.h"
       
    20 #include <unifiedkeystore.h>            // CUnifiedKeyStore
       
    21 #include <ct/tcttokenobjecthandle.h>    // TCTTokenObjectHandle
       
    22 
       
    23 
       
    24 // ======== MEMBER FUNCTIONS ========
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // CAdvSecSettingsSecurityModuleEraser::NewL()
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 CAdvSecSettingsSecurityModuleEraser *CAdvSecSettingsSecurityModuleEraser::NewL(
       
    31     CUnifiedKeyStore &aKeyStore)
       
    32 {
       
    33     CAdvSecSettingsSecurityModuleEraser *self = new(ELeave) CAdvSecSettingsSecurityModuleEraser(
       
    34         aKeyStore);
       
    35     CleanupStack::PushL(self);
       
    36     self->ConstructL();
       
    37     CleanupStack::Pop(self);
       
    38     return self;
       
    39 }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CAdvSecSettingsSecurityModuleEraser::~CAdvSecSettingsSecurityModuleEraser()
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CAdvSecSettingsSecurityModuleEraser::~CAdvSecSettingsSecurityModuleEraser()
       
    46 {
       
    47     iKeys.Close();
       
    48     delete iKeyFilter;
       
    49     iTargetKeyStore = NULL;
       
    50     iClientStatus = NULL;
       
    51 }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CAdvSecSettingsSecurityModuleEraser::Erase()
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 void CAdvSecSettingsSecurityModuleEraser::Erase(TInt aKeyStoreIndex, TRequestStatus &aStatus)
       
    58 {
       
    59     aStatus = KRequestPending;
       
    60     if (!IsActive() && (iState == EIdle)) {
       
    61         if (aKeyStoreIndex >= 0 && aKeyStoreIndex < iKeyStore.KeyStoreCount()) {
       
    62             iTargetKeyStore = &(iKeyStore.KeyStore(aKeyStoreIndex));
       
    63             iClientStatus = &aStatus;
       
    64 
       
    65             iKeys.Reset();
       
    66             iTargetKeyStore->List(iKeys, *iKeyFilter, iStatus);
       
    67             iState = EListingKeys;
       
    68             SetActive();
       
    69         } else {
       
    70             TRequestStatus *status = &aStatus;
       
    71             User::RequestComplete(status, KErrArgument);
       
    72         }
       
    73     } else {
       
    74         TRequestStatus *status = &aStatus;
       
    75         User::RequestComplete(status, KErrInUse);
       
    76     }
       
    77 }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // CAdvSecSettingsSecurityModuleEraser::DoCancel()
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 void CAdvSecSettingsSecurityModuleEraser::DoCancel()
       
    84 {
       
    85     switch (iState) {
       
    86     case EListingKeys:
       
    87         iTargetKeyStore->CancelList();
       
    88         break;
       
    89     case EDeletingKey:
       
    90         iKeyStore.CancelDeleteKey();
       
    91         break;
       
    92     default:
       
    93         break;
       
    94     }
       
    95     iState = EIdle;
       
    96 
       
    97     User::RequestComplete(iClientStatus, KErrCancel);
       
    98     iClientStatus = NULL;
       
    99 }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // CAdvSecSettingsSecurityModuleEraser::RunL()
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 void CAdvSecSettingsSecurityModuleEraser::RunL()
       
   106 {
       
   107     switch (iState) {
       
   108     case EListingKeys:
       
   109         DeleteFirstKeyL();
       
   110         break;
       
   111     case EDeletingKey:
       
   112         DeleteNextKeyL();
       
   113         break;
       
   114     default:
       
   115         ASSERT(EFalse);
       
   116         break;
       
   117     }
       
   118 }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // CAdvSecSettingsSecurityModuleEraser::RunError()
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 TInt CAdvSecSettingsSecurityModuleEraser::RunError(TInt aError)
       
   125 {
       
   126     User::RequestComplete(iClientStatus, aError);
       
   127     iClientStatus = NULL;
       
   128     iState = EIdle;
       
   129     return KErrNone;
       
   130 }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // CAdvSecSettingsSecurityModuleEraser::CAdvSecSettingsSecurityModuleEraser()
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 CAdvSecSettingsSecurityModuleEraser::CAdvSecSettingsSecurityModuleEraser(
       
   137     CUnifiedKeyStore &aKeyStore) : CActive(CActive::EPriorityStandard),
       
   138     iKeyStore(aKeyStore)
       
   139 {
       
   140     CActiveScheduler::Add(this);
       
   141 }
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // CAdvSecSettingsSecurityModuleEraser::ConstructL()
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 void CAdvSecSettingsSecurityModuleEraser::ConstructL()
       
   148 {
       
   149     iKeyFilter = new(ELeave) TCTKeyAttributeFilter;
       
   150     iKeyFilter->iPolicyFilter = TCTKeyAttributeFilter::EAllKeys;
       
   151 }
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // CAdvSecSettingsSecurityModuleEraser::DeleteFirstKeyL()
       
   155 // ---------------------------------------------------------------------------
       
   156 //
       
   157 void CAdvSecSettingsSecurityModuleEraser::DeleteFirstKeyL()
       
   158 {
       
   159     iKeyIndex = 0;
       
   160     DeleteOneKeyL();
       
   161 }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CAdvSecSettingsSecurityModuleEraser::DeleteOneKeyL()
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 void CAdvSecSettingsSecurityModuleEraser::DeleteOneKeyL()
       
   168 {
       
   169     if (iKeyIndex < iKeys.Count()) {
       
   170         iKeyStore.DeleteKey(iKeys[iKeyIndex]->Handle(), iStatus);
       
   171         iState = EDeletingKey;
       
   172         SetActive();
       
   173     } else {
       
   174         User::RequestComplete(iClientStatus, KErrNone);
       
   175         iClientStatus = NULL;
       
   176         iState = EIdle;
       
   177     }
       
   178 }
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // CAdvSecSettingsSecurityModuleEraser::DeleteNextKeyL()
       
   182 // ---------------------------------------------------------------------------
       
   183 //
       
   184 void CAdvSecSettingsSecurityModuleEraser::DeleteNextKeyL()
       
   185 {
       
   186     ++iKeyIndex;
       
   187     DeleteOneKeyL();
       
   188 }
       
   189