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" |
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 11 | #include "base/memory/ptr_util.h" |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 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() { |
| 19 | return base::MakeUnique<OSCryptMockerLinux>(); |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 20 | } |
| 21 | |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 22 | } |
| 23 | |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 24 | std::string OSCryptMockerLinux::GetKey() { |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 25 | return key_; |
| 26 | } |
| 27 | |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 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() { |
| 34 | UseMockKeyStorageForTesting( |
| 35 | &CreateNewMock, nullptr /* get the key from the provider above */); |
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 36 | OSCrypt::SetConfig(base::MakeUnique<os_crypt::Config>()); |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | // static |
| 40 | void OSCryptMockerLinux::TearDown() { |
| 41 | UseMockKeyStorageForTesting(nullptr, nullptr); |
cfroussios | f29e672 | 2017-05-10 11:23:17 | [diff] [blame] | 42 | ClearCacheForTesting(); |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 43 | } |
Christos Froussios | 2d15a8e | 2017-07-21 16:30:34 | [diff] [blame^] | 44 | |
| 45 | bool OSCryptMockerLinux::Init() { |
| 46 | key_ = "the_encryption_key"; |
| 47 | return true; |
| 48 | } |