First public contribution.
2 * Copyright (c) 1998-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.
15 * tactiondecodepkcs5.cpp
20 #include "tactiontestpkcs8.h"
28 _LIT8(KFilenameStart, "<filename>");
29 _LIT8(KMatchesStart, "<matches>");
31 _LIT8(KOutcomeNoMatch, "noMatch");
32 _LIT8(KOutcomeMatchesPKCS8, "pkcs8");
33 _LIT8(KOutcomeMatchesEncryptedPKCS8, "encryptedPkcs8");
35 _LIT(KFilenameBase, "\\tkeystore\\data\\");
37 CTestAction* CActionTestPKCS8::NewL(RFs& aFs,
38 CConsoleBase& aConsole,
40 const TTestActionSpec& aTestActionSpec)
42 CActionTestPKCS8* self = new(ELeave) CActionTestPKCS8(aFs, aConsole, aOut);
43 CleanupStack::PushL(self);
44 self->ConstructL(aTestActionSpec);
49 CActionTestPKCS8::~CActionTestPKCS8()
54 CActionTestPKCS8::CActionTestPKCS8(RFs& aFs,
55 CConsoleBase& aConsole,
58 : CTestAction(aConsole, aOut), iFs(aFs)
62 void CActionTestPKCS8::ConstructL(const TTestActionSpec& aTestActionSpec)
64 CTestAction::ConstructL(aTestActionSpec);
65 ReadInputFileL(Input::ParseElement(aTestActionSpec.iActionBody, KFilenameStart));
66 SetExpectedOutcomeL(Input::ParseElement(aTestActionSpec.iActionBody, KMatchesStart));
69 void CActionTestPKCS8::ReadInputFileL(const TDesC8& aFilename)
71 if (aFilename == KNullDesC8)
73 User::Leave(KErrArgument);
76 TFileName tempFilename;
77 tempFilename.Copy(aFilename); // convert from 8 -> 16 bit descriptor
79 TDriveUnit sysDrive = RFs::GetSystemDrive();
80 TDriveName sysDriveName (sysDrive.Name());
81 tempFilename.Insert(0,sysDriveName);
82 tempFilename.Insert(2,KFilenameBase);
85 User::LeaveIfError(file.Open(iFs, tempFilename, EFileRead));
86 CleanupClosePushL(file);
88 User::LeaveIfError(file.Size(size));
90 iInput = HBufC8::NewMaxL(size);
91 TPtr8 ptr = iInput->Des();
92 User::LeaveIfError(file.Read(ptr));
94 CleanupStack::PopAndDestroy(&file);
97 void CActionTestPKCS8::SetExpectedOutcomeL(const TDesC8& aOutcome)
99 if (aOutcome == KOutcomeNoMatch)
101 iExpectedOutcome = ENoMatch;
103 else if (aOutcome == KOutcomeMatchesPKCS8)
105 iExpectedOutcome = EMatchesPKCS8;
107 else if (aOutcome == KOutcomeMatchesEncryptedPKCS8)
109 iExpectedOutcome = EMatchesEncryptedPKCS8;
113 User::Leave(KErrArgument);
117 void CActionTestPKCS8::DoReportAction(void)
121 void CActionTestPKCS8::DoCheckResult(TInt)
125 void CActionTestPKCS8::PerformAction(TRequestStatus& aStatus)
127 TRequestStatus* status = &aStatus;
130 TBool matchesPKCS8 = TASN1DecPKCS8::IsPKCS8Data(*iInput);
131 TBool matchesEncryptedPKCS8 = TASN1DecPKCS8::IsEncryptedPKCS8Data(*iInput);
133 if (matchesPKCS8 && matchesEncryptedPKCS8)
135 iOut.writeString(_L("!! Data matches both cleartext and encrypted pkcs8\n"));
136 User::Leave(KErrGeneral);
139 TOutcome outcome = ENoMatch;
143 iOut.writeString(_L("Data matches cleartext pkcs8\n"));
144 outcome = EMatchesPKCS8;
146 else if (matchesEncryptedPKCS8)
148 iOut.writeString(_L("Data matches encrypted pkcs8\n"));
149 outcome = EMatchesEncryptedPKCS8;
153 iOut.writeString(_L("Data doesn't match anything\n"));
156 if(outcome == iExpectedOutcome)
161 User::RequestComplete(status, KErrNone);
162 iActionState = CTestAction::EPostrequisite;