os/security/securityanddataprivacytools/securitytools/certapp/encdec/swicertstore.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/securityanddataprivacytools/securitytools/certapp/encdec/swicertstore.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,133 @@
     1.4 +/*
     1.5 +* Copyright (c) 2008-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 "swicertstore.h"
    1.23 +static const EnumEntry enumDetailsForTBool[] =
    1.24 +{
    1.25 +    { "false", false},
    1.26 +    { "true", true},
    1.27 +    { "EFalse", false},
    1.28 +    { "ETrue", true},
    1.29 +	{ 0,0 }
    1.30 +};
    1.31 +
    1.32 +EncDecContainerItem *SwiCertStoreEntry::Factory()
    1.33 +{
    1.34 +	return new SwiCertStoreEntry;
    1.35 +}
    1.36 +
    1.37 +SwiCertStoreEntry::SwiCertStoreEntry()
    1.38 +	: CertStoreEntry(true),
    1.39 +	  iCapabilitySet("CapabilitySet"), 
    1.40 +	  iTmpFlags("Mandatory/SystemUpgrade"),
    1.41 +	  iMandatory("Mandatory", enumDetailsForTBool),
    1.42 +	  iSystemUpgrade("SystemUpgrade", enumDetailsForTBool)
    1.43 +{
    1.44 +	// We only need to initialise EncDecObject members which wrap non-class types
    1.45 +	iTmpFlags.Value() = 0;
    1.46 +}
    1.47 +
    1.48 +SwiCertStoreEntry::~SwiCertStoreEntry()
    1.49 +{
    1.50 +}
    1.51 +
    1.52 +const int KMandatoryMask = 0x01;
    1.53 +const int KSystemUpgradeMask = 0x02;
    1.54 +
    1.55 +void SwiCertStoreEntry::Encode(REncodeWriteStream &aWriteStream)
    1.56 +{
    1.57 +	CertStoreEntry::Encode(aWriteStream);
    1.58 +	aWriteStream << iCapabilitySet;
    1.59 +	if(aWriteStream.HumanReadable())
    1.60 +		{
    1.61 +		// Write the Mandatory and SystemUpgrade fields
    1.62 +		aWriteStream << iMandatory;
    1.63 +		aWriteStream << iSystemUpgrade;
    1.64 +		}
    1.65 +	else
    1.66 +		{
    1.67 +		// Encode the Mandatory and SystemUpgrade values and write the binary field
    1.68 +		TUint8 tmp = 0;
    1.69 +		if(iMandatory.Value())
    1.70 +			{
    1.71 +			tmp |= KMandatoryMask;
    1.72 +			}
    1.73 +		
    1.74 +		if(iSystemUpgrade.Value())
    1.75 +			{
    1.76 +			tmp |= KSystemUpgradeMask;
    1.77 +			}
    1.78 +		
    1.79 +		iTmpFlags.Value() = tmp;
    1.80 +		aWriteStream << iTmpFlags;
    1.81 +		}
    1.82 +
    1.83 +}
    1.84 +
    1.85 +void SwiCertStoreEntry::Decode(RDecodeReadStream &aReadStream)
    1.86 +{
    1.87 +	CertStoreEntry::Decode(aReadStream);
    1.88 +	aReadStream >> iCapabilitySet;
    1.89 +
    1.90 +	if(aReadStream.HumanReadable())
    1.91 +		{
    1.92 +		// Read the Mandatory and SystemUpgrade fields
    1.93 +		if(aReadStream.PeakToken() == iMandatory.Name())
    1.94 +			{
    1.95 +			aReadStream >> iMandatory;
    1.96 +			}
    1.97 +		else
    1.98 +			{
    1.99 +			iMandatory.SetValue("false");
   1.100 +			}
   1.101 +			if(aReadStream.PeakToken() == iSystemUpgrade.Name())
   1.102 +			{
   1.103 +			aReadStream >> iSystemUpgrade;
   1.104 +			}
   1.105 +		else
   1.106 +			{
   1.107 +			iSystemUpgrade.SetValue("false");
   1.108 +			}
   1.109 +		}
   1.110 +	else
   1.111 +		{
   1.112 +		// Read the binary field and decode the Mandatory and SystemUpgrade values
   1.113 +		aReadStream >> iTmpFlags;
   1.114 +		iMandatory.SetValue((iTmpFlags.Value() & KMandatoryMask) != 0);
   1.115 +		iSystemUpgrade.SetValue((iTmpFlags.Value() & KSystemUpgradeMask) != 0);
   1.116 +		}
   1.117 +}
   1.118 +
   1.119 +SwiCertStoreEntry& SwiCertStoreEntry::operator= (const SwiCertStoreEntry& aRhs)
   1.120 +{
   1.121 +	if(this == &aRhs) return *this; // handle self assignment
   1.122 +
   1.123 +	// Copy base class members
   1.124 +	CertStoreEntry::operator=(*static_cast<const CertStoreEntry *>(&aRhs));
   1.125 +
   1.126 +	// Copy our additional members
   1.127 +	iCapabilitySet = aRhs.iCapabilitySet;
   1.128 +	// iTmpFlags does not need copying
   1.129 +	iMandatory = aRhs.iMandatory;
   1.130 +	iSystemUpgrade = aRhs.iSystemUpgrade;
   1.131 +
   1.132 +	return *this;
   1.133 +}
   1.134 +
   1.135 +
   1.136 +// End of file