os/security/cryptoservices/certificateandkeymgmt/tadditionalstores/tadditionalstoreentries.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2005-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
/**
sl@0
    20
 @file
sl@0
    21
*/
sl@0
    22
sl@0
    23
#include "tadditionalstoremapping.h"
sl@0
    24
sl@0
    25
////////////////////////////////////////////////////////////////////////////////
sl@0
    26
//CFileCertStoreMapping
sl@0
    27
/////////////////////////////////////////////////////////////////////////////////
sl@0
    28
sl@0
    29
CFileCertStoreMapping* CFileCertStoreMapping::NewL()
sl@0
    30
	{
sl@0
    31
	CFileCertStoreMapping* self = CFileCertStoreMapping::NewLC();
sl@0
    32
	CleanupStack::Pop(self);
sl@0
    33
	return self;
sl@0
    34
	}
sl@0
    35
sl@0
    36
CFileCertStoreMapping* CFileCertStoreMapping::NewLC()
sl@0
    37
	{
sl@0
    38
	CFileCertStoreMapping* self = new(ELeave) CFileCertStoreMapping();
sl@0
    39
	CleanupStack::PushL(self);
sl@0
    40
	self->ConstructL();
sl@0
    41
	return self;
sl@0
    42
	}
sl@0
    43
sl@0
    44
void CFileCertStoreMapping::ConstructL()
sl@0
    45
	{
sl@0
    46
	iCertificateApps = new(ELeave) RArray<TUid>();
sl@0
    47
	}
sl@0
    48
sl@0
    49
CFileCertStoreMapping::CFileCertStoreMapping()
sl@0
    50
	{	
sl@0
    51
	}
sl@0
    52
sl@0
    53
CFileCertStoreMapping::~CFileCertStoreMapping()
sl@0
    54
	{
sl@0
    55
	if (iEntry)
sl@0
    56
		{
sl@0
    57
		iEntry->Release();
sl@0
    58
		}
sl@0
    59
	if (iCertificateApps)
sl@0
    60
		{
sl@0
    61
		iCertificateApps->Close();
sl@0
    62
		delete iCertificateApps;
sl@0
    63
		}
sl@0
    64
	}
sl@0
    65
sl@0
    66
void CFileCertStoreMapping::SetEntry(CCTCertInfo* aCertInfo)
sl@0
    67
	{
sl@0
    68
	if (iEntry)
sl@0
    69
		{
sl@0
    70
		iEntry->Release();
sl@0
    71
		}
sl@0
    72
	iEntry = aCertInfo;
sl@0
    73
	}
sl@0
    74
sl@0
    75
void CFileCertStoreMapping::SetCertificateApps(RArray<TUid>* aCertificateApps)
sl@0
    76
	{
sl@0
    77
	iCertificateApps->Close();
sl@0
    78
	delete iCertificateApps;
sl@0
    79
	iCertificateApps = aCertificateApps;
sl@0
    80
	}
sl@0
    81
sl@0
    82
void CFileCertStoreMapping::SetId(TStreamId aId)
sl@0
    83
	{
sl@0
    84
	iId = aId;
sl@0
    85
	}
sl@0
    86
sl@0
    87
CCTCertInfo* CFileCertStoreMapping::Entry() const
sl@0
    88
	{
sl@0
    89
	return iEntry;
sl@0
    90
	}
sl@0
    91
sl@0
    92
const RArray<TUid>& CFileCertStoreMapping::CertificateApps() const
sl@0
    93
	{
sl@0
    94
	return *iCertificateApps;
sl@0
    95
	}
sl@0
    96
sl@0
    97
TBool CFileCertStoreMapping::IsApplicable(const TUid& aApplication) const
sl@0
    98
	{
sl@0
    99
	TInt count = iCertificateApps->Count();
sl@0
   100
	for (TInt i = 0; i < count; i++)
sl@0
   101
		{
sl@0
   102
		TUid app = (*iCertificateApps)[i];
sl@0
   103
		if (app == aApplication)
sl@0
   104
				{
sl@0
   105
				return ETrue;
sl@0
   106
				}
sl@0
   107
		}
sl@0
   108
	return EFalse;
sl@0
   109
	}
sl@0
   110
sl@0
   111
TBool CFileCertStoreMapping::Trusted() const
sl@0
   112
	{
sl@0
   113
	return iTrusted;
sl@0
   114
	}
sl@0
   115
sl@0
   116
void CFileCertStoreMapping::SetTrusted(TBool aTrusted)
sl@0
   117
	{
sl@0
   118
	iTrusted = aTrusted;
sl@0
   119
	}
sl@0
   120
sl@0
   121
TStreamId CFileCertStoreMapping::Id() const
sl@0
   122
	{
sl@0
   123
	return iId;
sl@0
   124
	}
sl@0
   125
sl@0
   126
void CFileCertStoreMapping::ExternalizeL(RWriteStream& aStream) const
sl@0
   127
	{
sl@0
   128
	if (!iTempRemoved)
sl@0
   129
		{
sl@0
   130
		aStream << *iEntry;
sl@0
   131
		TInt count = iCertificateApps->Count();
sl@0
   132
		aStream.WriteInt32L(count);
sl@0
   133
		for (TInt i = 0; i < count; i++)
sl@0
   134
			{
sl@0
   135
			aStream << (*iCertificateApps)[i];
sl@0
   136
			}
sl@0
   137
		aStream.WriteUint8L(iTrusted);
sl@0
   138
		aStream << iId;			
sl@0
   139
		}
sl@0
   140
	}
sl@0
   141
sl@0
   142
void CFileCertStoreMapping::SetTempRemoved(TBool aFlag)
sl@0
   143
	{
sl@0
   144
	iTempRemoved=aFlag;
sl@0
   145
	}
sl@0
   146
sl@0
   147
TBool CFileCertStoreMapping::IsTempRemoved()
sl@0
   148
	{
sl@0
   149
	return iTempRemoved;
sl@0
   150
	}
sl@0
   151
sl@0
   152
#include "tadditionalstoremappings.h"
sl@0
   153
sl@0
   154
/////////////////////////////////////////////////////////////////////////////////
sl@0
   155
//CFileCertStoreMappings
sl@0
   156
/////////////////////////////////////////////////////////////////////////////////
sl@0
   157
CFileCertStoreMappings::~CFileCertStoreMappings()
sl@0
   158
	{
sl@0
   159
	if (iMappings)
sl@0
   160
		{
sl@0
   161
		iMappings->ResetAndDestroy();
sl@0
   162
		delete iMappings;
sl@0
   163
		}
sl@0
   164
	}
sl@0
   165
sl@0
   166
TInt CFileCertStoreMappings::Count()
sl@0
   167
	{
sl@0
   168
	return iMappings->Count();
sl@0
   169
	}
sl@0
   170
sl@0
   171
void CFileCertStoreMappings::AddL(CFileCertStoreMapping* aEntry)
sl@0
   172
	{
sl@0
   173
	User::LeaveIfError(iMappings->Append(aEntry));
sl@0
   174
	}
sl@0
   175
sl@0
   176
TInt CFileCertStoreMappings::Remove(const CCTCertInfo& aCertInfo)
sl@0
   177
	{
sl@0
   178
	TInt index = Index(aCertInfo);
sl@0
   179
	if (index == KErrNotFound)
sl@0
   180
		{
sl@0
   181
		return KErrNotFound;
sl@0
   182
		}
sl@0
   183
	CFileCertStoreMapping* mapping = (*iMappings)[index];
sl@0
   184
	iMappings->Remove(index);
sl@0
   185
	delete mapping;
sl@0
   186
	return KErrNone;
sl@0
   187
	}
sl@0
   188
sl@0
   189
TInt CFileCertStoreMappings::SetTempRemove(const CCTCertInfo& aCertInfo, TBool aFlag)
sl@0
   190
	{
sl@0
   191
	TInt index = Index(aCertInfo);
sl@0
   192
	if (index == KErrNotFound)
sl@0
   193
		{
sl@0
   194
		return KErrNotFound;
sl@0
   195
		}
sl@0
   196
	(*iMappings)[index]->SetTempRemoved(aFlag);
sl@0
   197
	return KErrNone;		
sl@0
   198
	}
sl@0
   199
sl@0
   200
sl@0
   201
void CFileCertStoreMappings::ExternalizeL(RWriteStream& aStream) const
sl@0
   202
	{
sl@0
   203
	TInt count = iMappings->Count();
sl@0
   204
	TInt realCount=count;
sl@0
   205
	TInt i=0;
sl@0
   206
	for (i = 0; i < count; i++)
sl@0
   207
		{
sl@0
   208
		if ((*iMappings)[i]->IsTempRemoved())
sl@0
   209
			{
sl@0
   210
			realCount--;
sl@0
   211
			}
sl@0
   212
		}
sl@0
   213
	aStream.WriteInt32L(realCount);
sl@0
   214
	for (i = 0; i < count; i++)
sl@0
   215
		{
sl@0
   216
		aStream << *(*iMappings)[i];
sl@0
   217
		}
sl@0
   218
	}
sl@0
   219
sl@0
   220
void CFileCertStoreMappings::ReplaceL()
sl@0
   221
	{
sl@0
   222
	RStoreWriteStream stream;
sl@0
   223
	stream.ReplaceLC(iStore, iStreamId);
sl@0
   224
	ExternalizeL(stream);
sl@0
   225
	stream.CommitL();
sl@0
   226
	CleanupStack::PopAndDestroy();
sl@0
   227
	}
sl@0
   228
sl@0
   229
TInt CFileCertStoreMappings::Index(const CCTCertInfo& aCertInfo)
sl@0
   230
	{
sl@0
   231
	TInt count = iMappings->Count();
sl@0
   232
	TInt ix = KErrNotFound;
sl@0
   233
	for (TInt i = 0; i < count; i++)
sl@0
   234
		{
sl@0
   235
		CFileCertStoreMapping* mapping = (*iMappings)[i];
sl@0
   236
		if (aCertInfo==*(mapping->Entry()))
sl@0
   237
			{
sl@0
   238
			ix = i;
sl@0
   239
			break;
sl@0
   240
			}
sl@0
   241
		}
sl@0
   242
	return ix;
sl@0
   243
	}
sl@0
   244
sl@0
   245
CFileCertStoreMapping* CFileCertStoreMappings::Mapping(TInt aIndex)
sl@0
   246
	{
sl@0
   247
	return (*iMappings)[aIndex];
sl@0
   248
	}
sl@0
   249
sl@0
   250
TStreamId CFileCertStoreMappings::StreamId() const
sl@0
   251
	{
sl@0
   252
	return iStreamId;
sl@0
   253
	}
sl@0
   254
sl@0
   255
CFileCertStoreMappings::CFileCertStoreMappings(TStreamId aStreamId, 
sl@0
   256
													   CPermanentFileStore& aStore)
sl@0
   257
	:iStreamId(aStreamId), iStore(aStore)
sl@0
   258
	{
sl@0
   259
	}
sl@0
   260
sl@0
   261
/////////////////////////////////////////////////////////////////////////////////
sl@0
   262
//CFileCertStoreMappings
sl@0
   263
/////////////////////////////////////////////////////////////////////////////////
sl@0
   264
CFileCertStoreMappings* CFileCertStoreMappings::NewL(TStreamId aStreamId, 
sl@0
   265
													 CPermanentFileStore& aStore)
sl@0
   266
	{
sl@0
   267
	CFileCertStoreMappings* self = new(ELeave) CFileCertStoreMappings(aStreamId, aStore);
sl@0
   268
	CleanupStack::PushL(self);
sl@0
   269
	self->ConstructL();
sl@0
   270
	CleanupStack::Pop();
sl@0
   271
	return self;
sl@0
   272
	}
sl@0
   273
sl@0
   274
const CCTCertInfo& CFileCertStoreMappings::Entry(TInt aIndex)
sl@0
   275
	{
sl@0
   276
	CFileCertStoreMapping* mapping = (*iMappings)[aIndex];
sl@0
   277
	return *mapping->Entry();
sl@0
   278
	}
sl@0
   279
sl@0
   280
const CCTCertInfo& CFileCertStoreMappings::EntryByHandleL(TInt aHandle) const
sl@0
   281
	{
sl@0
   282
	TInt count = iMappings->Count();
sl@0
   283
	for (TInt i = 0; i < count; i++)
sl@0
   284
		{
sl@0
   285
		CFileCertStoreMapping* mapping = (*iMappings)[i];
sl@0
   286
		if (aHandle==mapping->Entry()->Handle().iObjectId)
sl@0
   287
			{
sl@0
   288
			return *mapping->Entry();
sl@0
   289
			}
sl@0
   290
		}
sl@0
   291
	User::Leave(KErrNotFound);
sl@0
   292
	CCTCertInfo* info = NULL; // This is to shut up a compiler warning
sl@0
   293
	return *info;
sl@0
   294
	}
sl@0
   295
sl@0
   296
TInt CFileCertStoreMappings::NextHandle() const 
sl@0
   297
	{
sl@0
   298
	TInt count = iMappings->Count();
sl@0
   299
	TInt maxHandle = -1;
sl@0
   300
	for (TInt i = 0; i < count; i++)
sl@0
   301
		{
sl@0
   302
		CFileCertStoreMapping* mapping = (*iMappings)[i];
sl@0
   303
		if (mapping->Entry()->Handle().iObjectId > maxHandle)
sl@0
   304
			{
sl@0
   305
			maxHandle = mapping->Entry()->Handle().iObjectId;
sl@0
   306
			}
sl@0
   307
		}
sl@0
   308
	return ++maxHandle;
sl@0
   309
	}
sl@0
   310
sl@0
   311
void CFileCertStoreMappings::ConstructL()
sl@0
   312
	{
sl@0
   313
	iMappings = new(ELeave) RPointerArray<CFileCertStoreMapping>;
sl@0
   314
	}