|
1 /* |
|
2 * Copyright (c) 2002 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 "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: Hashing tool |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "PEngHashTool.h" |
|
21 // #include <e32std.h> |
|
22 #include <hash.h> |
|
23 #include <imcvcodc.h> |
|
24 #include "PEngStorageGlobals.h" |
|
25 |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // PEngHashTool::HashDescriptorL() |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 HBufC* PEngHashTool::HashDescriptorL( |
|
32 const TDesC& aDesToHash ) |
|
33 { |
|
34 HBufC8* temHashBuf = HBufC8::NewLC( aDesToHash.Length() + KMinimalHashSize ); |
|
35 temHashBuf->Des().Copy( aDesToHash ); |
|
36 temHashBuf->Des().LowerCase(); |
|
37 CSHA1* sHA1 = CSHA1::NewL(); |
|
38 CleanupStack::PushL( sHA1 ); |
|
39 sHA1->Reset(); |
|
40 |
|
41 TPtrC8 hash ( sHA1->Hash( *temHashBuf ) ); |
|
42 |
|
43 TImCodecB64 b64; |
|
44 b64.Initialise(); |
|
45 |
|
46 TPtr8 encodeBuffer( temHashBuf->Des() ); |
|
47 encodeBuffer.Zero(); |
|
48 b64.Encode( hash, encodeBuffer ); |
|
49 |
|
50 HBufC* hashedId = HBufC::NewL( encodeBuffer.Length() ); |
|
51 TPtr tmp( hashedId->Des() ); |
|
52 tmp.Copy( encodeBuffer ); |
|
53 CleanupStack::PopAndDestroy( 2 ); // sHA1, temHashBuf |
|
54 |
|
55 |
|
56 ReplaceCharacterInDescriptor( tmp, '/', '_' ); |
|
57 ReplaceCharacterInDescriptor( tmp, ':', '_' ); |
|
58 ReplaceCharacterInDescriptor( tmp, '@', '_' ); |
|
59 return hashedId; |
|
60 } |
|
61 |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // PEngHashTool::HashSubfolderL() |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 HBufC* PEngHashTool::HashStateNameL( |
|
68 const TDesC& aServerAddress, |
|
69 const TDesC& aUserName ) |
|
70 { |
|
71 HBufC* address = HBufC::NewLC( aServerAddress.Length() + aUserName.Length() ); |
|
72 address->Des().Append( aServerAddress ); |
|
73 address->Des().Append( aUserName ); |
|
74 address->Des().LowerCase(); |
|
75 HBufC* folder = HashDescriptorL( *address ); |
|
76 CleanupStack::PopAndDestroy();//address |
|
77 CleanupStack::PushL( folder ); |
|
78 // KPEngStorageStateSuffix if client wants to attach some |
|
79 folder = folder->ReAllocL( folder->Length() + |
|
80 KPEngStorageStateSuffix().Length() ); |
|
81 CleanupStack::Pop(); // folder |
|
82 folder->Des().Append( KPEngStorageStateSuffix ); |
|
83 return folder; |
|
84 } |
|
85 |
|
86 |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // PEngHashTool::ReplaceCharacterInDescriptor() |
|
90 // Replace characters in descriptor with defined |
|
91 // (other items were commented in a header). |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 void PEngHashTool::ReplaceCharacterInDescriptor( |
|
95 TPtr& aDescriptor, |
|
96 const TText aConvertFrom, |
|
97 const TText aConvertTo ) |
|
98 { |
|
99 TInt offset; |
|
100 while ( ( offset = aDescriptor.Locate( aConvertFrom ) ) != KErrNotFound ) |
|
101 { |
|
102 aDescriptor[ offset ] = aConvertTo; |
|
103 } |
|
104 } |
|
105 |
|
106 |
|
107 // End of File |