os/security/cryptoservices/certificateandkeymgmt/tasn1/tasn1normaltest.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 * ASN1TestAction.cpp: implementation of the CASN1NormalTest class.
    16 *
    17 */
    18 
    19 
    20 /**
    21  @file
    22 */
    23 
    24 #include "tasn1normaltest.h"
    25 #include "testnull.h"
    26 #include "testboolean.h"
    27 #include "testint.h"
    28 #include "testbigint.h"
    29 #include "testoctetstr.h"
    30 #include "testoid.h"
    31 #include "testinvalidoid.h"
    32 #include "testgeneralizedtime.h"
    33 #include "testsequence.h"
    34 #include "testexplicittag.h"
    35 #include "testimplicittag.h"
    36 #include "testoutput.h"
    37 #include "testbitstr.h"
    38 #include "t_input.h"
    39 
    40 //////////////////////////////////////////////////////////////////////
    41 // Construction/Destruction
    42 //////////////////////////////////////////////////////////////////////
    43 TInt CASN1NormalTest::iReportCount = 1;
    44 
    45 _LIT(KASN1TestStart, "<asn1test>");
    46 _LIT(KTypeStart, "<type>");
    47 _LIT(KIntType, "int");
    48 _LIT(KBigIntType, "bigint");
    49 _LIT(KBooleanType, "boolean");
    50 _LIT(KNullType, "null");
    51 _LIT(KExplicitTagType, "explicittag");
    52 _LIT(KImplicitTagType, "implicittag");
    53 _LIT(KGeneralizedTimeType, "generalizedtime");
    54 _LIT(KOctetStringType, "octetstring");
    55 _LIT(KObjectIDType, "objectid");
    56 _LIT(KInvaidObjectIDType, "invalidobjectid");
    57 _LIT(KSequenceType, "sequence");
    58 _LIT(KOutputType, "output");
    59 _LIT(KBitStrType, "bitstring");
    60 
    61 CASN1NormalTest::~CASN1NormalTest()
    62 	{
    63 		delete iTestType;
    64 	}
    65 
    66 CASN1NormalTest::CASN1NormalTest(RFs& /*aFs*/, 
    67 								 CConsoleBase& aConsole,
    68 								 Output& aOut)
    69 : CTestAction(aConsole, aOut), iTestType(0), iPercentReported(-1), iReportNumber(iReportCount++) 
    70 	{
    71 	}
    72 
    73 CTestAction* CASN1NormalTest::NewL(RFs& aFs,
    74 										 CConsoleBase& aConsole,
    75 										 Output& aOut, 
    76 										 const TTestActionSpec& aTestActionSpec)
    77 	{
    78 	CTestAction* self = CASN1NormalTest::NewLC(aFs, aConsole,
    79 		aOut,  aTestActionSpec);
    80 	CleanupStack::Pop(self);
    81 	return self;
    82 	}
    83 
    84 CTestAction* CASN1NormalTest::NewLC(RFs& aFs,
    85 										  CConsoleBase& aConsole,
    86 										  Output& aOut, 
    87 										  const TTestActionSpec& aTestActionSpec)
    88 	{
    89 	CASN1NormalTest* self = new(ELeave) CASN1NormalTest(aFs, aConsole, aOut);
    90 	CleanupStack::PushL(self);
    91 	self->ConstructL(aTestActionSpec);
    92 	return self;
    93 	}
    94 
    95 
    96 void CASN1NormalTest::ConstructL(const TTestActionSpec& aTestActionSpec)
    97 	{
    98 	CTestAction::ConstructL(aTestActionSpec);
    99 	HBufC* body = HBufC::NewLC(aTestActionSpec.iActionBody.Length());
   100 
   101 	body->Des().Copy(aTestActionSpec.iActionBody);
   102 	TPtrC rootCert = Input::ParseElement(*body, KASN1TestStart);
   103 	TPtrC iType = Input::ParseElement(rootCert, KTypeStart);
   104 	
   105 	// constucts correct class depending on string
   106 	if(iType.CompareF(KIntType)==0)
   107 		iTestType = CTestInt::NewL(*this);
   108 	else if(iType.CompareF(KBigIntType)==0)
   109 		iTestType = CTestBigInt::NewL(*this);
   110 	else if(iType.CompareF(KBooleanType)==0)
   111 		iTestType = CTestBoolean::NewL(*this);
   112 	else if(iType.CompareF(KNullType)==0)
   113 		iTestType = CTestNull::NewL(*this);
   114 	else if(iType.CompareF(KExplicitTagType)==0)
   115 		iTestType = CTestExplicitTag::NewL(*this);
   116 	else if(iType.CompareF(KImplicitTagType)==0)
   117 		iTestType = CTestImplicitTag::NewL(*this);
   118 	else if(iType.CompareF(KGeneralizedTimeType)==0)
   119 		iTestType = CTestGeneralizedTime::NewL(*this);
   120 	else if(iType.CompareF(KOctetStringType)==0)
   121 		iTestType = CTestOctetString::NewL(*this);
   122 	else if(iType.CompareF(KObjectIDType)==0)
   123 		iTestType = CTestOID::NewL(*this);
   124 	else if(iType.CompareF(KSequenceType)==0)
   125 		iTestType = CTestSequence::NewL(*this);
   126 	else if(iType.CompareF(KOutputType)==0)
   127 		iTestType = CTestOutput::NewL(*this);
   128 	else if(iType.CompareF(KBitStrType)==0)
   129 		iTestType = CTestBitStr::NewL(*this);
   130 	else if(iType.CompareF(KInvaidObjectIDType)==0)
   131 		iTestType = CTestInvalidOID::NewL(*this);
   132 
   133 	if(iTestType)
   134 		SetScriptError(iTestType->ConstructL(aTestActionSpec), iTestType->iSyntaxErrorDescription);
   135 
   136 	CleanupStack::PopAndDestroy(); // body
   137 	}
   138 
   139 void CASN1NormalTest::PerformAction(TRequestStatus& aStatus)
   140 	{
   141 	TRAPD(err, iResult = iTestType->PerformTestsL(iConsole));
   142 	if (err==KErrNoMemory)
   143 		User::Leave(err);
   144 	else
   145 		{
   146 		iActionState = EPostrequisite;
   147 		TRequestStatus* status = &aStatus;
   148 		User::RequestComplete(status, err);
   149 		}
   150 	}
   151 
   152 
   153 void CASN1NormalTest::ReportProgressL(const TInt aError, const TInt aCount, const TInt aMax)
   154 	{
   155 	if(aMax == 0) return;
   156 	TInt newPercentage = aCount * 100 / aMax;
   157 	
   158 	if (newPercentage > iPercentReported && iResult == 0)
   159 		{
   160 		iPercentReported = newPercentage;
   161 		
   162 		iConsole.Printf(_L(" %d"), iPercentReported);
   163 
   164 		if (iPercentReported == 100)
   165 			{
   166 			iConsole.Write(_L("%"));
   167 			iConsole.Write(_L(" Completed:\n"));
   168 			CheckResult(aError);
   169 			iPercentReported = -1;
   170 			}
   171 		}
   172 	if(aError != 0)
   173 		{
   174 		iFinished = ETrue;
   175 		iResult = EFalse;
   176 		}
   177 	}
   178 
   179 void CASN1NormalTest::DoCheckResult(TInt aError)
   180 	{
   181 	if(aError == 0 && !iFinished)
   182 		{
   183 		iFinished = ETrue;
   184 		iResult = ETrue;
   185 		}
   186 	}
   187 
   188 
   189 void CASN1NormalTest::DoReportAction()
   190 	{
   191 	HBufC *tmp = HBufC::NewMaxLC(iNameInfo->Length());
   192 
   193 	// converts name to unicode (if necessary) and dumps it out to screen
   194  	tmp->Des().Copy(*iNameInfo);
   195 	iConsole.Printf(_L("\n"));
   196 	iConsole.Printf(_L("Report %d - "), iReportNumber);
   197 	iConsole.Write(*tmp);
   198 	iConsole.Printf(_L("\n"));
   199 
   200 	CleanupStack::PopAndDestroy(); // tmp
   201 	}
   202 
   203 TBool CASN1NormalTest::TestResult(TInt /*aError*/)
   204 	{
   205 	return 0;
   206 	}
   207 	
   208 void CASN1NormalTest::PerformCancel()
   209 	{
   210 	}
   211 	
   212 void CASN1NormalTest::Reset()
   213 	{
   214 	}
   215