os/security/cryptoservices/certificateandkeymgmt/tcertstore/t_certstoreactionsfilecertstore.cpp
First public contribution.
2 * Copyright (c) 2005-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.
23 #include "t_certstoreactionsfilecertstore.h"
24 #include "t_certstoredefs.h"
27 CTestAction* CCreateFileCertStore::NewL(RFs &aFs,
28 CConsoleBase& aConsole,
30 const TTestActionSpec& aTestActionSpec)
32 CTestAction* self = NewLC(aFs, aConsole, aOut, aTestActionSpec);
33 CleanupStack::Pop(self);
37 CTestAction* CCreateFileCertStore::NewLC(RFs &aFs,
38 CConsoleBase& aConsole,
40 const TTestActionSpec& aTestActionSpec)
42 CCreateFileCertStore* self =
43 new(ELeave) CCreateFileCertStore(aFs, aConsole, aOut);
44 CleanupStack::PushL(self);
45 self->ConstructL(aTestActionSpec);
49 CCreateFileCertStore::~CCreateFileCertStore()
54 void CCreateFileCertStore::PerformAction(TRequestStatus& aStatus)
60 TRAPD(err, HandleEInit());
61 TRequestStatus* status = &aStatus;
62 User::RequestComplete(status, err);
68 TRequestStatus* status = &aStatus;
69 User::RequestComplete(status, aStatus.Int());
70 if (aStatus == iExpectedResult)
84 void CCreateFileCertStore::PerformCancel()
88 void CCreateFileCertStore::Reset()
90 __ASSERT_DEBUG(EFalse, User::Panic(_L("CCreateFileCertStore::Reset()"), 1));
93 CCreateFileCertStore::CCreateFileCertStore(RFs &aFs,
94 CConsoleBase& aConsole,
96 : CCertStoreTestAction(aFs, aConsole, aOut),
97 iState(EInit), iFs(aFs)
101 void CCreateFileCertStore::ConstructL(const TTestActionSpec& aTestActionSpec)
103 CCertStoreTestAction::ConstructL(aTestActionSpec);
106 TPtrC8 fileName = Input::ParseElement(aTestActionSpec.iActionBody, KFileNameStart,
107 KFileNameEnd, pos, err);
108 iFileName = HBufC::NewL(fileName.Length());
109 iFileName->Des().Copy(fileName);
111 // Set expected result
114 HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
115 TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
116 Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
117 CleanupStack::PopAndDestroy(result);
120 void CCreateFileCertStore::HandleEInit()
123 CreateStoreL(*iFileName, iFs);
126 void CCreateFileCertStore::DoReportAction()
130 void CCreateFileCertStore::DoCheckResult(TInt /*aError*/)
134 void CCreateFileCertStore::CreateStoreL(const TDesC& aFileName, RFs& aFs)
136 aFs.MkDirAll(aFileName);
138 User::LeaveIfError(file.Replace(aFs, aFileName, EFileWrite));
140 //TCleanupItem deleteFile(CFileCertStore::DeleteFile, this);//store will revert() if a leave occurs
141 //CleanupStack::PushL(deleteFile);
143 CPermanentFileStore* store = CPermanentFileStore::NewLC(file);
144 store->SetTypeL(KPermanentFileStoreLayoutUid);
146 RStoreWriteStream caCertEntryStream;
147 TStreamId caCertEntryStreamId = caCertEntryStream.CreateLC(*store);
148 caCertEntryStream.WriteInt32L(0);//we have zero ca certs
149 caCertEntryStream.CommitL();
150 CleanupStack::PopAndDestroy();
152 RStoreWriteStream rootStream;
153 TStreamId rootId = rootStream.CreateLC(*store);
155 rootStream << caCertEntryStreamId;
156 rootStream.CommitL();
157 CleanupStack::PopAndDestroy();
159 store->SetRootL(rootId);
161 CleanupStack::PopAndDestroy();//store