?? interfaceclient.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 + -