cryptoservices/certificateandkeymgmt/tcertstore/T_unifiedcertstoreactiongetcert.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     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 
       
    21 /**
       
    22  @file
       
    23 */
       
    24 
       
    25 #include "t_unifiedcertstoreactiongetcert.h"
       
    26 #include "t_input.h"
       
    27 #include "t_certstoredefs.h"
       
    28 #include "t_certstoreout.h"
       
    29 
       
    30 CTestAction* CUnifiedCertStoreGetCert::NewL(RFs& aFs, CConsoleBase& aConsole,
       
    31 											Output& aOut, 
       
    32 											const TTestActionSpec& aTestActionSpec)
       
    33 
       
    34 	{
       
    35 	CUnifiedCertStoreGetCert* self = new(ELeave) CUnifiedCertStoreGetCert(aFs, aConsole, aOut);
       
    36 	CleanupStack::PushL(self);
       
    37 	self->ConstructL(aTestActionSpec);
       
    38 	CleanupStack::Pop(self);
       
    39 	return self;
       
    40 	}
       
    41 
       
    42 
       
    43 CUnifiedCertStoreGetCert::~CUnifiedCertStoreGetCert()
       
    44 	{
       
    45 	if (iCertInfo)
       
    46 		iCertInfo->Release();
       
    47 	}
       
    48 
       
    49 CUnifiedCertStoreGetCert::CUnifiedCertStoreGetCert(RFs& aFs, CConsoleBase& aConsole,	
       
    50 												   Output& aOut)
       
    51 : CCertStoreTestAction(aFs, aConsole, aOut),
       
    52 iState(EGetCert)
       
    53 	{
       
    54 	}
       
    55 
       
    56 void CUnifiedCertStoreGetCert::ConstructL(const TTestActionSpec& aTestActionSpec)
       
    57 	{
       
    58 	CCertStoreTestAction::ConstructL(aTestActionSpec);
       
    59 	TInt pos = 0;
       
    60 	TInt err = KErrNone;
       
    61 	TLex8 lex(Input::ParseElement(aTestActionSpec.iActionBody, KTokenTypeStart, KTokenTypeEnd, pos, err));
       
    62 	if (err != KErrNone)
       
    63 		{
       
    64 		User::Leave(err);
       
    65 		}
       
    66 	TUid uid;
       
    67 	lex.Val(uid.iUid); // check for error
       
    68 
       
    69 	TInt token;
       
    70 	lex = TLex8(Input::ParseElement(aTestActionSpec.iActionBody, KTokenStart, KTokenEnd, pos, err));
       
    71 	lex.Val(token);
       
    72 
       
    73 	TInt object;
       
    74 	lex = TLex8(Input::ParseElement(aTestActionSpec.iActionBody, KObjectStart, KObjectEnd, pos, err));
       
    75 	lex.Val(object);
       
    76 
       
    77 	iHandle = TCTTokenObjectHandle(TCTTokenHandle(uid, token), object);
       
    78 
       
    79 	pos = 0;
       
    80 
       
    81 	HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
       
    82 	TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
       
    83 	Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
       
    84 	CleanupStack::PopAndDestroy(result);
       
    85 	}
       
    86 
       
    87 void CUnifiedCertStoreGetCert::PerformAction(TRequestStatus& aStatus)
       
    88 	{
       
    89 	switch (iState)
       
    90 		{
       
    91 	case EGetCert:
       
    92 		CertStore().GetCert(iCertInfo, iHandle, aStatus);
       
    93 		iState = EFinished;
       
    94 		break;
       
    95 
       
    96 	case EFinished:
       
    97 		{
       
    98 		if (aStatus == iExpectedResult)
       
    99 			{
       
   100 			iResult = ETrue;
       
   101 			}
       
   102 		else
       
   103 			{
       
   104 			iResult = EFalse;
       
   105 			}
       
   106 		iFinished = ETrue;
       
   107 		TRequestStatus* status = &aStatus;
       
   108 		User::RequestComplete(status, KErrNone);
       
   109 		break;
       
   110 		}
       
   111 	
       
   112 	// The initial state is set to EGetCert and the default case would
       
   113 	// never be reached.
       
   114 	default:
       
   115 		iResult = EFalse;
       
   116 		iFinished = ETrue;
       
   117 		TRequestStatus* status = &aStatus;
       
   118 		User::RequestComplete(status, KErrNotSupported);
       
   119 		break;
       
   120 		}
       
   121 	}
       
   122 
       
   123 void CUnifiedCertStoreGetCert::PerformCancel()
       
   124 	{
       
   125 	}
       
   126 
       
   127 void CUnifiedCertStoreGetCert::Reset()
       
   128 	{
       
   129 	__ASSERT_DEBUG(EFalse, User::Panic(_L("CUnifiedCertStoreGetCert::Reset()"), 1));
       
   130 	}
       
   131 
       
   132 void CUnifiedCertStoreGetCert::DoReportAction()
       
   133 	{
       
   134 	//iOut.writeString(_L("Setting trust settings..."));
       
   135 	iOut.writeHex(iHandle.iTokenHandle.iTokenTypeUid.iUid);
       
   136 	//iOut.writeNewLine();
       
   137 	//iOut.writeString(_L("\tLabel = "));
       
   138 //	iOut.writeString(iLabel);
       
   139 //	iOut.writeNewLine();
       
   140 	//iOut.writeString(_L("\tTrusters = "));
       
   141 	//TInt count = iTrusters->Count();
       
   142 	//for (TInt i = 0; i < count; i++)
       
   143 	//	{
       
   144 	//	iOut.writeNum((*iTrusters)[i].iUid);
       
   145 	//	iOut.writeString(_L(" "));
       
   146 	//	}
       
   147 	//iOut.writeNewLine();
       
   148 	//iOut.writeNewLine();
       
   149 	}	
       
   150 
       
   151 void CUnifiedCertStoreGetCert::DoCheckResult(TInt /*aError*/)
       
   152 	{
       
   153 	}