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" |
Pawel Baran | 1e2ce63 | 2022-04-19 16:31:19 | [diff] [blame] | 10 | #include "base/bind.h" |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 11 | #include "base/lazy_instance.h" |
| 12 | #include "base/rand_util.h" |
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 13 | #include "components/os_crypt/key_storage_config_linux.h" |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 14 | #include "components/os_crypt/os_crypt.h" |
| 15 | |
| 16 | namespace { |
| 17 | |
Christos Froussios | 2d15a8e | 2017-07-21 16:30:34 | [diff] [blame] | 18 | std::unique_ptr<KeyStorageLinux> CreateNewMock() { |
edchin | 3398a815 | 2022-05-16 17:23:18 | [diff] [blame] | 19 | return std::make_unique<OSCryptMockerLinux>(); |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 20 | } |
| 21 | |
edchin | 3398a815 | 2022-05-16 17:23:18 | [diff] [blame] | 22 | } |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 23 | |
edchin | 3398a815 | 2022-05-16 17:23:18 | [diff] [blame] | 24 | absl::optional<std::string> OSCryptMockerLinux::GetKeyImpl() { |
| 25 | return key_; |
| 26 | } |
| 27 | |
| 28 | std::string* OSCryptMockerLinux::GetKeyPtr() { |
| 29 | return &key_; |
| 30 | } |
| 31 | |
| 32 | // static |
Christos Froussios | 2d15a8e | 2017-07-21 16:30:34 | [diff] [blame] | 33 | void OSCryptMockerLinux::SetUp() { |
edchin | 3398a815 | 2022-05-16 17:23:18 | [diff] [blame] | 34 | OSCrypt::UseMockKeyStorageForTesting(base::BindOnce(&CreateNewMock)); |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 35 | } |
| 36 | |
edchin | 3398a815 | 2022-05-16 17:23:18 | [diff] [blame] | 37 | // static |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 38 | void OSCryptMockerLinux::TearDown() { |
edchin | 3398a815 | 2022-05-16 17:23:18 | [diff] [blame] | 39 | OSCrypt::UseMockKeyStorageForTesting(base::NullCallback()); |
| 40 | OSCrypt::ClearCacheForTesting(); |
| 41 | } |
| 42 | |
| 43 | bool OSCryptMockerLinux::Init() { |
| 44 | key_ = "the_encryption_key"; |
| 45 | return true; |
Christos Froussios | 2d15a8e | 2017-07-21 16:30:34 | [diff] [blame] | 46 | } |