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.
24 #include "dumpprocessor.h"
26 #include <cryptospi/cryptospidef.h>
28 #include <cryptospi/cryptocharacteristics.h>
29 #include <cryptospi/cryptospistateapi.h>
31 using namespace CryptoSpi;
33 //Copy-right, Tool name format
34 _LIT(KShortName, "Dump CryptoSpi Tool");
35 _LIT(KName, "Symbian Dump CryptoSpi Tool");
36 _LIT(KCopyright, "Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.");
37 _LIT(KDone, "Complete Dumping... \n");
39 //dumpcryptoplugin options
41 _LIT(KAllShort, "-a");
43 _LIT(KInterface, "-interface");
44 _LIT(KInterfaceShort, "-i");
46 _LIT(KAlgorithm, "-algorithm");
47 _LIT(KAlgorithmShort, "-al");
49 _LIT(KExtended, "-extended");
50 _LIT(KExtendedShort, "-e");
53 _LIT(KDllShort, "-d");
56 _LIT(KHelpShort, "-h");
58 _LIT(KOutputFile, "-out");
59 _LIT(KOutputFileShort, "-o");
63 _LIT(KMissingInterfaceName, "Missing Interface Name. \n");
64 _LIT(KInvalidInterfaceName, "Invalid Interface Name. \n");
65 _LIT(KMissingAlgorithmName, "Missing Algorithm Name. \n");
66 _LIT(KInvalidAlgorithmName, "Invalid Algorithm Name. \n");
67 _LIT(KMissingDllName, "Missing Plugin Dll Name. \n");
68 _LIT(KMissingOutputName, "Missing Output Name. \n");
69 _LIT(KError, "Error=%d \n");
72 The method converts the given interface name to interface uid
74 TInt ConvertToInterfaceId(const TDesC& aInterfaceName, TInt32& aInterfaceId)
76 if (aInterfaceName.CompareF(KHash)==0)
78 aInterfaceId=KHashInterface;
82 if (aInterfaceName.CompareF(KRandom)==0)
84 aInterfaceId=KRandomInterface;
88 if (aInterfaceName.CompareF(KSymmetricCipher)==0)
90 aInterfaceId=KSymmetricCipherInterface;
94 if (aInterfaceName.CompareF(KAsymmetricCipher)==0)
96 aInterfaceId=KAsymmetricCipherInterface;
100 if (aInterfaceName.CompareF(KSigner)==0)
102 aInterfaceId=KSignerInterface;
106 if (aInterfaceName.CompareF(KVerifier)==0)
108 aInterfaceId=KVerifierInterface;
112 if (aInterfaceName.CompareF(KKeyPairGenerator)==0)
114 aInterfaceId=KKeypairGeneratorInterface;
118 if (aInterfaceName.CompareF(KKeyAgreement)==0)
120 aInterfaceId=KKeyAgreementInterface;
124 if (aInterfaceName.CompareF(KAsyncHash)==0)
126 aInterfaceId=KAsyncHashInterface;
130 if (aInterfaceName.CompareF(KAsyncRandom)==0)
132 aInterfaceId=KAsyncRandomInterface;
136 if (aInterfaceName.CompareF(KAsyncSymmetricCipher)==0)
138 aInterfaceId=KAsyncSymmetricCipherInterface;
142 if (aInterfaceName.CompareF(KAsyncAsymmetricCipher)==0)
144 aInterfaceId=KAsyncAsymmetricCipherInterface;
148 if (aInterfaceName.CompareF(KAsyncSigner)==0)
150 aInterfaceId=KAsyncSignerInterface;
154 if (aInterfaceName.CompareF(KAsyncVerifier)==0)
156 aInterfaceId=KAsyncVerifierInterface;
160 if (aInterfaceName.CompareF(KAsyncKeyPairGenerator)==0)
162 aInterfaceId=KAsyncKeypairGeneratorInterface;
166 if (aInterfaceName.CompareF(KAsyncKeyAgreement)==0)
168 aInterfaceId=KAsyncKeyAgreementInterface;
176 The method converts the given algorithm name to algorithm uid
178 TInt ConvertToAlgorithmId(const TDesC& aAlgorithmName, TInt32& aAlgorithmId)
180 if (aAlgorithmName.CompareF(KMd2)==0)
182 aAlgorithmId=KAlgorithmHashMd2;
186 if (aAlgorithmName.CompareF(KMd5)==0)
188 aAlgorithmId=KAlgorithmHashMd5;
192 if (aAlgorithmName.CompareF(KMd4)==0)
194 aAlgorithmId=KAlgorithmHashMd4;
198 if (aAlgorithmName.CompareF(KSha1)==0)
200 aAlgorithmId=KAlgorithmHashSha1;
204 if (aAlgorithmName.CompareF(KDes)==0)
206 aAlgorithmId=KAlgorithmCipherDes;
210 if (aAlgorithmName.CompareF(K3Des)==0)
212 aAlgorithmId=KAlgorithmCipher3Des;
216 if (aAlgorithmName.CompareF(KRC2)==0)
218 aAlgorithmId=KAlgorithmCipherRc2;
222 if (aAlgorithmName.CompareF(KAes)==0)
224 aAlgorithmId=KAlgorithmCipherAes;
228 if (aAlgorithmName.CompareF(KRC4)==0)
230 aAlgorithmId=KAlgorithmCipherArc4;
234 if (aAlgorithmName.CompareF(KRsaCipher)==0)
236 aAlgorithmId=KAlgorithmCipherRsa;
240 if (aAlgorithmName.CompareF(KRsaSigner)==0)
242 aAlgorithmId=KAlgorithmSignerRsa;
246 if (aAlgorithmName.CompareF(KRsaVerifier)==0)
248 aAlgorithmId=KAlgorithmVerifierRsa;
252 if (aAlgorithmName.CompareF(KRsaKeyPair)==0)
254 aAlgorithmId=KAlgorithmRSAKeyPairGenerator;
258 if (aAlgorithmName.CompareF(KDsaSigner)==0)
260 aAlgorithmId=KAlgorithmSignerDsa;
264 if (aAlgorithmName.CompareF(KDsaVerifier)==0)
266 aAlgorithmId=KAlgorithmVerifierDsa;
270 if (aAlgorithmName.CompareF(KDsaKeyPair)==0)
272 aAlgorithmId=KAlgorithmDSAKeyPairGenerator;
276 if (aAlgorithmName.CompareF(KDhKeyPair)==0)
278 aAlgorithmId=KAlgorithmDHKeyPairGenerator;
282 if (aAlgorithmName.CompareF(KDhKeyAgreement)==0)
284 aAlgorithmId=KAlgorithmKeyAgreementDH;
293 Displays tool name and copy-right informations.
295 void BoilerPlate(CConsoleBase* console)
297 console->Printf(KNewLine);
298 console->Printf(KName);
299 console->Printf(KNewLine);
300 console->Printf(KCopyright);
301 console->Printf(KNewLine);
302 console->Printf(KNewLine);
306 The method retrieves the command line parameters and build the CDumpToolParameters object.
309 void ExtractOptionL(const CCommandLineArguments& aInput, CDumpToolParameters& aParam, CConsoleBase* aConsole)
311 TInt count=aInput.Count();
318 if ((aInput.Arg(i).Compare(KAll)==0)||(aInput.Arg(i).Compare(KAllShort)==0))
323 //Handle -i and -interface
324 if ((aInput.Arg(i).Compare(KInterface)==0)||(aInput.Arg(i).Compare(KInterfaceShort)==0))
326 //Move to interface name
330 aConsole->Printf(KMissingInterfaceName);
331 User::Leave(KErrArgument);
334 //Currently point to interface name
335 if (KErrNone!=ConvertToInterfaceId(aInput.Arg(i), aParam.iInterface))
337 //Invalid interface name
338 aConsole->Printf(KInvalidInterfaceName);
339 User::Leave(KErrArgument);
344 //Handle -al and -algorithm
345 if ((aInput.Arg(i).Compare(KAlgorithm)==0)||(aInput.Arg(i).Compare(KAlgorithmShort)==0))
347 //Move to algorithm name
351 aConsole->Printf(KMissingAlgorithmName);
352 User::Leave(KErrArgument);
355 //Currently point to algorithm name
356 if (KErrNone!=ConvertToAlgorithmId(aInput.Arg(i), aParam.iAlgorithm))
358 //Invalid algorithm name
359 aConsole->Printf(KInvalidAlgorithmName);
360 User::Leave(KErrArgument);
365 //Handle -e and -extended
366 if ((aInput.Arg(i).Compare(KExtended)==0)||(aInput.Arg(i).Compare(KExtendedShort)==0))
368 aParam.iOptions.AppendL(CDumpToolParameters::EOptionExtendedCharacteristic);
373 if ((aInput.Arg(i).Compare(KDll)==0)||(aInput.Arg(i).Compare(KDllShort)==0))
378 aConsole->Printf(KMissingDllName);
379 User::Leave(KErrArgument);
381 aParam.iDllName=aInput.Arg(i);
386 if ((aInput.Arg(i).Compare(KOutputFile)==0)||(aInput.Arg(i).Compare(KOutputFileShort)==0))
391 aConsole->Printf(KMissingOutputName);
392 User::Leave(KErrArgument);
394 aParam.iDumpFileName=aInput.Arg(i);
398 //Handle -h and -help
399 if ((aInput.Arg(i).Compare(KHelp)==0)||(aInput.Arg(i).Compare(KHelpShort)==0))
401 aParam.iOptions.AppendL(CDumpToolParameters::EOptionHelp);
405 HBufC* temp=aInput.Arg(i).AllocLC();
406 aParam.iInvalidOptions.AppendL(temp);
407 CleanupStack::Pop(temp);
412 void DoProcessL(CConsoleBase* aConsole)
414 //Get the command line arguments
415 CCommandLineArguments* args = CCommandLineArguments::NewLC();
417 //Construct the parameters holder
418 CDumpToolParameters* params = CDumpToolParameters::NewLC();
420 //Retrieve the command line options
421 ExtractOptionL(*args, *params, aConsole);
423 //Process the command line and output the characteristics.
424 CDumpToolProcessor* processor=CDumpToolProcessor::NewLC(*params, aConsole);
425 processor->ProcessL();
426 aConsole->Printf(KNewLine);
427 CleanupStack::PopAndDestroy(processor);
428 CleanupStack::PopAndDestroy(2, args); // params, args,
432 Main function to retrieve and log the characteristics
436 //New a console and print tool information
437 CConsoleBase* console = Console::NewL(KShortName, TSize(KDefaultConsWidth, KDefaultConsHeight));
438 CleanupStack::PushL(console);
439 BoilerPlate(console);
440 TRAPD(err, DoProcessL(console));
441 if (err!=KErrArgument && err!=KErrNone)
443 console->Printf(KError, err);
447 console->Printf(KPressAnyKey);
450 console->Printf(KDone);
452 CleanupStack::PopAndDestroy(console); // params, args, console
456 @return KErrNone (0) if successful, KErrMemory if out of memory
457 otherwise error result from DoMainL
462 CTrapCleanup* trapCleanup=CTrapCleanup::New();
468 TRAPD(err, DoMainL());