|
1 /* |
|
2 * Copyright (c) 2007-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 * Note: This file may contain code to generate corrupt files for test purposes. |
|
16 * Such code is excluded from production builds by use of compiler defines; |
|
17 * it is recommended that such code should be removed if this code is ever published publicly. |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 /** |
|
23 @file |
|
24 @internalComponent |
|
25 @released |
|
26 */ |
|
27 #include <iostream> |
|
28 #include <openssl/sha.h> |
|
29 |
|
30 #include "symbiantypes.h" |
|
31 #include "sishash.h" |
|
32 |
|
33 CSISHash::CSISHash (const CSISHash& aInitialiser) : |
|
34 CStructure <CSISFieldRoot::ESISHash> (aInitialiser), |
|
35 iAlgorithm (aInitialiser.iAlgorithm), |
|
36 iBlob (aInitialiser.iBlob) |
|
37 { |
|
38 InsertMembers (); |
|
39 } |
|
40 |
|
41 |
|
42 void CSISHash::Verify (const TUint32 aLanguages) const |
|
43 |
|
44 { |
|
45 CStructure <CSISFieldRoot::ESISHash>::Verify (aLanguages); |
|
46 CSISException::ThrowIf (iAlgorithm != EHashSHA, CSISException::EVerification, "unsupported hash algorithm"); |
|
47 } |
|
48 |
|
49 |
|
50 std::string CSISHash::Name () const |
|
51 { |
|
52 return "Hash"; |
|
53 } |
|
54 |
|
55 bool CSISHash::VerifyAlgorithm () const |
|
56 { |
|
57 // Only EHashSHA supported |
|
58 if (iAlgorithm != EHashSHA) |
|
59 { |
|
60 return false; |
|
61 } |
|
62 return true; |
|
63 } |
|
64 |
|
65 void CSISHash::operator=(const CSISHash& aHash) |
|
66 { |
|
67 const TUint8* data = aHash.Blob().Data(); |
|
68 int size = aHash.Blob().Size(); |
|
69 iBlob.Assign (data, size); |
|
70 } |
|
71 |
|
72 void CSISHash::AddPackageEntry(std::wostream& aStream, bool aVerbose) const |
|
73 { |
|
74 if(aVerbose) |
|
75 { |
|
76 aStream << L"; " << ((iAlgorithm.Value()==EHashSHA)?L"SHA-1: ":L"Unknown hash: "); |
|
77 iBlob.AddPackageEntry(aStream, aVerbose); |
|
78 aStream << std::endl; |
|
79 } |
|
80 } |
|
81 |
|
82 void CSISHash::SetHash(const TUint8* aHash, TUint32 aHashSize) |
|
83 { |
|
84 iBlob.Assign(aHash, aHashSize); |
|
85 } |
|
86 |
|
87 |