os/security/cryptoservices/certificateandkeymgmt/swicertstore/CSWICertStoreEntryList.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.
     1 /*
     2 * Copyright (c) 2004-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 #include "CSWICertStoreEntryList.h"
    20 #include "CSWICertStoreEntry.h"
    21 #include <cctcertinfo.h>
    22 
    23 CSWICertStoreEntryList* CSWICertStoreEntryList::NewL(RReadStream& aStream, MCTToken& aToken, TInt aCertIndex, TInt aStoreIndex)
    24 	{
    25 	CSWICertStoreEntryList* self = new(ELeave) CSWICertStoreEntryList();
    26 	CleanupStack::PushL(self);
    27 	self->InternalizeL(aStream, aToken, aCertIndex, aStoreIndex);
    28 	CleanupStack::Pop(self);
    29 	return self;
    30 	}
    31 
    32 CSWICertStoreEntryList* CSWICertStoreEntryList::NewL()
    33 	{
    34 	CSWICertStoreEntryList* self = new(ELeave) CSWICertStoreEntryList();
    35 	return self;
    36 	}
    37 
    38 CSWICertStoreEntryList::CSWICertStoreEntryList()
    39 	{
    40 	}
    41 
    42 CSWICertStoreEntryList::~CSWICertStoreEntryList()
    43 	{
    44 	iEntries.ResetAndDestroy();
    45 	iEntries.Close();
    46 	}
    47 
    48 void CSWICertStoreEntryList::InternalizeL(RReadStream& aStream, MCTToken& aToken, TInt aCertIndex, TInt aStoreIndex)
    49 	{
    50 	TInt count = aStream.ReadInt32L();
    51 	
    52 	for (TInt i = 0 ; i < count ; ++i)
    53 		{
    54 		CSWICertStoreEntry* entry = CSWICertStoreEntry::NewLC(aStream, aToken, aCertIndex+i, aStoreIndex);
    55 		iEntries.AppendL(entry);
    56 		CleanupStack::Pop(entry);		
    57 		}
    58 	}
    59 
    60 TInt CSWICertStoreEntryList::Count() const
    61 	{
    62 	return iEntries.Count();
    63 	}
    64 
    65 TBool CSWICertStoreEntryList::LabelExists(const TDesC& aLabel) const
    66 	{
    67 	TInt count = iEntries.Count();
    68 	for (TInt i = 0 ; i < count ; ++i)
    69 		{
    70 		CSWICertStoreEntry* entry = iEntries[i];
    71 		if (entry->CertInfo().Label() == aLabel)
    72 			{
    73 			return ETrue;
    74 			}
    75 		}
    76 	return EFalse;
    77 	}
    78 
    79 TInt CSWICertStoreEntryList::AppendL(CSWICertStoreEntry* aCertInfo)
    80 	{
    81 	User::LeaveIfError(iEntries.Append(aCertInfo));
    82 	return iEntries.Count() - 1;
    83 	}
    84 
    85 void CSWICertStoreEntryList::Remove(TInt aIndex)
    86 	{
    87 	CSWICertStoreEntry* entry = iEntries[aIndex];
    88 	iEntries.Remove(aIndex);
    89 	delete entry;
    90 	}
    91 
    92 const CSWICertStoreEntry& CSWICertStoreEntryList::GetByIndex(TInt aIndex) const
    93 	{
    94 	return *iEntries[aIndex];
    95 	}
    96 
    97 const CSWICertStoreEntry& CSWICertStoreEntryList::GetByHandleL(const TCTTokenObjectHandle& aHandle) const
    98 	{
    99 	TInt index = KErrNotFound;
   100 	
   101 	for (TInt i = 0 ; i < iEntries.Count() ; ++i)
   102 		{
   103 		CSWICertStoreEntry* entry = iEntries[i];
   104 		if (aHandle == entry->CertInfo().Handle())
   105 			{
   106 			index = i;
   107 			break;
   108 			}
   109 		}
   110 
   111 	User::LeaveIfError(index);
   112 	return GetByIndex(index);
   113 	}