os/security/cryptoservices/filebasedcertificateandkeystores/test/keytool/keytoolfileview.cpp
First public contribution.
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.
19 #include "keytool_defs.h"
20 #include "keytoolfileview.h"
23 #include "keytool_utils.h"
27 /*static*/ CKeytoolFileView* CKeytoolFileView::NewLC(const TDesC& aInputFile)
29 CKeytoolFileView* self = new (ELeave) CKeytoolFileView();
30 CleanupStack::PushL(self);
31 self->ConstructL(aInputFile);
35 CKeytoolFileView::CKeytoolFileView()
39 CKeytoolFileView::~CKeytoolFileView()
43 iArgs.ResetAndDestroy();
46 void CKeytoolFileView::ConstructL(const TDesC& aInputFile)
48 User::LeaveIfError(iFs.Connect());
49 User::LeaveIfError(iFile.Open(iFs, aInputFile, EFileShareExclusive));
52 void CKeytoolFileView::DisplayUsage()
56 void CKeytoolFileView::BoilerPlate()
61 void CKeytoolFileView::DisplayKeyInfoL(CCTKeyInfo& aKey, TBool aIsDetailed, TBool /*aPageWise*/)
63 // Display the key infos
64 KeyToolUtils::PrintKeyInfoL(aKey, aIsDetailed);
65 KeyToolUtils::PrintInfoL(_L("\n"));
68 void CKeytoolFileView::DisplayErrorL(const TDesC& aError, TInt aErrorCode, TBool/* aPageWise*/)
70 KeyToolUtils::PrintInfoL(aError);
71 KeyToolUtils::PrintInfoL(_L("\nError code: "));
72 KeyToolUtils::WriteErrorL(aErrorCode);
73 KeyToolUtils::PrintInfoL(_L("\n"));
76 void CKeytoolFileView::DisplayErrorL(const TDesC& aError, TBool/* aPageWise*/)
78 KeyToolUtils::PrintInfoL(aError);
79 KeyToolUtils::PrintInfoL(_L("\n"));
82 void CKeytoolFileView::DisplayCertL(CCTCertInfo& aCert, CCertificate& aCertificate, RUidArray aApps, TBool aTrusted, TBool aIsDetailed, TBool/* aPageWise*/)
84 // Display the key infos
85 KeyToolUtils::PrintCertInfoL(aCert, aCertificate, aApps, aTrusted, aIsDetailed);
86 KeyToolUtils::PrintInfoL(_L("\n"));
89 CArrayFixFlat<TPtrC>* CKeytoolFileView::ReadArrayArgumentsLC(TInt cmdIndex)
91 CArrayFixFlat<TPtrC>* currentCmd = new (ELeave) CArrayFixFlat<TPtrC> (10);
92 CleanupStack::PushL(currentCmd);
93 TPtr cmd = iArgs[cmdIndex]->Des();
96 while(!arguments.Eos())
98 TPtrC token = arguments.NextToken();
99 currentCmd->AppendL(token);
103 string.Format(_L("Command : %S\noutput :"), &cmd);
104 KeyToolUtils::PrintInfoL(_L("================================================"));
105 KeyToolUtils::PrintInfoL(_L("================================================\n"));
106 DisplayErrorL(string, 0);
110 TInt CKeytoolFileView::SplitFileInputToArrayL()
115 HBufC8* fileContents = HBufC8::NewLC(fSize);
116 TPtr8 ptr(fileContents->Des());
117 ptr.SetLength(fSize);
119 // create file stream and Read the content from the file
120 RFileReadStream inputFileStream(iFile);
121 CleanupClosePushL(inputFileStream);
122 inputFileStream.ReadL(ptr, fSize);
123 CleanupStack::PopAndDestroy(&inputFileStream);
129 while (!ReadLine(*fileContents, readPos, lineContents))
131 TInt lineLength = lineContents.Length();
135 HBufC* currentLine = HBufC::NewLC(lineLength);
136 currentLine->Des().Copy(lineContents);
137 iArgs.AppendL(currentLine);
138 CleanupStack::Pop(currentLine);
141 CleanupStack::PopAndDestroy(fileContents);
145 TInt CKeytoolFileView::ReadLine(const TDesC8& aBuffer, TInt& aPos, TPtrC8& aLine)
147 TBool endOfBuffer = EFalse;
148 const TChar KCarriageReturn = '\r';
149 const TChar KLineReturn = '\n';
151 TInt bufferLength = aBuffer.Length();
152 if ( aPos > bufferLength || aPos < 0 )
154 return ETrue; // End of buffer
157 // find the position of the next delimter
159 while (endPos < bufferLength)
161 TChar c = aBuffer[endPos];
163 if (c == KCarriageReturn || c == KLineReturn)
172 TInt tokenLen = endPos - aPos;
173 aLine.Set(&aBuffer[aPos], tokenLen);
178 return ETrue; // End of buffer