securityanddataprivacytools/securitytools/certapp/encdec/swicertstore.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2008-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 "swicertstore.h"
       
    20 static const EnumEntry enumDetailsForTBool[] =
       
    21 {
       
    22     { "false", false},
       
    23     { "true", true},
       
    24     { "EFalse", false},
       
    25     { "ETrue", true},
       
    26 	{ 0,0 }
       
    27 };
       
    28 
       
    29 EncDecContainerItem *SwiCertStoreEntry::Factory()
       
    30 {
       
    31 	return new SwiCertStoreEntry;
       
    32 }
       
    33 
       
    34 SwiCertStoreEntry::SwiCertStoreEntry()
       
    35 	: CertStoreEntry(true),
       
    36 	  iCapabilitySet("CapabilitySet"), 
       
    37 	  iTmpFlags("Mandatory/SystemUpgrade"),
       
    38 	  iMandatory("Mandatory", enumDetailsForTBool),
       
    39 	  iSystemUpgrade("SystemUpgrade", enumDetailsForTBool)
       
    40 {
       
    41 	// We only need to initialise EncDecObject members which wrap non-class types
       
    42 	iTmpFlags.Value() = 0;
       
    43 }
       
    44 
       
    45 SwiCertStoreEntry::~SwiCertStoreEntry()
       
    46 {
       
    47 }
       
    48 
       
    49 const int KMandatoryMask = 0x01;
       
    50 const int KSystemUpgradeMask = 0x02;
       
    51 
       
    52 void SwiCertStoreEntry::Encode(REncodeWriteStream &aWriteStream)
       
    53 {
       
    54 	CertStoreEntry::Encode(aWriteStream);
       
    55 	aWriteStream << iCapabilitySet;
       
    56 	if(aWriteStream.HumanReadable())
       
    57 		{
       
    58 		// Write the Mandatory and SystemUpgrade fields
       
    59 		aWriteStream << iMandatory;
       
    60 		aWriteStream << iSystemUpgrade;
       
    61 		}
       
    62 	else
       
    63 		{
       
    64 		// Encode the Mandatory and SystemUpgrade values and write the binary field
       
    65 		TUint8 tmp = 0;
       
    66 		if(iMandatory.Value())
       
    67 			{
       
    68 			tmp |= KMandatoryMask;
       
    69 			}
       
    70 		
       
    71 		if(iSystemUpgrade.Value())
       
    72 			{
       
    73 			tmp |= KSystemUpgradeMask;
       
    74 			}
       
    75 		
       
    76 		iTmpFlags.Value() = tmp;
       
    77 		aWriteStream << iTmpFlags;
       
    78 		}
       
    79 
       
    80 }
       
    81 
       
    82 void SwiCertStoreEntry::Decode(RDecodeReadStream &aReadStream)
       
    83 {
       
    84 	CertStoreEntry::Decode(aReadStream);
       
    85 	aReadStream >> iCapabilitySet;
       
    86 
       
    87 	if(aReadStream.HumanReadable())
       
    88 		{
       
    89 		// Read the Mandatory and SystemUpgrade fields
       
    90 		if(aReadStream.PeakToken() == iMandatory.Name())
       
    91 			{
       
    92 			aReadStream >> iMandatory;
       
    93 			}
       
    94 		else
       
    95 			{
       
    96 			iMandatory.SetValue("false");
       
    97 			}
       
    98 			if(aReadStream.PeakToken() == iSystemUpgrade.Name())
       
    99 			{
       
   100 			aReadStream >> iSystemUpgrade;
       
   101 			}
       
   102 		else
       
   103 			{
       
   104 			iSystemUpgrade.SetValue("false");
       
   105 			}
       
   106 		}
       
   107 	else
       
   108 		{
       
   109 		// Read the binary field and decode the Mandatory and SystemUpgrade values
       
   110 		aReadStream >> iTmpFlags;
       
   111 		iMandatory.SetValue((iTmpFlags.Value() & KMandatoryMask) != 0);
       
   112 		iSystemUpgrade.SetValue((iTmpFlags.Value() & KSystemUpgradeMask) != 0);
       
   113 		}
       
   114 }
       
   115 
       
   116 SwiCertStoreEntry& SwiCertStoreEntry::operator= (const SwiCertStoreEntry& aRhs)
       
   117 {
       
   118 	if(this == &aRhs) return *this; // handle self assignment
       
   119 
       
   120 	// Copy base class members
       
   121 	CertStoreEntry::operator=(*static_cast<const CertStoreEntry *>(&aRhs));
       
   122 
       
   123 	// Copy our additional members
       
   124 	iCapabilitySet = aRhs.iCapabilitySet;
       
   125 	// iTmpFlags does not need copying
       
   126 	iMandatory = aRhs.iMandatory;
       
   127 	iSystemUpgrade = aRhs.iSystemUpgrade;
       
   128 
       
   129 	return *this;
       
   130 }
       
   131 
       
   132 
       
   133 // End of file