installationservices/swi/source/securitymanager/secutils.cpp
changeset 0 ba25891c3a9e
child 12 7ca52d38f8c3
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2004-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 "secutils.h"
       
    20 #include <hash.h> 
       
    21 
       
    22 namespace Swi
       
    23 {
       
    24 
       
    25 EXPORT_C TBool SecUtils::IsExeL(const TDesC& aFileName)
       
    26 	{
       
    27 	TEntry entry;
       
    28 	EntryL(aFileName, entry);
       
    29 	return IsExe(entry);
       
    30 	}
       
    31 	
       
    32 EXPORT_C TBool SecUtils::IsDllL(const TDesC& aFileName)
       
    33 	{
       
    34 	TEntry entry;
       
    35 	EntryL(aFileName, entry);
       
    36 	return IsDll(entry);
       
    37 	}
       
    38 
       
    39 void SecUtils::EntryL(const TFileName& aFileName, TEntry& aEntry)
       
    40 	{
       
    41 	RFs fs;
       
    42 	User::LeaveIfError(fs.Connect());
       
    43 	CleanupClosePushL(fs);
       
    44 	User::LeaveIfError(fs.Entry(aFileName, aEntry));
       
    45 	CleanupStack::PopAndDestroy(&fs);
       
    46 	}
       
    47 
       
    48 EXPORT_C HBufC* SecUtils::HexHashL(const TDesC& aName)
       
    49 	{
       
    50 	CMessageDigest* digester = CMD5::NewL();
       
    51 	CleanupStack::PushL(digester);
       
    52 
       
    53 	TPtrC8 nameHash = digester->Final(TPtrC8(REINTERPRET_CAST(const TUint8*, aName.Ptr()),
       
    54 						aName.Size()));
       
    55 
       
    56 	HBufC* hashBuf = HBufC::NewL(nameHash.Length() * 2);
       
    57 	TPtr hashPtr = hashBuf->Des();
       
    58 	
       
    59 	_LIT(KHexDigit, "%02x");
       
    60 	for (TInt i = 0; i < nameHash.Length(); i++)
       
    61 		{
       
    62 		hashPtr.AppendFormat(KHexDigit, nameHash[i]);
       
    63 		}
       
    64 
       
    65 	CleanupStack::PopAndDestroy(digester);
       
    66 	return hashBuf;
       
    67 	}
       
    68 	
       
    69 } // namespace Swi