sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "ValidateTest.h"
|
sl@0
|
20 |
#include "t_input.h"
|
sl@0
|
21 |
|
sl@0
|
22 |
_LIT(KFilenameStart, "<filename>");
|
sl@0
|
23 |
_LIT(KExpectedKeyIDStart, "<expectedkeyid>");
|
sl@0
|
24 |
_LIT(KResultStart, "<result>");
|
sl@0
|
25 |
|
sl@0
|
26 |
CTestAction* CValidateTest::NewL(RFs& aFs, CConsoleBase& aConsole,
|
sl@0
|
27 |
Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
28 |
{
|
sl@0
|
29 |
CTestAction* self = CValidateTest::NewLC(aFs, aConsole, aOut, aTestActionSpec);
|
sl@0
|
30 |
CleanupStack::Pop(self);
|
sl@0
|
31 |
return self;
|
sl@0
|
32 |
}
|
sl@0
|
33 |
|
sl@0
|
34 |
CTestAction* CValidateTest::NewLC(RFs& aFs, CConsoleBase& aConsole,
|
sl@0
|
35 |
Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
36 |
{
|
sl@0
|
37 |
CValidateTest* self = new(ELeave) CValidateTest(aFs, aConsole, aOut);
|
sl@0
|
38 |
CleanupStack::PushL(self);
|
sl@0
|
39 |
self->ConstructL(aTestActionSpec);
|
sl@0
|
40 |
return self;
|
sl@0
|
41 |
}
|
sl@0
|
42 |
|
sl@0
|
43 |
|
sl@0
|
44 |
CValidateTest::CValidateTest(RFs& aFs,
|
sl@0
|
45 |
CConsoleBase& aConsole,
|
sl@0
|
46 |
Output& aOut)
|
sl@0
|
47 |
: CTestAction(aConsole, aOut), iFs(aFs)
|
sl@0
|
48 |
{
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
void CValidateTest::ConstructL(const TTestActionSpec& aTestActionSpec)
|
sl@0
|
52 |
{
|
sl@0
|
53 |
CTestAction::ConstructL(aTestActionSpec);
|
sl@0
|
54 |
TInt pos=0, resultPos=0;
|
sl@0
|
55 |
HBufC* aBody = HBufC::NewLC(aTestActionSpec.iActionBody.Length());
|
sl@0
|
56 |
|
sl@0
|
57 |
aBody->Des().Copy(aTestActionSpec.iActionBody);
|
sl@0
|
58 |
// creates the test chan validation object
|
sl@0
|
59 |
TPtrC ioFilename = Input::ParseElement(*aBody, KFilenameStart, pos);
|
sl@0
|
60 |
iFilename.Copy(ioFilename);
|
sl@0
|
61 |
TPtrC ioKeyId = Input::ParseElement(*aBody, KExpectedKeyIDStart, pos);
|
sl@0
|
62 |
|
sl@0
|
63 |
if(ioKeyId.Length() == 40)
|
sl@0
|
64 |
{
|
sl@0
|
65 |
iResultKeyID.SetLength(iResultKeyID.MaxLength());
|
sl@0
|
66 |
for(TInt byte =0; byte < 40; byte+=2)
|
sl@0
|
67 |
{
|
sl@0
|
68 |
TUint8 firstHalfOfOutput = ConvertByteA2H(static_cast<TInt8>(ioKeyId[byte]));
|
sl@0
|
69 |
TUint8 secondHalfOfOutput = ConvertByteA2H(static_cast<TInt8>(ioKeyId[byte+1]));
|
sl@0
|
70 |
iResultKeyID[resultPos] = static_cast<TInt8>((firstHalfOfOutput << 4)|secondHalfOfOutput);
|
sl@0
|
71 |
resultPos++;
|
sl@0
|
72 |
};
|
sl@0
|
73 |
}
|
sl@0
|
74 |
TPtrC ioResult = Input::ParseElement(*aBody, KResultStart, pos);
|
sl@0
|
75 |
|
sl@0
|
76 |
if(ioResult.CompareF(_L("Valid"))==0)
|
sl@0
|
77 |
iValid = ETrue;
|
sl@0
|
78 |
else
|
sl@0
|
79 |
iValid = EFalse;
|
sl@0
|
80 |
|
sl@0
|
81 |
CleanupStack::PopAndDestroy(aBody);
|
sl@0
|
82 |
}
|
sl@0
|
83 |
|
sl@0
|
84 |
CValidateTest::~CValidateTest()
|
sl@0
|
85 |
{
|
sl@0
|
86 |
}
|
sl@0
|
87 |
|
sl@0
|
88 |
TUint8 CValidateTest::ConvertByteA2H(TUint8 aInput)
|
sl@0
|
89 |
{
|
sl@0
|
90 |
TUint8 output=0;
|
sl@0
|
91 |
if ((aInput > 0x29) && (aInput < 0x3a))
|
sl@0
|
92 |
{
|
sl@0
|
93 |
output = static_cast<TInt8>(aInput-0x30);
|
sl@0
|
94 |
}
|
sl@0
|
95 |
if ((aInput > 0x40) && (aInput < 0x47))
|
sl@0
|
96 |
{
|
sl@0
|
97 |
output = static_cast<TInt8>(aInput-0x37);
|
sl@0
|
98 |
}
|
sl@0
|
99 |
return output;
|
sl@0
|
100 |
}
|
sl@0
|
101 |
|
sl@0
|
102 |
|
sl@0
|
103 |
void CValidateTest::DoPerformPrerequisite(TRequestStatus& aStatus)
|
sl@0
|
104 |
{
|
sl@0
|
105 |
TRequestStatus* status = &aStatus;
|
sl@0
|
106 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
107 |
iActionState = EAction;
|
sl@0
|
108 |
}
|
sl@0
|
109 |
|
sl@0
|
110 |
void CValidateTest::DoPerformPostrequisite(TRequestStatus& aStatus)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
TRequestStatus* status = &aStatus;
|
sl@0
|
113 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
114 |
iFinished = ETrue;
|
sl@0
|
115 |
}
|
sl@0
|
116 |
|
sl@0
|
117 |
void CValidateTest::PerformAction(TRequestStatus& aStatus)
|
sl@0
|
118 |
{
|
sl@0
|
119 |
CX509Certificate* cert = NULL;
|
sl@0
|
120 |
TInt err;
|
sl@0
|
121 |
TFileName filename(iFilename);
|
sl@0
|
122 |
|
sl@0
|
123 |
HBufC8* buf=NULL;
|
sl@0
|
124 |
TRAP(err, buf = Input::ReadFileL(filename, iFs));
|
sl@0
|
125 |
|
sl@0
|
126 |
if (err == KErrNotFound)
|
sl@0
|
127 |
{
|
sl@0
|
128 |
iResult = EFalse;
|
sl@0
|
129 |
iFinished = ETrue;
|
sl@0
|
130 |
SetScriptError(EFileNotFound, iFilename);
|
sl@0
|
131 |
TRequestStatus* status = &aStatus;
|
sl@0
|
132 |
iActionState = EPostrequisite;
|
sl@0
|
133 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
134 |
return;
|
sl@0
|
135 |
}
|
sl@0
|
136 |
else if (err != KErrNone)
|
sl@0
|
137 |
User::Leave(err);
|
sl@0
|
138 |
|
sl@0
|
139 |
CleanupStack::PushL(buf);
|
sl@0
|
140 |
cert = CX509Certificate::NewLC(buf->Des());
|
sl@0
|
141 |
|
sl@0
|
142 |
TKeyIdentifier id = cert->KeyIdentifierL();
|
sl@0
|
143 |
CleanupStack::PopAndDestroy(2); // buf & cert
|
sl@0
|
144 |
|
sl@0
|
145 |
iConsole.Printf(_L("Validating file "));
|
sl@0
|
146 |
iConsole.Printf(iFilename);
|
sl@0
|
147 |
iOut.writeString(_L("Validating file "));
|
sl@0
|
148 |
iOut.writeString(iFilename);
|
sl@0
|
149 |
|
sl@0
|
150 |
if(id == iResultKeyID)
|
sl@0
|
151 |
{
|
sl@0
|
152 |
iConsole.Printf(_L(" Match "));
|
sl@0
|
153 |
iOut.writeString(_L(" Match "));
|
sl@0
|
154 |
if(iValid)
|
sl@0
|
155 |
iResult = ETrue;
|
sl@0
|
156 |
else
|
sl@0
|
157 |
iResult = EFalse;
|
sl@0
|
158 |
}
|
sl@0
|
159 |
else
|
sl@0
|
160 |
{
|
sl@0
|
161 |
iConsole.Printf(_L(" No Match "));
|
sl@0
|
162 |
iOut.writeString(_L(" No Match "));
|
sl@0
|
163 |
if(!iValid)
|
sl@0
|
164 |
iResult = ETrue;
|
sl@0
|
165 |
else
|
sl@0
|
166 |
iResult = EFalse;
|
sl@0
|
167 |
}
|
sl@0
|
168 |
if(iResult)
|
sl@0
|
169 |
{
|
sl@0
|
170 |
iConsole.Printf(_L(" Success\n"));
|
sl@0
|
171 |
iOut.writeString(_L(" Success"));
|
sl@0
|
172 |
iOut.writeNewLine();
|
sl@0
|
173 |
}
|
sl@0
|
174 |
else
|
sl@0
|
175 |
{
|
sl@0
|
176 |
iConsole.Printf(_L(" Failed\n"));
|
sl@0
|
177 |
iOut.writeString(_L(" Failed"));
|
sl@0
|
178 |
iOut.writeNewLine();
|
sl@0
|
179 |
};
|
sl@0
|
180 |
|
sl@0
|
181 |
TRequestStatus* status = &aStatus;
|
sl@0
|
182 |
iActionState = EPostrequisite;
|
sl@0
|
183 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
184 |
}
|
sl@0
|
185 |
|
sl@0
|
186 |
|
sl@0
|
187 |
void CValidateTest::DoReportAction()
|
sl@0
|
188 |
{
|
sl@0
|
189 |
}
|
sl@0
|
190 |
|
sl@0
|
191 |
void CValidateTest::DoCheckResult(TInt /*aError*/)
|
sl@0
|
192 |
{
|
sl@0
|
193 |
}
|
sl@0
|
194 |
|