cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 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 | |
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 7 | #include <memory> |
| 8 | |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 9 | #include "base/base64.h" |
| 10 | #include "base/lazy_instance.h" |
| 11 | #include "base/rand_util.h" |
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 12 | #include "components/os_crypt/key_storage_config_linux.h" |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 13 | #include "components/os_crypt/os_crypt.h" |
| 14 | |
| 15 | namespace { |
| 16 | |
Christos Froussios | 2d15a8e | 2017-07-21 16:30:34 | [diff] [blame] | 17 | std::unique_ptr<KeyStorageLinux> CreateNewMock() { |
Gyuyoung Kim | 8b084c0 | 2018-01-23 13:34:37 | [diff] [blame^] | 18 | return std::make_unique<OSCryptMockerLinux>(); |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 19 | } |
| 20 | |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 21 | } |
| 22 | |
Christos Froussios | 985d1aac | 2017-11-09 11:01:07 | [diff] [blame] | 23 | std::string OSCryptMockerLinux::GetKeyImpl() { |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 24 | return key_; |
| 25 | } |
| 26 | |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 27 | std::string* OSCryptMockerLinux::GetKeyPtr() { |
| 28 | return &key_; |
| 29 | } |
| 30 | |
| 31 | // static |
Christos Froussios | 2d15a8e | 2017-07-21 16:30:34 | [diff] [blame] | 32 | void OSCryptMockerLinux::SetUp() { |
| 33 | UseMockKeyStorageForTesting( |
| 34 | &CreateNewMock, nullptr /* get the key from the provider above */); |
Gyuyoung Kim | 8b084c0 | 2018-01-23 13:34:37 | [diff] [blame^] | 35 | OSCrypt::SetConfig(std::make_unique<os_crypt::Config>()); |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | // static |
| 39 | void OSCryptMockerLinux::TearDown() { |
| 40 | UseMockKeyStorageForTesting(nullptr, nullptr); |
cfroussios | f29e672 | 2017-05-10 11:23:17 | [diff] [blame] | 41 | ClearCacheForTesting(); |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 42 | } |
Christos Froussios | 2d15a8e | 2017-07-21 16:30:34 | [diff] [blame] | 43 | |
| 44 | bool OSCryptMockerLinux::Init() { |
| 45 | key_ = "the_encryption_key"; |
| 46 | return true; |
| 47 | } |