os/security/crypto/weakcryptospi/test/tbigint/tprimegen.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/crypto/weakcryptospi/test/tbigint/tprimegen.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,103 @@
     1.4 +/*
     1.5 +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include "tprimegen.h"
    1.23 +#include "t_input.h"
    1.24 +#include <bigint.h>
    1.25 +#include "tutils.h"
    1.26 +#include <random.h>
    1.27 +
    1.28 +CTestAction* CPrimeGen::NewL(RFs& aFs, CConsoleBase& aConsole, 
    1.29 +	Output& aOut, const TTestActionSpec& aTestActionSpec)
    1.30 +	{
    1.31 +	CTestAction* self = CPrimeGen::NewLC(aFs, aConsole,
    1.32 +		aOut, aTestActionSpec);
    1.33 +	CleanupStack::Pop();
    1.34 +	return self;
    1.35 +	}
    1.36 +
    1.37 +CTestAction* CPrimeGen::NewLC(RFs& aFs, CConsoleBase& aConsole, 
    1.38 +	Output& aOut, const TTestActionSpec& aTestActionSpec)
    1.39 +	{
    1.40 +	CPrimeGen* self = new(ELeave) CPrimeGen(aFs, aConsole, aOut);
    1.41 +	CleanupStack::PushL(self);
    1.42 +	self->ConstructL(aTestActionSpec);
    1.43 +	return self;
    1.44 +	}
    1.45 +
    1.46 +CPrimeGen::~CPrimeGen()
    1.47 +	{
    1.48 +	delete iBody;
    1.49 +	}
    1.50 +
    1.51 +CPrimeGen::CPrimeGen(RFs& aFs, CConsoleBase& aConsole, 
    1.52 +	Output& aOut) : CTestAction(aConsole, aOut), iFs(aFs)
    1.53 +	{
    1.54 +	}
    1.55 +
    1.56 +void CPrimeGen::ConstructL(const TTestActionSpec& aTestActionSpec)
    1.57 +	{
    1.58 +	CTestAction::ConstructL(aTestActionSpec);
    1.59 +	iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length());
    1.60 +	iBody->Des().Copy(aTestActionSpec.iActionBody);
    1.61 +
    1.62 +	iBits = Input::ParseIntElement(*iBody, _L8("<bits>"), _L8("</bits>"));
    1.63 +	}
    1.64 +
    1.65 +void CPrimeGen::DoPerformPrerequisite(TRequestStatus& aStatus)
    1.66 +	{
    1.67 +	TRequestStatus* status = &aStatus;
    1.68 +	User::RequestComplete(status, KErrNone);
    1.69 +	iActionState = CTestAction::EAction;
    1.70 +	}
    1.71 +
    1.72 +void CPrimeGen::DoPerformPostrequisite(TRequestStatus& aStatus)
    1.73 +	{
    1.74 +	TRequestStatus* status = &aStatus;
    1.75 +	iFinished = ETrue;
    1.76 +	User::RequestComplete(status, KErrNone);
    1.77 +	}
    1.78 +
    1.79 +void CPrimeGen::DoReportAction(void)
    1.80 +	{
    1.81 +	}
    1.82 +
    1.83 +void CPrimeGen::DoCheckResult(TInt)
    1.84 +	{
    1.85 +	}
    1.86 +
    1.87 +void CPrimeGen::PerformAction(TRequestStatus& aStatus)
    1.88 +	{
    1.89 +	__UHEAP_MARK;
    1.90 +	TRequestStatus* status = &aStatus;
    1.91 +	iResult = EFalse;
    1.92 +
    1.93 +	RInteger prime = RInteger::NewPrimeL(iBits, TInteger::ETopBitSet);
    1.94 +	CleanupStack::PushL(prime);
    1.95 +	if(prime.BitCount() == iBits && prime.IsPrimeL())
    1.96 +		{
    1.97 +		iResult = ETrue;
    1.98 +		}
    1.99 +
   1.100 +	CleanupStack::PopAndDestroy(&prime);
   1.101 +
   1.102 +	User::RequestComplete(status, KErrNone);
   1.103 +	iActionState = CTestAction::EPostrequisite;
   1.104 +	__UHEAP_MARKEND;
   1.105 +	}
   1.106 +