os/security/cryptoservices/certificateandkeymgmt/tadditionalstores/tadditionalstoreentries.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/tadditionalstores/tadditionalstoreentries.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,314 @@
     1.4 +/*
     1.5 +* Copyright (c) 2005-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 +/**
    1.23 + @file
    1.24 +*/
    1.25 +
    1.26 +#include "tadditionalstoremapping.h"
    1.27 +
    1.28 +////////////////////////////////////////////////////////////////////////////////
    1.29 +//CFileCertStoreMapping
    1.30 +/////////////////////////////////////////////////////////////////////////////////
    1.31 +
    1.32 +CFileCertStoreMapping* CFileCertStoreMapping::NewL()
    1.33 +	{
    1.34 +	CFileCertStoreMapping* self = CFileCertStoreMapping::NewLC();
    1.35 +	CleanupStack::Pop(self);
    1.36 +	return self;
    1.37 +	}
    1.38 +
    1.39 +CFileCertStoreMapping* CFileCertStoreMapping::NewLC()
    1.40 +	{
    1.41 +	CFileCertStoreMapping* self = new(ELeave) CFileCertStoreMapping();
    1.42 +	CleanupStack::PushL(self);
    1.43 +	self->ConstructL();
    1.44 +	return self;
    1.45 +	}
    1.46 +
    1.47 +void CFileCertStoreMapping::ConstructL()
    1.48 +	{
    1.49 +	iCertificateApps = new(ELeave) RArray<TUid>();
    1.50 +	}
    1.51 +
    1.52 +CFileCertStoreMapping::CFileCertStoreMapping()
    1.53 +	{	
    1.54 +	}
    1.55 +
    1.56 +CFileCertStoreMapping::~CFileCertStoreMapping()
    1.57 +	{
    1.58 +	if (iEntry)
    1.59 +		{
    1.60 +		iEntry->Release();
    1.61 +		}
    1.62 +	if (iCertificateApps)
    1.63 +		{
    1.64 +		iCertificateApps->Close();
    1.65 +		delete iCertificateApps;
    1.66 +		}
    1.67 +	}
    1.68 +
    1.69 +void CFileCertStoreMapping::SetEntry(CCTCertInfo* aCertInfo)
    1.70 +	{
    1.71 +	if (iEntry)
    1.72 +		{
    1.73 +		iEntry->Release();
    1.74 +		}
    1.75 +	iEntry = aCertInfo;
    1.76 +	}
    1.77 +
    1.78 +void CFileCertStoreMapping::SetCertificateApps(RArray<TUid>* aCertificateApps)
    1.79 +	{
    1.80 +	iCertificateApps->Close();
    1.81 +	delete iCertificateApps;
    1.82 +	iCertificateApps = aCertificateApps;
    1.83 +	}
    1.84 +
    1.85 +void CFileCertStoreMapping::SetId(TStreamId aId)
    1.86 +	{
    1.87 +	iId = aId;
    1.88 +	}
    1.89 +
    1.90 +CCTCertInfo* CFileCertStoreMapping::Entry() const
    1.91 +	{
    1.92 +	return iEntry;
    1.93 +	}
    1.94 +
    1.95 +const RArray<TUid>& CFileCertStoreMapping::CertificateApps() const
    1.96 +	{
    1.97 +	return *iCertificateApps;
    1.98 +	}
    1.99 +
   1.100 +TBool CFileCertStoreMapping::IsApplicable(const TUid& aApplication) const
   1.101 +	{
   1.102 +	TInt count = iCertificateApps->Count();
   1.103 +	for (TInt i = 0; i < count; i++)
   1.104 +		{
   1.105 +		TUid app = (*iCertificateApps)[i];
   1.106 +		if (app == aApplication)
   1.107 +				{
   1.108 +				return ETrue;
   1.109 +				}
   1.110 +		}
   1.111 +	return EFalse;
   1.112 +	}
   1.113 +
   1.114 +TBool CFileCertStoreMapping::Trusted() const
   1.115 +	{
   1.116 +	return iTrusted;
   1.117 +	}
   1.118 +
   1.119 +void CFileCertStoreMapping::SetTrusted(TBool aTrusted)
   1.120 +	{
   1.121 +	iTrusted = aTrusted;
   1.122 +	}
   1.123 +
   1.124 +TStreamId CFileCertStoreMapping::Id() const
   1.125 +	{
   1.126 +	return iId;
   1.127 +	}
   1.128 +
   1.129 +void CFileCertStoreMapping::ExternalizeL(RWriteStream& aStream) const
   1.130 +	{
   1.131 +	if (!iTempRemoved)
   1.132 +		{
   1.133 +		aStream << *iEntry;
   1.134 +		TInt count = iCertificateApps->Count();
   1.135 +		aStream.WriteInt32L(count);
   1.136 +		for (TInt i = 0; i < count; i++)
   1.137 +			{
   1.138 +			aStream << (*iCertificateApps)[i];
   1.139 +			}
   1.140 +		aStream.WriteUint8L(iTrusted);
   1.141 +		aStream << iId;			
   1.142 +		}
   1.143 +	}
   1.144 +
   1.145 +void CFileCertStoreMapping::SetTempRemoved(TBool aFlag)
   1.146 +	{
   1.147 +	iTempRemoved=aFlag;
   1.148 +	}
   1.149 +
   1.150 +TBool CFileCertStoreMapping::IsTempRemoved()
   1.151 +	{
   1.152 +	return iTempRemoved;
   1.153 +	}
   1.154 +
   1.155 +#include "tadditionalstoremappings.h"
   1.156 +
   1.157 +/////////////////////////////////////////////////////////////////////////////////
   1.158 +//CFileCertStoreMappings
   1.159 +/////////////////////////////////////////////////////////////////////////////////
   1.160 +CFileCertStoreMappings::~CFileCertStoreMappings()
   1.161 +	{
   1.162 +	if (iMappings)
   1.163 +		{
   1.164 +		iMappings->ResetAndDestroy();
   1.165 +		delete iMappings;
   1.166 +		}
   1.167 +	}
   1.168 +
   1.169 +TInt CFileCertStoreMappings::Count()
   1.170 +	{
   1.171 +	return iMappings->Count();
   1.172 +	}
   1.173 +
   1.174 +void CFileCertStoreMappings::AddL(CFileCertStoreMapping* aEntry)
   1.175 +	{
   1.176 +	User::LeaveIfError(iMappings->Append(aEntry));
   1.177 +	}
   1.178 +
   1.179 +TInt CFileCertStoreMappings::Remove(const CCTCertInfo& aCertInfo)
   1.180 +	{
   1.181 +	TInt index = Index(aCertInfo);
   1.182 +	if (index == KErrNotFound)
   1.183 +		{
   1.184 +		return KErrNotFound;
   1.185 +		}
   1.186 +	CFileCertStoreMapping* mapping = (*iMappings)[index];
   1.187 +	iMappings->Remove(index);
   1.188 +	delete mapping;
   1.189 +	return KErrNone;
   1.190 +	}
   1.191 +
   1.192 +TInt CFileCertStoreMappings::SetTempRemove(const CCTCertInfo& aCertInfo, TBool aFlag)
   1.193 +	{
   1.194 +	TInt index = Index(aCertInfo);
   1.195 +	if (index == KErrNotFound)
   1.196 +		{
   1.197 +		return KErrNotFound;
   1.198 +		}
   1.199 +	(*iMappings)[index]->SetTempRemoved(aFlag);
   1.200 +	return KErrNone;		
   1.201 +	}
   1.202 +
   1.203 +
   1.204 +void CFileCertStoreMappings::ExternalizeL(RWriteStream& aStream) const
   1.205 +	{
   1.206 +	TInt count = iMappings->Count();
   1.207 +	TInt realCount=count;
   1.208 +	TInt i=0;
   1.209 +	for (i = 0; i < count; i++)
   1.210 +		{
   1.211 +		if ((*iMappings)[i]->IsTempRemoved())
   1.212 +			{
   1.213 +			realCount--;
   1.214 +			}
   1.215 +		}
   1.216 +	aStream.WriteInt32L(realCount);
   1.217 +	for (i = 0; i < count; i++)
   1.218 +		{
   1.219 +		aStream << *(*iMappings)[i];
   1.220 +		}
   1.221 +	}
   1.222 +
   1.223 +void CFileCertStoreMappings::ReplaceL()
   1.224 +	{
   1.225 +	RStoreWriteStream stream;
   1.226 +	stream.ReplaceLC(iStore, iStreamId);
   1.227 +	ExternalizeL(stream);
   1.228 +	stream.CommitL();
   1.229 +	CleanupStack::PopAndDestroy();
   1.230 +	}
   1.231 +
   1.232 +TInt CFileCertStoreMappings::Index(const CCTCertInfo& aCertInfo)
   1.233 +	{
   1.234 +	TInt count = iMappings->Count();
   1.235 +	TInt ix = KErrNotFound;
   1.236 +	for (TInt i = 0; i < count; i++)
   1.237 +		{
   1.238 +		CFileCertStoreMapping* mapping = (*iMappings)[i];
   1.239 +		if (aCertInfo==*(mapping->Entry()))
   1.240 +			{
   1.241 +			ix = i;
   1.242 +			break;
   1.243 +			}
   1.244 +		}
   1.245 +	return ix;
   1.246 +	}
   1.247 +
   1.248 +CFileCertStoreMapping* CFileCertStoreMappings::Mapping(TInt aIndex)
   1.249 +	{
   1.250 +	return (*iMappings)[aIndex];
   1.251 +	}
   1.252 +
   1.253 +TStreamId CFileCertStoreMappings::StreamId() const
   1.254 +	{
   1.255 +	return iStreamId;
   1.256 +	}
   1.257 +
   1.258 +CFileCertStoreMappings::CFileCertStoreMappings(TStreamId aStreamId, 
   1.259 +													   CPermanentFileStore& aStore)
   1.260 +	:iStreamId(aStreamId), iStore(aStore)
   1.261 +	{
   1.262 +	}
   1.263 +
   1.264 +/////////////////////////////////////////////////////////////////////////////////
   1.265 +//CFileCertStoreMappings
   1.266 +/////////////////////////////////////////////////////////////////////////////////
   1.267 +CFileCertStoreMappings* CFileCertStoreMappings::NewL(TStreamId aStreamId, 
   1.268 +													 CPermanentFileStore& aStore)
   1.269 +	{
   1.270 +	CFileCertStoreMappings* self = new(ELeave) CFileCertStoreMappings(aStreamId, aStore);
   1.271 +	CleanupStack::PushL(self);
   1.272 +	self->ConstructL();
   1.273 +	CleanupStack::Pop();
   1.274 +	return self;
   1.275 +	}
   1.276 +
   1.277 +const CCTCertInfo& CFileCertStoreMappings::Entry(TInt aIndex)
   1.278 +	{
   1.279 +	CFileCertStoreMapping* mapping = (*iMappings)[aIndex];
   1.280 +	return *mapping->Entry();
   1.281 +	}
   1.282 +
   1.283 +const CCTCertInfo& CFileCertStoreMappings::EntryByHandleL(TInt aHandle) const
   1.284 +	{
   1.285 +	TInt count = iMappings->Count();
   1.286 +	for (TInt i = 0; i < count; i++)
   1.287 +		{
   1.288 +		CFileCertStoreMapping* mapping = (*iMappings)[i];
   1.289 +		if (aHandle==mapping->Entry()->Handle().iObjectId)
   1.290 +			{
   1.291 +			return *mapping->Entry();
   1.292 +			}
   1.293 +		}
   1.294 +	User::Leave(KErrNotFound);
   1.295 +	CCTCertInfo* info = NULL; // This is to shut up a compiler warning
   1.296 +	return *info;
   1.297 +	}
   1.298 +
   1.299 +TInt CFileCertStoreMappings::NextHandle() const 
   1.300 +	{
   1.301 +	TInt count = iMappings->Count();
   1.302 +	TInt maxHandle = -1;
   1.303 +	for (TInt i = 0; i < count; i++)
   1.304 +		{
   1.305 +		CFileCertStoreMapping* mapping = (*iMappings)[i];
   1.306 +		if (mapping->Entry()->Handle().iObjectId > maxHandle)
   1.307 +			{
   1.308 +			maxHandle = mapping->Entry()->Handle().iObjectId;
   1.309 +			}
   1.310 +		}
   1.311 +	return ++maxHandle;
   1.312 +	}
   1.313 +
   1.314 +void CFileCertStoreMappings::ConstructL()
   1.315 +	{
   1.316 +	iMappings = new(ELeave) RPointerArray<CFileCertStoreMapping>;
   1.317 +	}