Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/os_crypt/os_crypt_mocker_linux.h" | |
| 6 | |
| 7 #include "base/base64.h" | |
| 8 #include "base/rand_util.h" | |
| 9 #include "components/os_crypt/os_crypt.h" | |
| 10 | |
| 11 namespace { | |
|
Lei Zhang
2016/05/20 21:15:33
Add blank line after.
cfroussios
2016/05/23 09:31:22
Done.
| |
| 12 KeyStorageLinux* GetKeyStorage() { | |
| 13 return OSCryptMockerLinux::GetInstance(); | |
| 14 } | |
| 15 | |
| 16 std::string* GetPassword() { | |
| 17 return OSCryptMockerLinux::GetInstance()->GetKeyPtr(); | |
| 18 } | |
| 19 } | |
|
Lei Zhang
2016/05/20 21:15:33
Add blank line before, add // namespace
cfroussios
2016/05/23 09:31:22
Done.
| |
| 20 | |
| 21 std::string OSCryptMockerLinux::GetKey() { | |
| 22 if (key_.empty()) | |
| 23 base::Base64Encode(base::RandBytesAsString(16), &key_); | |
| 24 return key_; | |
| 25 } | |
| 26 | |
| 27 bool OSCryptMockerLinux::Init() { | |
| 28 return true; | |
| 29 } | |
| 30 | |
| 31 void OSCryptMockerLinux::ResetTo(base::StringPiece new_key) { | |
| 32 key_ = new_key.as_string(); | |
| 33 } | |
| 34 | |
| 35 std::string* OSCryptMockerLinux::GetKeyPtr() { | |
| 36 return &key_; | |
| 37 } | |
| 38 | |
| 39 // static | |
| 40 OSCryptMockerLinux* OSCryptMockerLinux::GetInstance() { | |
| 41 return base::Singleton<OSCryptMockerLinux>::get(); | |
|
Lei Zhang
2016/05/20 21:15:33
Can we use a lazy instance instead? See comment in
cfroussios
2016/05/23 09:31:22
Done.
| |
| 42 } | |
| 43 | |
| 44 // static | |
| 45 void OSCryptMockerLinux::SetUpWithSingleton() { | |
| 46 UseMockKeyStorageForTesting(&GetKeyStorage, &GetPassword); | |
| 47 } | |
| 48 | |
| 49 // static | |
| 50 void OSCryptMockerLinux::TearDown() { | |
| 51 UseMockKeyStorageForTesting(nullptr, nullptr); | |
| 52 } | |
| OLD | NEW |