os/security/cryptoservices/certificateandkeymgmt/tcertstore/T_certstoreactionshandle.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2005-2009 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 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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 /**
    20  @file
    21 */
    22 
    23 #include "t_certstoreactionshandle.h"
    24 #include "t_input.h"
    25 #include "t_certstoredefs.h"
    26 #include "t_certstoreout.h"
    27 #include <ccertattributefilter.h>
    28 
    29 CTestAction* CCertStoreHandle::NewL(RFs& aFs, CConsoleBase& aConsole,
    30 									Output& aOut, 
    31 									const TTestActionSpec& aTestActionSpec)
    32 	{
    33 	CCertStoreHandle* self = new(ELeave) CCertStoreHandle(aFs, aConsole, aOut);
    34 	CleanupStack::PushL(self);
    35 	self->ConstructL(aTestActionSpec);
    36 	CleanupStack::Pop(self);
    37 	return self;
    38 	}
    39 
    40 
    41 CCertStoreHandle::~CCertStoreHandle()
    42 	{
    43 	delete iFilter;
    44 	iCertInfos.Close();
    45 	}
    46 
    47 CCertStoreHandle::CCertStoreHandle(RFs& aFs, CConsoleBase& aConsole,	
    48 								   Output& aOut)
    49 : CCertStoreTestAction(aFs, aConsole, aOut), iState(EList)
    50 	{
    51 	}
    52 
    53 void CCertStoreHandle::ConstructL(const TTestActionSpec& aTestActionSpec)
    54 	{
    55 	CCertStoreTestAction::ConstructL(aTestActionSpec);
    56 	// Creates a default filter
    57 	iFilter = CCertAttributeFilter::NewL();
    58 
    59 	TInt pos = 0;
    60 	TInt err = KErrNone;
    61 	iLabel.Copy(Input::ParseElement(aTestActionSpec.iActionBody, KCertLabelStart, KCertLabelEnd, pos, err));
    62 	
    63 	// set the expected result
    64 	HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
    65 	TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
    66 	Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
    67 	CleanupStack::PopAndDestroy(result);
    68 	
    69 	}
    70 
    71 void CCertStoreHandle::PerformAction(TRequestStatus& aStatus)
    72 	{
    73 	switch (iState)
    74 		{
    75 	case EList:
    76 		// Get the list of all certificates
    77 		CertStore().List(iCertInfos, *iFilter, aStatus);
    78 		iState = EHandle;
    79 		break;
    80 
    81 	case EHandle:
    82 		{
    83 		// Find the certificate we want
    84 		TInt end =  iCertInfos.Count();
    85 		for (TInt i = 0; i < end; i++)
    86 			{
    87 			if (iCertInfos[i]->Label() == iLabel)
    88 				{
    89 				iHandle = iCertInfos[i]->Handle();
    90 				break;
    91 				}
    92 			}
    93 		if (aStatus == iExpectedResult)
    94 			{
    95 			iResult = ETrue;
    96 			}
    97 		else
    98 			{
    99 			iResult = EFalse;
   100 			}
   101 		if (aStatus == KErrNoMemory)
   102 			{	
   103 			}
   104 		else
   105 			{
   106 			iFinished = ETrue;
   107 			}
   108 		TRequestStatus* status = &aStatus;
   109 		User::RequestComplete(status, KErrNone);
   110 		break;
   111 		}
   112 	
   113 	// The initial state is set to EList and the default case would
   114 	// never be reached.
   115 	default:
   116 		iResult = EFalse;
   117 		iFinished = ETrue;
   118 		TRequestStatus* status = &aStatus;
   119 		User::RequestComplete(status, KErrNotSupported);
   120 		break;
   121 		}
   122 	}
   123 
   124 void CCertStoreHandle::PerformCancel()
   125 	{
   126 	}
   127 
   128 void CCertStoreHandle::Reset()
   129 	{
   130 	__ASSERT_DEBUG(EFalse, User::Panic(_L("CCertStoreHandle::Reset()"), 1));
   131 	}
   132 
   133 void CCertStoreHandle::DoReportAction()
   134 	{
   135 	iOut.writeString(_L("\tLabel = "));
   136 	iOut.writeString(iLabel);
   137 	iOut.writeNewLine();
   138 	}	
   139 
   140 void CCertStoreHandle::DoCheckResult(TInt aError)
   141 	{
   142 	if (iFinished)
   143 		{
   144 		if (aError == KErrNone)
   145 			{
   146 			iOut.writeHex(iHandle.iTokenHandle.iTokenTypeUid.iUid);
   147 			iOut.writeHex(iHandle.iTokenHandle.iTokenId);
   148 			iOut.writeHex(iHandle.iObjectId);
   149 			}
   150 		}
   151 	}