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