Update contrib.
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
 
     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".
 
     9 * Initial Contributors:
 
    10 * Nokia Corporation - initial contribution.
 
    15 * Tests generating a key.
 
    24 #include "kmslddtest.h"
 
    27 void TestGenerateSingleKey(TInt aLength, RProcess aOwner, TKeyHandle& aHandle, TInt aExpectedResult)
 
    29 	Generate a key with the global channel object, and test the LDD completes the request
 
    30 	with the expected result.
 
    32 	@param	aLength			Key length in bytes.
 
    33 	@param	aOwner			Process which will own the newly-created key.
 
    34 	@param	aHandle			On success this will identify the newly-created key.  Its
 
    35 							value is undefined on failure.
 
    36 	@param	aExpectedResult	Expected Symbian OS error code with which the LDD will complete
 
    41 	KmsChannel.GenerateKey(aLength, aOwner, aHandle, rs);
 
    42 	User::WaitForRequest(rs);
 
    43 	test(rs == aExpectedResult);
 
    46 void TestGenerateSingleKey(TInt aLength, TKeyHandle& aHandle, TInt aExpectedResult)
 
    48 	Generate a key with the global channel object, using the current process as the owner.
 
    50 	@param	aLength			Key length in bytes.
 
    51 	@param	aHandle			On success this will identify the newly-created key.  Its
 
    52 							value is undefined on failure.
 
    53 	@param	aExpectedResult	Expected Symbian OS error code with which the LDD will complete
 
    57 	TestGenerateSingleKey(aLength, CurrentProcess, aHandle, aExpectedResult);
 
    60 void RKmsChannelTest::TestInvalidGenArgsDescriptor(TRequestStatus& aStatus)
 
    62 	Supply an invalid TGenKeyArgs descriptor to the driver to ensure the current
 
    63 	thread is panicked as expected.
 
    65 	@param	aStatus			This object is passed to the driver, but it should not
 
    66 							be used because the thread should be panicked.
 
    67 							It is supplied to this function as a convenience so this
 
    68 							function does not have to declare its own instance.
 
    71 	DoRequest(KmsLddImpl::EGenerateKey, aStatus, NULL);
 
    74 static void TestGenerateKeyBadHandleAddr(RKmsChannel& aChannel, TRequestStatus& aStatus)
 
    76 	Supply an invalid key handle to the LDD when generating the key, to ensure the
 
    77 	driver panicks the current thread.
 
    79 	@param	aChannel		Custom channel which is used to send generate request to
 
    81 	@param	aStatus			This object is passed to the driver, but it should not
 
    82 							be used because the thread should be panicked.
 
    83 							It is supplied to this function as a convenience so this
 
    84 							function does not have to declare its own instance.
 
    87 	TKeyHandle* ph = 0;		// in two stages to avoid RVCT #284-D: NULL reference is not allowed
 
    88 	aChannel.GenerateKey(2, CurrentProcess, *ph, aStatus);
 
    91 static void GenKeyOomAlloc(TRequestStatus& aStatus)
 
    93 	Attempt to generate a key.  This function is called in OOM to test the
 
    94 	driver cleans up on failure.
 
    96 	@param	aStatus			On return, the caller will wait on this object.
 
    97 							This is provided to save the function from having
 
    98 							to declare an instance, wait on it, and then return
 
   103 	KmsChannel.GenerateKey(12, CurrentProcess, GenKeyHandle0, aStatus);
 
   106 static void GenKeyOomFree()
 
   108 	Clean up resources allocated for GenKeyOomAlloc.  This is called after the
 
   114 	TestDeleteSingleKey(GenKeyHandle0, KErrNone);
 
   118 void TestGenerateKey()
 
   120 	Test generating keys, successfully and otherwise.  See in-function
 
   121 	comments for specific test cases.
 
   124 	test.Start(_L(" @SYMTestCaseID:SEC-CRYPTOSPI-GENERATE-0001 TestGenerateKey "));
 
   126 	TestGenerateSingleKey(1, GenKeyHandle0, KErrNone);
 
   127 	TestGenerateSingleKey(13, GenKeyHandle1, KErrNone);
 
   129 	// error case - invalid length
 
   130 	TestGenerateSingleKey(0, GenKeyHandle0, KErrArgument);
 
   132 	// error case - invalid arg descriptor
 
   133 	TestPanicTestChannel(&RKmsChannelTest::TestInvalidGenArgsDescriptor, KmsLddImpl::EGenKeyBadArgDescriptor);
 
   135 	// error case - invalid handle
 
   136 	TestPanic(TestGenerateKeyBadHandleAddr, KmsLddImpl::EGenKeyInvalidHandleAddr);
 
   139 	TestDeleteSingleKey(GenKeyHandle0, KErrNone);
 
   140 	RunOomTest(GenKeyOomAlloc, GenKeyOomFree);