os/security/crypto/weakcryptospi/test/tbigint/tutils.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2002-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 "tutils.h"
    20 #include <bigint.h>
    21 #include "t_output.h"
    22 
    23 void Utils::DumpInteger(Output& aOut, const TDesC& aDesc, 
    24 	const RInteger& aThat)
    25 	{
    26 	aOut.writeString(aDesc);
    27 	HBufC8* buf = aThat.BufferLC();
    28 	aOut.writeOctetString(*buf);
    29 	aOut.writeNewLine();
    30 	CleanupStack::PopAndDestroy(buf);
    31 	}
    32 
    33 
    34 /* CRandomSetSource */
    35 CRandomSetSource::CRandomSetSource(const TDesC8& aSource)
    36     {
    37 	SetSource(aSource);
    38     }
    39 
    40 void CRandomSetSource::GenerateBytesL(TDes8& aDest)
    41     {
    42 	TInt i=0;
    43 	//Reverse the string by bytes up to the point of the end of the given string
    44 	//of "random" bytes.
    45     for (i=0; iCounter >= 0 && i< aDest.Length(); ++i,--iCounter)
    46         {
    47         aDest[i] = iValue[iCounter];
    48         }
    49 	//Then fill the remaining (if any) bytes in aDest with 0's.  This is all to
    50 	//allow the stuff to work with bigint style integers; we're writing straight
    51 	//into a RInteger.Ptr() here
    52 	for(;i<aDest.Length(); ++i)
    53 		{
    54         aDest[i] = 0x00;
    55 		}
    56     }
    57 
    58 void CRandomSetSource::SetSource(const TDesC8& aSource)
    59 	{
    60 	iValue.Set(aSource);
    61 	Reset();
    62 	}
    63 
    64 void CRandomSetSource::Reset(void) 
    65 	{
    66 	iCounter = iValue.Length() - 1;
    67 	}