os/security/cryptoservices/filebasedcertificateandkeystores/test/keytool/keytoolfileview.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/filebasedcertificateandkeystores/test/keytool/keytoolfileview.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,185 @@
     1.4 +/*
     1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include "keytool_defs.h"
    1.23 +#include "keytoolfileview.h"
    1.24 +
    1.25 +#include <e32cons.h>
    1.26 +#include "keytool_utils.h"
    1.27 +#include <s32file.h>
    1.28 +
    1.29 +
    1.30 +/*static*/ CKeytoolFileView* CKeytoolFileView::NewLC(const TDesC& aInputFile)
    1.31 +	{
    1.32 +	CKeytoolFileView* self = new (ELeave) CKeytoolFileView();
    1.33 +	CleanupStack::PushL(self);
    1.34 +	self->ConstructL(aInputFile);
    1.35 +	return self;
    1.36 +	}
    1.37 +
    1.38 +CKeytoolFileView::CKeytoolFileView()
    1.39 +	{	
    1.40 +	}
    1.41 +	
    1.42 +CKeytoolFileView::~CKeytoolFileView()
    1.43 +	{
    1.44 +	iFs.Close();
    1.45 +	iFile.Close();
    1.46 +	iArgs.ResetAndDestroy();
    1.47 +	}
    1.48 +	
    1.49 +void CKeytoolFileView::ConstructL(const TDesC& aInputFile)
    1.50 +	{
    1.51 +	User::LeaveIfError(iFs.Connect());
    1.52 +	User::LeaveIfError(iFile.Open(iFs, aInputFile, EFileShareExclusive));
    1.53 +	}
    1.54 +
    1.55 +void CKeytoolFileView::DisplayUsage()
    1.56 +	{	
    1.57 +	}
    1.58 +	
    1.59 +void CKeytoolFileView::BoilerPlate()
    1.60 +	{
    1.61 +	
    1.62 +	}
    1.63 +	
    1.64 +void CKeytoolFileView::DisplayKeyInfoL(CCTKeyInfo& aKey, TBool aIsDetailed, TBool /*aPageWise*/)
    1.65 +	{
    1.66 +	// Display the key infos
    1.67 +	KeyToolUtils::PrintKeyInfoL(aKey, aIsDetailed);
    1.68 + 	KeyToolUtils::PrintInfoL(_L("\n"));
    1.69 + 	}
    1.70 +	
    1.71 +void CKeytoolFileView::DisplayErrorL(const TDesC& aError, TInt aErrorCode, TBool/* aPageWise*/)
    1.72 +	{
    1.73 +	KeyToolUtils::PrintInfoL(aError);
    1.74 +	KeyToolUtils::PrintInfoL(_L("\nError code: "));
    1.75 +	KeyToolUtils::WriteErrorL(aErrorCode);
    1.76 +	KeyToolUtils::PrintInfoL(_L("\n"));
    1.77 +	}
    1.78 +	 	
    1.79 + void CKeytoolFileView::DisplayErrorL(const TDesC& aError, TBool/* aPageWise*/)
    1.80 +	{
    1.81 +	KeyToolUtils::PrintInfoL(aError);
    1.82 +	KeyToolUtils::PrintInfoL(_L("\n"));
    1.83 +	}
    1.84 +	
    1.85 + void CKeytoolFileView::DisplayCertL(CCTCertInfo& aCert, CCertificate& aCertificate, RUidArray aApps, TBool aTrusted, TBool aIsDetailed, TBool/* aPageWise*/)
    1.86 + 	{
    1.87 +	// Display the key infos
    1.88 +	KeyToolUtils::PrintCertInfoL(aCert, aCertificate, aApps, aTrusted, aIsDetailed);
    1.89 + 	KeyToolUtils::PrintInfoL(_L("\n")); 	
    1.90 + 	}
    1.91 +
    1.92 +CArrayFixFlat<TPtrC>* CKeytoolFileView::ReadArrayArgumentsLC(TInt cmdIndex)
    1.93 +	{
    1.94 +	CArrayFixFlat<TPtrC>* currentCmd = new (ELeave) CArrayFixFlat<TPtrC> (10);
    1.95 +	CleanupStack::PushL(currentCmd);
    1.96 +	TPtr cmd = iArgs[cmdIndex]->Des();
    1.97 +	cmd.Trim();
    1.98 +	TLex arguments(cmd);
    1.99 +	while(!arguments.Eos())
   1.100 +    	{
   1.101 +        TPtrC token = arguments.NextToken();
   1.102 +        currentCmd->AppendL(token);
   1.103 +        }
   1.104 +    
   1.105 +    TBuf<150> string;
   1.106 +	string.Format(_L("Command :  %S\noutput :"), &cmd);
   1.107 +	KeyToolUtils::PrintInfoL(_L("================================================"));
   1.108 +	KeyToolUtils::PrintInfoL(_L("================================================\n"));
   1.109 +    DisplayErrorL(string, 0);
   1.110 +    return currentCmd;
   1.111 +	}
   1.112 +
   1.113 +TInt CKeytoolFileView::SplitFileInputToArrayL()
   1.114 +	{
   1.115 +	TInt fSize;
   1.116 +	iFile.Size(fSize);
   1.117 +
   1.118 +	HBufC8* fileContents = HBufC8::NewLC(fSize);
   1.119 +	TPtr8 ptr(fileContents->Des());
   1.120 +	ptr.SetLength(fSize);
   1.121 +	
   1.122 +	// create file stream and Read the content from the file
   1.123 +	RFileReadStream inputFileStream(iFile);
   1.124 +    CleanupClosePushL(inputFileStream);
   1.125 +	inputFileStream.ReadL(ptr, fSize);
   1.126 +	CleanupStack::PopAndDestroy(&inputFileStream);
   1.127 +	
   1.128 +	TInt readPos = 0;
   1.129 +	TPtrC8 lineContents;
   1.130 +
   1.131 +	TInt lineCount = 0;
   1.132 +	while (!ReadLine(*fileContents, readPos, lineContents))
   1.133 +		{
   1.134 +		TInt lineLength = lineContents.Length();
   1.135 +		if (lineLength)
   1.136 +			{
   1.137 +			lineCount++;
   1.138 +			HBufC* currentLine = HBufC::NewLC(lineLength);
   1.139 +			currentLine->Des().Copy(lineContents);
   1.140 +			iArgs.AppendL(currentLine);
   1.141 +			CleanupStack::Pop(currentLine);
   1.142 +			}
   1.143 +		}
   1.144 +	CleanupStack::PopAndDestroy(fileContents);
   1.145 +	return lineCount;
   1.146 +	}
   1.147 +	
   1.148 +TInt CKeytoolFileView::ReadLine(const TDesC8& aBuffer, TInt& aPos, TPtrC8& aLine)
   1.149 +	{
   1.150 +	TBool endOfBuffer = EFalse;
   1.151 +	const TChar KCarriageReturn = '\r';
   1.152 +	const TChar KLineReturn = '\n';
   1.153 +
   1.154 +	TInt bufferLength = aBuffer.Length();
   1.155 +	if ( aPos > bufferLength || aPos < 0 )
   1.156 +		{	
   1.157 +		return ETrue; // End of buffer
   1.158 +		}
   1.159 +		
   1.160 +	// find the position of the next delimter		
   1.161 +	TInt endPos = aPos;	
   1.162 +	while (endPos < bufferLength)
   1.163 +		{
   1.164 +		TChar c = aBuffer[endPos];
   1.165 +
   1.166 +		if (c == KCarriageReturn || c == KLineReturn) 
   1.167 +			{
   1.168 +			break;
   1.169 +			}	
   1.170 +		endPos++;
   1.171 +		}
   1.172 +
   1.173 +	if (endPos != aPos)	
   1.174 +		{
   1.175 +		TInt tokenLen = endPos - aPos;
   1.176 +		aLine.Set(&aBuffer[aPos], tokenLen);
   1.177 +		endPos += 2;
   1.178 +		}
   1.179 +	else
   1.180 +		{
   1.181 +		return ETrue; // End of buffer
   1.182 +		}
   1.183 +
   1.184 +	aPos = endPos;
   1.185 +	return endOfBuffer;
   1.186 +	}
   1.187 +	
   1.188 +