secureswitools/swisistools/source/interpretsislib/controllerinfo.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2006-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 #ifdef _MSC_VER
       
    20 #pragma warning (disable: 4786)
       
    21 #endif // _MSC_VER
       
    22 
       
    23 // System Includes
       
    24 #include <iostream>
       
    25 #include <openssl/sha.h>
       
    26 // User includes
       
    27 #include "controllerinfo.h"
       
    28 #include "deserialiser.h"
       
    29 #include "serialiser.h"
       
    30 
       
    31 // SisX includes
       
    32 #include "siscontroller.h"
       
    33 
       
    34 
       
    35 ControllerInfo::~ControllerInfo ()
       
    36 	{
       
    37 	}
       
    38 
       
    39 void ControllerInfo::Internalize(Deserialiser& des)
       
    40 	{
       
    41 	des >> iVersion >> iOffset >> iHashContainer;
       
    42 	}
       
    43 void ControllerInfo::Externalize(Serialiser& ser)
       
    44 	{
       
    45 	ser << iVersion << iOffset << iHashContainer;
       
    46 	}
       
    47 
       
    48 void ControllerInfo::CalculateAndSetHash(const CSISController& aController, 
       
    49 										TUint16 aRegFileMajorVersion, 
       
    50 										TUint16 aRegFileMinorVersion)
       
    51 	{
       
    52 	unsigned char hash[SHA_DIGEST_LENGTH];
       
    53 	memset(hash, 0, SHA_DIGEST_LENGTH);
       
    54 	
       
    55 	const unsigned char* buffer = aController.RawBuffer();
       
    56 
       
    57 	SHA_CTX  ctx;
       
    58 	SHA1_Init(&ctx);
       
    59 	if(aRegFileMajorVersion > 5 || (aRegFileMajorVersion == 5 && aRegFileMinorVersion > 1))
       
    60 		{
       
    61 		int controllerLength = aController.ControllerSizeForHash();
       
    62 		SHA1_Update(&ctx, buffer, controllerLength);
       
    63 		}
       
    64 	else
       
    65 		{
       
    66 		int controllerLength = aController.RawBufferSize();
       
    67 		SHA1_Update(&ctx, &controllerLength, 4);
       
    68 		SHA1_Update(&ctx, buffer, controllerLength);
       
    69 		}
       
    70 	SHA1_Final(hash,&ctx);
       
    71 	
       
    72 	std::string hashStr((char*)hash, SHA_DIGEST_LENGTH);
       
    73 	iHashContainer.SetData(hashStr);
       
    74 	iHashContainer.SetHashId(HashContainer::EHashSHA);
       
    75 	}
       
    76 
       
    77 
       
    78 #ifdef _MSC_VER
       
    79 
       
    80 Deserialiser& operator>>(Deserialiser& aInput, std::vector<ControllerInfo*>& val)
       
    81 	{
       
    82 	TUint32 size = 0;
       
    83 	aInput>> size;
       
    84 	val.resize(size);
       
    85 	for (TUint32 i = 0; i < size ; ++i)
       
    86 		{
       
    87 		val[i] = new ControllerInfo;
       
    88 		aInput >> *val[i];
       
    89 		}
       
    90 	return aInput;
       
    91 	}
       
    92 #endif