diff -r 000000000000 -r ba25891c3a9e secureswitools/swisistools/source/sisxlibrary/checksum.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/secureswitools/swisistools/source/sisxlibrary/checksum.h Thu Dec 17 08:51:10 2009 +0200 @@ -0,0 +1,138 @@ +/* +* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Note: This file may contain code to generate corrupt files for test purposes. +* Such code is excluded from production builds by use of compiler defines; +* it is recommended that such code should be removed if this code is ever published publicly. +* generic base for all SIS checksums +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __CHECKSUM_H__ +#define __CHECKSUM_H__ + +#include "structure.h" +#include "numeric.h" + +#include + + +template class CChecksum : public CStructure + { +public: + /** + * Default constructor + */ + CChecksum (const bool aRequired = true); + /** + * Copy Constructor + */ + CChecksum (const CChecksum& aInitialiser); + +public: + /** + * Class name + */ + virtual std::string Name () const; + /** + * Checks if the structure is required or not. Used for externalizing + * the class. If its a waste of space then we need not write this into + * the file. + */ + virtual bool WasteOfSpace () const; +#ifdef GENERATE_ERRORS + virtual void CreateDefects (); +#endif // GENERATE_ERRORS + /** + * Set the CRC value + * @param aCrc new CRC value + */ + void Set (const TCRC aCrc); + /** + * Adds the write the package details into the stream. + * @param aStream - Stream in which the package entries need to be written. + * @param aVerbose - If this option is set then detail description of pkg + * will be written into the stream. + */ + void AddPackageEntry(std::wostream& aStream, bool aVerbose) const; + +private: + CSISUInt16 iDataChecksum; + }; + + +template inline + CChecksum ::CChecksum (const bool aRequired) : + CStructure (aRequired) + { + InsertMember (iDataChecksum); + } + +template inline + CChecksum ::CChecksum (const CChecksum& aInitialiser) : + CStructure (aInitialiser), + iDataChecksum (aInitialiser.iDataChecksum) + { + InsertMember (iDataChecksum); + } + +template inline + std::string CChecksum ::Name () const + { + return "Checksum"; + } + +template inline + void CChecksum ::Set (const TCRC aCrc) + { + iDataChecksum = aCrc; + } + + +template inline + bool CChecksum ::WasteOfSpace () const + { + return iDataChecksum.Value()? false: true; + } + + +#ifdef GENERATE_ERRORS +template + void CChecksum ::CreateDefects () + { + if (IsBugToBeCreated (CSISFieldRoot::EBugCRCError)) + { + iDataChecksum |= static_cast (rand () & 0xFFFF); + } + } +#endif // GENERATE_ERRORS + +template inline + void CChecksum ::AddPackageEntry(std::wostream& aStream, bool aVerbose) const + { + if(aVerbose) + { + aStream << L"; CRC16: " << std::hex << iDataChecksum.Value() << std::dec << std::endl; + } + } + +#endif // __SISDATACHECKSUM_H__ +