os/security/cryptoservices/certificateandkeymgmt/swicertstore/CSWICertStoreEntry.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) 1998-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 "CSWICertStoreEntry.h"
    20 #include <cctcertinfo.h>
    21 
    22 CSWICertStoreEntry* CSWICertStoreEntry::NewLC(RReadStream& aStream, MCTToken& aToken, TInt aCertIndex, TInt aStoreIndex)
    23 	{
    24 	CSWICertStoreEntry* self = new(ELeave) CSWICertStoreEntry(aStoreIndex);
    25 	CleanupStack::PushL(self);
    26 	
    27 	self->InternalizeL(aStream, aToken, aCertIndex);
    28 	return self;
    29 	}
    30 
    31 CSWICertStoreEntry* CSWICertStoreEntry::NewL(const CCTCertInfo& aCertInfo,const RArray<TUid>& aCertificateApps,TBool aTrusted,TStreamId aDataStreamId,const TCertMetaInfo& aCertMetaInfo, TInt aStoreIndex)
    32 	{
    33 	CSWICertStoreEntry* self = new(ELeave) CSWICertStoreEntry(aStoreIndex);
    34 	CleanupStack::PushL(self);
    35 	self->ConstructL(aCertInfo, aCertificateApps, aTrusted, aDataStreamId, aCertMetaInfo);
    36 	CleanupStack::Pop(self);
    37 	return self;
    38 	}	
    39 	
    40 void CSWICertStoreEntry::ConstructL(const CCTCertInfo& aCertInfo,const RArray<TUid>& aCertificateApps,TBool aTrusted,TStreamId aDataStreamId, const TCertMetaInfo& aCertMetaInfo)
    41 	{
    42 	iCertInfo = CCTCertInfo::NewL(aCertInfo);
    43 	
    44 	for (TInt i = 0 ; i < aCertificateApps.Count() ; ++i)
    45 		{
    46 		iCertificateApps.AppendL(aCertificateApps[i]);
    47 		}
    48 
    49 	iTrusted = aTrusted;	
    50 	iDataStreamId = aDataStreamId;
    51 	iCertMetaInfo = aCertMetaInfo; 
    52 	}	
    53 
    54 TInt CSWICertStoreEntry::StoreIndex() const
    55 	{
    56 	return iStoreIndex;
    57 	}
    58 
    59 CSWICertStoreEntry::CSWICertStoreEntry(TInt aStoreIndex):iStoreIndex(aStoreIndex)
    60 	{	
    61 	}
    62 
    63 CSWICertStoreEntry::~CSWICertStoreEntry()
    64 	{
    65 	if (iCertInfo)
    66 		{
    67 		iCertInfo->Release();
    68 		}
    69 	iCertificateApps.Close();
    70 	}
    71 
    72 void CSWICertStoreEntry::InternalizeL(RReadStream& aStream, MCTToken& aToken, TInt aCertIndex)
    73 	{
    74 	ASSERT(!iCertInfo);
    75 	iCertInfo = CCTCertInfo::NewL(aStream, aToken);
    76 	iCertInfo->SetCertificateId(aCertIndex);
    77 
    78 	TInt count = aStream.ReadInt32L();
    79 	for (TInt i = 0 ; i < count ; ++i)
    80 		{
    81 		TUid id;
    82 		aStream >> id;
    83 		User::LeaveIfError(iCertificateApps.Append(id));
    84 		}
    85 	
    86 	iTrusted = !!aStream.ReadUint8L();  // !! converts TUint8 to TBool
    87 	aStream >> iDataStreamId;
    88 	TPckg<TCapabilitySet> capsPckg(iCertMetaInfo.iCapabilities);
    89 	aStream >> capsPckg;
    90 	TUint8 value = aStream.ReadUint8L();
    91 	iCertMetaInfo.iIsMandatory = !!(value & (1 << KMandatory)); // !! converts TUint8 to TBool
    92 	iCertMetaInfo.iIsSystemUpgrade = !!(value & (1 << KSystemUpgrade));
    93 	}
    94 
    95 const CCTCertInfo& CSWICertStoreEntry::CertInfo() const
    96 	{
    97 	return *iCertInfo;
    98 	}
    99 
   100 const RArray<TUid>& CSWICertStoreEntry::CertificateApps() const
   101 	{
   102 	return iCertificateApps;
   103 	}
   104 
   105 TBool CSWICertStoreEntry::IsApplicable(const TUid& aApplication) const
   106 	{
   107 	for (TInt i = 0 ; i < iCertificateApps.Count() ; ++i)
   108 		{
   109 		if (iCertificateApps[i] == aApplication)
   110 				{
   111 				return ETrue;
   112 				}
   113 		}
   114 	return EFalse;
   115 	}
   116 
   117 TBool CSWICertStoreEntry::Trusted() const
   118 	{
   119 	return iTrusted;
   120 	}
   121 
   122 TStreamId CSWICertStoreEntry::DataStreamId() const
   123 	{
   124 	return iDataStreamId;
   125 	}
   126 
   127 const TCertMetaInfo& CSWICertStoreEntry::CertMetaInfo() const
   128 	{
   129 	return iCertMetaInfo;	
   130 	}
   131 
   132