os/security/crypto/weakcrypto/test/tasymmetric/tvectortest.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 1998-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 #include "tvectortest.h"
    20 #include <e32twin.h>
    21 #include "t_input.h"
    22 #include <asymmetric.h>
    23 #include <random.h>
    24 #include <padding.h>
    25 #include "tvectorutils.h"
    26 #include "performancetest.h"
    27 #include <securityerr.h>
    28 
    29 _LIT8(KKeyBitsStart, "<keybits>");
    30 _LIT8(KKeyBitsEnd, "</keybits>");
    31 _LIT8(KResultStart, "<result>");
    32 _LIT8(KResultEnd, "</result>");
    33 
    34 ////////////////////////////////////////////////////////////////////////////////
    35 // CVectorTest 
    36 ////////////////////////////////////////////////////////////////////////////////
    37 
    38 CVectorTest::CVectorTest(CConsoleBase& aConsole, Output& aOut)
    39     : CTestAction(aConsole, aOut), iPerfTestIterations(100)
    40     {
    41     }
    42 
    43 CVectorTest::~CVectorTest()
    44     {
    45     }
    46 
    47 void CVectorTest::ConstructL(const TTestActionSpec& aTestActionSpec)
    48 {
    49 	CTestAction::ConstructL(aTestActionSpec);
    50 
    51 	if (CPerformance::PerformanceTester()->IsTestingPerformance())
    52 	{//	Number of test iterations
    53 		TPtrC8 itsPtr = Input::ParseElement(aTestActionSpec.iActionBody, KIterationsStart, KIterationsEnd);
    54 		if (itsPtr!=KNullDesC8)
    55 		{
    56 			TLex8 lex;
    57 			lex.Assign(itsPtr);
    58 			User::LeaveIfError(lex.Val(iPerfTestIterations));
    59 			if (iPerfTestIterations > KMaxIterations)
    60 				User::Panic(_L("AsymmetricPerformance.exe"), KErrArgument);
    61 		}
    62 	}
    63 
    64 	TPtrC8 keyBitsPtr = Input::ParseElement(aTestActionSpec.iActionBody, KKeyBitsStart, KKeyBitsEnd); 
    65 	if (keyBitsPtr!=KNullDesC8)
    66 	{
    67 		TLex8 lex;
    68 		lex.Assign(keyBitsPtr);
    69 		User::LeaveIfError(lex.Val(iKeyBits));
    70 	}
    71 
    72     TPtrC8 resultIn = Input::ParseElement(aTestActionSpec.iActionResult, KResultStart, KResultEnd);
    73     iExpectedResult = VectorUtils::ParseBoolL(resultIn);
    74 }
    75 
    76 void CVectorTest::PerformAction(TRequestStatus& aStatus)
    77 {
    78 	TRequestStatus* status = &aStatus;
    79 	
    80 	if (CPerformance::PerformanceTester()->IsTestingPerformance())
    81 	{
    82 		iConsole.Printf(_L(">"));	//	Indicates start of test
    83 		TRAP(iActionResult, DoPerformanceTestActionL());
    84 	}
    85 	else
    86 	{
    87 		TRAP(iActionResult, DoPerformActionL());
    88 	}
    89 	
    90 	if (iActionResult==KErrNoMemory)
    91 		{
    92 		User::Leave(iActionResult);	//	For OOM testing
    93 		}
    94 	if (iActionResult==KErrKeyNotWeakEnough)
    95 		{
    96 		iResult = ETrue;
    97 		iConsole.Printf(_L("Crypto libraries returned KErrKeyNotWeakEnough!  Passing test automatically.\n\r"));
    98 		iOut.writeString(_L("Crypto libraries returned KErrKeyNotWeakEnough!  Passing test automatically.\n\r"));
    99 		}
   100 
   101 	User::RequestComplete(status, iActionResult);
   102 
   103 	iActionState = CTestAction::EPostrequisite;
   104 
   105 }
   106 
   107 void CVectorTest::DoPerformPrerequisite(TRequestStatus& aStatus)
   108 	{
   109 	TRequestStatus* status = &aStatus;
   110 	User::RequestComplete(status, KErrNone);
   111 	iActionState = CTestAction::EAction;
   112 	}
   113 
   114 void CVectorTest::DoPerformPostrequisite(TRequestStatus& aStatus)
   115 	{
   116 	TRequestStatus* status = &aStatus;
   117 	iFinished = ETrue;
   118 	User::RequestComplete(status, KErrNone);
   119 	}
   120 
   121 void CVectorTest::DoReportAction(void)
   122 	{
   123 	}
   124 
   125 void CVectorTest::DoCheckResult(TInt /*aError*/)
   126 	{
   127 //	If using Keith's fixed up testframework for testing failures, iResult will 
   128 //	have already been corrected for a deliberate fail result.
   129 //	If not using Keith's testframework iResult is still a fail result at this
   130 //	point, so now's the time to adjust for deliberate failure.
   131 
   132 	if (!iResult)
   133 		iResult = (iResult && iExpectedResult) || (!iResult && !iExpectedResult);
   134 
   135 	if (iResult)
   136 		iConsole.Printf(_L("."));
   137 	else
   138 		iConsole.Printf(_L("X"));
   139 	}