cryptoservices/certificateandkeymgmt/twtlscert/CorruptionTest.cpp
branchRCL_3
changeset 41 9b5a3a9fddf8
parent 8 35751d3474b7
equal deleted inserted replaced
37:721a5e5fe251 41:9b5a3a9fddf8
    25 
    25 
    26 #include <asymmetric.h>
    26 #include <asymmetric.h>
    27 
    27 
    28 #include <bigint.h>
    28 #include <bigint.h>
    29 #include <hash.h>
    29 #include <hash.h>
       
    30 #include <securityerr.h>
    30 
    31 
    31 TInt CCorruptionTest::nInstances = 0;
    32 TInt CCorruptionTest::nInstances = 0;
    32 _LIT(KCorruptLogFile, "WTLSCERTCorruptLog.txt");
    33 _LIT(KCorruptLogFile, "WTLSCERTCorruptLog.txt");
    33 _LIT(KPathStart, "<path>");
    34 _LIT(KPathStart, "<path>");
    34 _LIT(KIterationsStart, "<iterations>");
    35 _LIT(KIterationsStart, "<iterations>");
   170 			{
   171 			{
   171 				//randomness
   172 				//randomness
   172 			HBufC8* rand = HBufC8::NewLC(5);
   173 			HBufC8* rand = HBufC8::NewLC(5);
   173 			TPtr8 pRand = rand->Des();
   174 			TPtr8 pRand = rand->Des();
   174 			pRand.SetLength(5);
   175 			pRand.SetLength(5);
   175 			random->GenerateBytesL(pRand);
   176 			TRAPD(err, random->GenerateBytesL(pRand));
       
   177 			if((err != KErrNone) && (err != KErrNotSecure))
       
   178 				User::Leave(err);
   176 			TUint num = 0;
   179 			TUint num = 0;
   177 			for (TInt k = 0; k < 4 ; k++)
   180 			for (TInt k = 0; k < 4 ; k++)
   178 				{
   181 				{
   179 				num<<=8;
   182 				num<<=8;
   180 				num+=pRand[k];
   183 				num+=pRand[k];
   195 			iCorruptOut->writeString(_L("o:"));
   198 			iCorruptOut->writeString(_L("o:"));
   196 			iCorruptOut->writeOctetString(pOctsBuf);
   199 			iCorruptOut->writeOctetString(pOctsBuf);
   197 			iCorruptOut->writeNewLine();
   200 			iCorruptOut->writeNewLine();
   198 			//try to make corrupt cert
   201 			//try to make corrupt cert
   199 			CWTLSCertificate* cert = NULL;
   202 			CWTLSCertificate* cert = NULL;
   200 			TRAPD(err, cert = CWTLSCertificate::NewL(pBuf));
   203 			TRAP(err, cert = CWTLSCertificate::NewL(pBuf));
   201 			CleanupStack::PushL(cert);
   204 			CleanupStack::PushL(cert);
   202 			if (err == KErrNone)
   205 			if (err == KErrNone)
   203 				{
   206 				{
   204 				TRAP_IGNORE(iWriter->WriteCert(*cert));
   207 				TRAP_IGNORE(iWriter->WriteCert(*cert));
   205 				TBool res = EFalse;;
   208 				TBool res = EFalse;;