OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/component_updater/component_patcher_operation.h" | 5 #include "components/component_updater/component_patcher_operation.h" |
6 | 6 |
| 7 #include <stdint.h> |
7 #include <vector> | 8 #include <vector> |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
11 #include "base/files/memory_mapped_file.h" | 12 #include "base/files/memory_mapped_file.h" |
12 #include "base/location.h" | 13 #include "base/location.h" |
13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
14 #include "components/component_updater/component_patcher.h" | 15 #include "components/component_updater/component_patcher.h" |
15 #include "components/component_updater/component_updater_service.h" | 16 #include "components/component_updater/component_updater_service.h" |
16 #include "courgette/courgette.h" | 17 #include "courgette/courgette.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 if (error == ComponentUnpacker::kNone) | 101 if (error == ComponentUnpacker::kNone) |
101 error = CheckHash(); | 102 error = CheckHash(); |
102 task_runner_->PostTask(FROM_HERE, | 103 task_runner_->PostTask(FROM_HERE, |
103 base::Bind(callback_, error, extended_error)); | 104 base::Bind(callback_, error, extended_error)); |
104 callback_.Reset(); | 105 callback_.Reset(); |
105 } | 106 } |
106 | 107 |
107 // Uses the hash as a checksum to confirm that the file now residing in the | 108 // Uses the hash as a checksum to confirm that the file now residing in the |
108 // output directory probably has the contents it should. | 109 // output directory probably has the contents it should. |
109 ComponentUnpacker::Error DeltaUpdateOp::CheckHash() { | 110 ComponentUnpacker::Error DeltaUpdateOp::CheckHash() { |
110 std::vector<uint8> expected_hash; | 111 std::vector<uint8_t> expected_hash; |
111 if (!base::HexStringToBytes(output_sha256_, &expected_hash) || | 112 if (!base::HexStringToBytes(output_sha256_, &expected_hash) || |
112 expected_hash.size() != crypto::kSHA256Length) | 113 expected_hash.size() != crypto::kSHA256Length) |
113 return ComponentUnpacker::kDeltaVerificationFailure; | 114 return ComponentUnpacker::kDeltaVerificationFailure; |
114 | 115 |
115 base::MemoryMappedFile output_file_mmapped; | 116 base::MemoryMappedFile output_file_mmapped; |
116 if (!output_file_mmapped.Initialize(output_abs_path_)) | 117 if (!output_file_mmapped.Initialize(output_abs_path_)) |
117 return ComponentUnpacker::kDeltaVerificationFailure; | 118 return ComponentUnpacker::kDeltaVerificationFailure; |
118 | 119 |
119 uint8 actual_hash[crypto::kSHA256Length] = {0}; | 120 uint8_t actual_hash[crypto::kSHA256Length] = {0}; |
120 const scoped_ptr<SecureHash> hasher(SecureHash::Create(SecureHash::SHA256)); | 121 const scoped_ptr<SecureHash> hasher(SecureHash::Create(SecureHash::SHA256)); |
121 hasher->Update(output_file_mmapped.data(), output_file_mmapped.length()); | 122 hasher->Update(output_file_mmapped.data(), output_file_mmapped.length()); |
122 hasher->Finish(actual_hash, sizeof(actual_hash)); | 123 hasher->Finish(actual_hash, sizeof(actual_hash)); |
123 if (memcmp(actual_hash, &expected_hash[0], sizeof(actual_hash))) | 124 if (memcmp(actual_hash, &expected_hash[0], sizeof(actual_hash))) |
124 return ComponentUnpacker::kDeltaVerificationFailure; | 125 return ComponentUnpacker::kDeltaVerificationFailure; |
125 | 126 |
126 return ComponentUnpacker::kNone; | 127 return ComponentUnpacker::kNone; |
127 } | 128 } |
128 | 129 |
129 scoped_refptr<base::SequencedTaskRunner> DeltaUpdateOp::GetTaskRunner() { | 130 scoped_refptr<base::SequencedTaskRunner> DeltaUpdateOp::GetTaskRunner() { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 } else { | 257 } else { |
257 callback.Run(ComponentUnpacker::kDeltaOperationFailure, | 258 callback.Run(ComponentUnpacker::kDeltaOperationFailure, |
258 result + kCourgetteErrorOffset); | 259 result + kCourgetteErrorOffset); |
259 } | 260 } |
260 } else { | 261 } else { |
261 NOTREACHED(); | 262 NOTREACHED(); |
262 } | 263 } |
263 } | 264 } |
264 | 265 |
265 } // namespace component_updater | 266 } // namespace component_updater |
OLD | NEW |