os/security/cryptoservices/certificateandkeymgmt/swicertstore/CSWICertStoreEntryList.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/swicertstore/CSWICertStoreEntryList.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,113 @@
     1.4 +/*
     1.5 +* Copyright (c) 2004-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 +#include "CSWICertStoreEntryList.h"
    1.23 +#include "CSWICertStoreEntry.h"
    1.24 +#include <cctcertinfo.h>
    1.25 +
    1.26 +CSWICertStoreEntryList* CSWICertStoreEntryList::NewL(RReadStream& aStream, MCTToken& aToken, TInt aCertIndex, TInt aStoreIndex)
    1.27 +	{
    1.28 +	CSWICertStoreEntryList* self = new(ELeave) CSWICertStoreEntryList();
    1.29 +	CleanupStack::PushL(self);
    1.30 +	self->InternalizeL(aStream, aToken, aCertIndex, aStoreIndex);
    1.31 +	CleanupStack::Pop(self);
    1.32 +	return self;
    1.33 +	}
    1.34 +
    1.35 +CSWICertStoreEntryList* CSWICertStoreEntryList::NewL()
    1.36 +	{
    1.37 +	CSWICertStoreEntryList* self = new(ELeave) CSWICertStoreEntryList();
    1.38 +	return self;
    1.39 +	}
    1.40 +
    1.41 +CSWICertStoreEntryList::CSWICertStoreEntryList()
    1.42 +	{
    1.43 +	}
    1.44 +
    1.45 +CSWICertStoreEntryList::~CSWICertStoreEntryList()
    1.46 +	{
    1.47 +	iEntries.ResetAndDestroy();
    1.48 +	iEntries.Close();
    1.49 +	}
    1.50 +
    1.51 +void CSWICertStoreEntryList::InternalizeL(RReadStream& aStream, MCTToken& aToken, TInt aCertIndex, TInt aStoreIndex)
    1.52 +	{
    1.53 +	TInt count = aStream.ReadInt32L();
    1.54 +	
    1.55 +	for (TInt i = 0 ; i < count ; ++i)
    1.56 +		{
    1.57 +		CSWICertStoreEntry* entry = CSWICertStoreEntry::NewLC(aStream, aToken, aCertIndex+i, aStoreIndex);
    1.58 +		iEntries.AppendL(entry);
    1.59 +		CleanupStack::Pop(entry);		
    1.60 +		}
    1.61 +	}
    1.62 +
    1.63 +TInt CSWICertStoreEntryList::Count() const
    1.64 +	{
    1.65 +	return iEntries.Count();
    1.66 +	}
    1.67 +
    1.68 +TBool CSWICertStoreEntryList::LabelExists(const TDesC& aLabel) const
    1.69 +	{
    1.70 +	TInt count = iEntries.Count();
    1.71 +	for (TInt i = 0 ; i < count ; ++i)
    1.72 +		{
    1.73 +		CSWICertStoreEntry* entry = iEntries[i];
    1.74 +		if (entry->CertInfo().Label() == aLabel)
    1.75 +			{
    1.76 +			return ETrue;
    1.77 +			}
    1.78 +		}
    1.79 +	return EFalse;
    1.80 +	}
    1.81 +
    1.82 +TInt CSWICertStoreEntryList::AppendL(CSWICertStoreEntry* aCertInfo)
    1.83 +	{
    1.84 +	User::LeaveIfError(iEntries.Append(aCertInfo));
    1.85 +	return iEntries.Count() - 1;
    1.86 +	}
    1.87 +
    1.88 +void CSWICertStoreEntryList::Remove(TInt aIndex)
    1.89 +	{
    1.90 +	CSWICertStoreEntry* entry = iEntries[aIndex];
    1.91 +	iEntries.Remove(aIndex);
    1.92 +	delete entry;
    1.93 +	}
    1.94 +
    1.95 +const CSWICertStoreEntry& CSWICertStoreEntryList::GetByIndex(TInt aIndex) const
    1.96 +	{
    1.97 +	return *iEntries[aIndex];
    1.98 +	}
    1.99 +
   1.100 +const CSWICertStoreEntry& CSWICertStoreEntryList::GetByHandleL(const TCTTokenObjectHandle& aHandle) const
   1.101 +	{
   1.102 +	TInt index = KErrNotFound;
   1.103 +	
   1.104 +	for (TInt i = 0 ; i < iEntries.Count() ; ++i)
   1.105 +		{
   1.106 +		CSWICertStoreEntry* entry = iEntries[i];
   1.107 +		if (aHandle == entry->CertInfo().Handle())
   1.108 +			{
   1.109 +			index = i;
   1.110 +			break;
   1.111 +			}
   1.112 +		}
   1.113 +
   1.114 +	User::LeaveIfError(index);
   1.115 +	return GetByIndex(index);
   1.116 +	}