⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interfaceclient.cpp

📁 ecom symbian os application development
💻 CPP
字号:
// InterfaceClient.cpp

#include <e32base.h>
//#include <badesca.h>
#include <interface.h>

// Utility clean up function
void CleanupEComArray(TAny* aArray);

void TestEncryptL(CCryptoInterface& aCrypto)
{
	_LIT8(KPlaintext, "Clanger");
	TBuf8<10> cipherText;
	aCrypto.EncryptL(KPlaintext, KNullDesC8, cipherText, CCryptoInterface::E3DES);
	ASSERT(cipherText==KPlaintext);
}

void TestDecryptL(CCryptoInterface& aCrypto)
{
	_LIT8(KPlaintext, "Clanger");	
	TBuf8<10> cipherText;
	aCrypto.DecryptL(KPlaintext, KNullDesC8, cipherText, CCryptoInterface::E3DES);
	ASSERT(cipherText==KPlaintext);
}

void GetDefaultCryptoL()
	{// Get the default implementation and call its method
	CCryptoInterface* crypto = CCryptoInterface::NewL();
	CleanupStack::PushL(crypto);
	TestEncryptL(*crypto);
	TestDecryptL(*crypto);
	CleanupStack::PopAndDestroy(crypto);
	}

void GetSpecifiedCryptoL()
	{// Get the implementation that has a data identifier HW
	_LIT8(KSpec,"HW");
	CCryptoInterface* crypto = CCryptoInterface::NewL(KSpec);
	CleanupStack::PushL(crypto);
	TestEncryptL(*crypto);
	TestDecryptL(*crypto);
	CleanupStack::PopAndDestroy(crypto);
	}

void GetAllCryptoL()
	{// Read info about all implementations into infoArray
	RImplInfoPtrArray infoArray;
	// Note that a special cleanup function is required to reset and destroy
	// all items in the array, and then close it.
	TCleanupItem cleanup(CleanupEComArray, &infoArray);
	CleanupStack::PushL(cleanup);
	CCryptoInterface::ListImplementationsL(infoArray);

	// Loop through each info for each implementation
	// and create and use each in turn
	CCryptoInterface* crypto = NULL;
	for (TInt i=0; i< infoArray.Count(); i++)
		{
		// Slice off first sub-section in the data section
		TPtrC8 type = infoArray[i]->DataType();
		// Create object of type and call its function
		crypto = CCryptoInterface::NewL(type);
		CleanupStack::PushL(crypto);		
		TestEncryptL(*crypto);
		TestDecryptL(*crypto);
		CleanupStack::PopAndDestroy(crypto);
		}
	
	// Clean up
	CleanupStack::PopAndDestroy(&infoArray); //infoArray, results in a call to CleanupEComArray
	}

// CleanupEComArray function is used for cleanup support of locally declared arrays
void CleanupEComArray(TAny* aArray)
	{
	(static_cast<RImplInfoPtrArray*> (aArray))->ResetAndDestroy();
	(static_cast<RImplInfoPtrArray*> (aArray))->Close();
	}

// do the example
LOCAL_C void doExampleL()
    {
	GetDefaultCryptoL();
	GetSpecifiedCryptoL();
	GetAllCryptoL();
	}

GLDEF_C TInt E32Main() 
    {
	__UHEAP_MARK;
	CTrapCleanup* cleanup=CTrapCleanup::New(); 
	TRAPD(error, doExampleL()); 
	__ASSERT_ALWAYS((KErrNone==error),User::Panic(_L("interfaceclient"), error));
	delete cleanup; 
	__UHEAP_MARKEND;
	return 0; 
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -