OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/os_crypt/os_crypt.h" | 5 #include "components/os_crypt/os_crypt.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <iterator> | 10 #include <iterator> |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 } | 211 } |
212 | 212 |
213 // static | 213 // static |
214 void OSCrypt::SetStore(const std::string& store_type) { | 214 void OSCrypt::SetStore(const std::string& store_type) { |
215 // Changing the targeted password store makes no sense after initializing. | 215 // Changing the targeted password store makes no sense after initializing. |
216 DCHECK(!g_cache.Get().is_key_storage_cached); | 216 DCHECK(!g_cache.Get().is_key_storage_cached); |
217 | 217 |
218 KeyStorageLinux::SetStore(store_type); | 218 KeyStorageLinux::SetStore(store_type); |
219 } | 219 } |
220 | 220 |
| 221 // static |
| 222 void OSCrypt::SetProductName(const std::string& product_name) { |
| 223 // Setting the product name makes no sense after initializing. |
| 224 DCHECK(!g_cache.Get().is_key_storage_cached); |
| 225 |
| 226 KeyStorageLinux::SetProductName(product_name); |
| 227 } |
| 228 |
221 void UseMockKeyStorageForTesting(KeyStorageLinux* (*get_key_storage_mock)(), | 229 void UseMockKeyStorageForTesting(KeyStorageLinux* (*get_key_storage_mock)(), |
222 std::string* (*get_password_v11_mock)()) { | 230 std::string* (*get_password_v11_mock)()) { |
223 // Save the real implementation to restore it later. | 231 // Save the real implementation to restore it later. |
224 static bool is_get_password_saved = false; | 232 static bool is_get_password_saved = false; |
225 static std::string* (*get_password_save[arraysize(g_get_password)])(); | 233 static std::string* (*get_password_save[arraysize(g_get_password)])(); |
226 if (!is_get_password_saved) { | 234 if (!is_get_password_saved) { |
227 std::copy(std::begin(g_get_password), std::end(g_get_password), | 235 std::copy(std::begin(g_get_password), std::end(g_get_password), |
228 std::begin(get_password_save)); | 236 std::begin(get_password_save)); |
229 is_get_password_saved = true; | 237 is_get_password_saved = true; |
230 } | 238 } |
231 | 239 |
232 if (get_key_storage_mock && get_password_v11_mock) { | 240 if (get_key_storage_mock && get_password_v11_mock) { |
233 // Bypass calling KeyStorage::CreateService and caching of the key for V11 | 241 // Bypass calling KeyStorage::CreateService and caching of the key for V11 |
234 g_get_password[Version::V11] = get_password_v11_mock; | 242 g_get_password[Version::V11] = get_password_v11_mock; |
235 // OSCrypt will determine the encryption version by checking if a | 243 // OSCrypt will determine the encryption version by checking if a |
236 // |KeyStorage| instance can be created. Enable V11 by returning the mock. | 244 // |KeyStorage| instance can be created. Enable V11 by returning the mock. |
237 g_key_storage_provider = get_key_storage_mock; | 245 g_key_storage_provider = get_key_storage_mock; |
238 } else { | 246 } else { |
239 // Restore real implementation | 247 // Restore real implementation |
240 std::copy(std::begin(get_password_save), std::end(get_password_save), | 248 std::copy(std::begin(get_password_save), std::end(get_password_save), |
241 std::begin(g_get_password)); | 249 std::begin(g_get_password)); |
242 } | 250 } |
243 } | 251 } |
OLD | NEW |