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 "chrome/browser/extensions/updater/local_extension_cache.h" | 5 #include "chrome/browser/extensions/updater/local_extension_cache.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } | 91 } |
92 | 92 |
93 std::string CreateSignedExtensionFile(const base::FilePath& dir, | 93 std::string CreateSignedExtensionFile(const base::FilePath& dir, |
94 const std::string& id, | 94 const std::string& id, |
95 const std::string& version, | 95 const std::string& version, |
96 size_t size, | 96 size_t size, |
97 const base::Time& timestamp, | 97 const base::Time& timestamp, |
98 base::FilePath* filename) { | 98 base::FilePath* filename) { |
99 std::string data(size, 0); | 99 std::string data(size, 0); |
100 | 100 |
101 crypto::SecureHash* hash = | 101 std::unique_ptr<crypto::SecureHash> hash = |
102 crypto::SecureHash::Create(crypto::SecureHash::SHA256); | 102 crypto::SecureHash::Create(crypto::SecureHash::SHA256); |
103 hash->Update(data.c_str(), size); | 103 hash->Update(data.c_str(), size); |
104 uint8_t output[crypto::kSHA256Length]; | 104 uint8_t output[crypto::kSHA256Length]; |
105 hash->Finish(output, sizeof(output)); | 105 hash->Finish(output, sizeof(output)); |
106 const std::string hex_hash = | 106 const std::string hex_hash = |
107 base::ToLowerASCII(base::HexEncode(output, sizeof(output))); | 107 base::ToLowerASCII(base::HexEncode(output, sizeof(output))); |
108 delete hash; | |
109 | 108 |
110 const base::FilePath file = | 109 const base::FilePath file = |
111 GetExtensionFileName(dir, id, version, hex_hash); | 110 GetExtensionFileName(dir, id, version, hex_hash); |
112 if (filename) | 111 if (filename) |
113 *filename = file; | 112 *filename = file; |
114 EXPECT_EQ(base::WriteFile(file, data.data(), data.size()), int(size)); | 113 EXPECT_EQ(base::WriteFile(file, data.data(), data.size()), int(size)); |
115 EXPECT_TRUE(base::TouchFile(file, timestamp, timestamp)); | 114 EXPECT_TRUE(base::TouchFile(file, timestamp, timestamp)); |
116 | 115 |
117 return hex_hash; | 116 return hex_hash; |
118 } | 117 } |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 const base::FilePath hashed2 = | 479 const base::FilePath hashed2 = |
481 GetExtensionFileName(cache_dir, kTestExtensionId1, "3.0", hash4); | 480 GetExtensionFileName(cache_dir, kTestExtensionId1, "3.0", hash4); |
482 EXPECT_TRUE(base::PathExists(hashed2)); | 481 EXPECT_TRUE(base::PathExists(hashed2)); |
483 EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash4, NULL, NULL)); | 482 EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash4, NULL, NULL)); |
484 // Old file kept | 483 // Old file kept |
485 EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash3, NULL, NULL)); | 484 EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash3, NULL, NULL)); |
486 EXPECT_TRUE(base::DeleteFile(temp7, false)); | 485 EXPECT_TRUE(base::DeleteFile(temp7, false)); |
487 } | 486 } |
488 | 487 |
489 } // namespace extensions | 488 } // namespace extensions |
OLD | NEW |