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