blob: 37d5cf7c87750ebbc444d6a238667fd5c7e66e6a [file] [log] [blame]
cfroussios3b5a4e42016-05-31 11:02:181// 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 Froussios494196d2017-07-14 10:10:047#include <memory>
8
cfroussios3b5a4e42016-05-31 11:02:189#include "base/base64.h"
10#include "base/lazy_instance.h"
11#include "base/rand_util.h"
Christos Froussios494196d2017-07-14 10:10:0412#include "components/os_crypt/key_storage_config_linux.h"
cfroussios3b5a4e42016-05-31 11:02:1813#include "components/os_crypt/os_crypt.h"
14
15namespace {
16
Christos Froussios2d15a8e2017-07-21 16:30:3417std::unique_ptr<KeyStorageLinux> CreateNewMock() {
Gyuyoung Kim8b084c02018-01-23 13:34:3718 return std::make_unique<OSCryptMockerLinux>();
cfroussios3b5a4e42016-05-31 11:02:1819}
20
cfroussios3b5a4e42016-05-31 11:02:1821}
22
Christos Froussios985d1aac2017-11-09 11:01:0723std::string OSCryptMockerLinux::GetKeyImpl() {
cfroussios3b5a4e42016-05-31 11:02:1824 return key_;
25}
26
cfroussios3b5a4e42016-05-31 11:02:1827std::string* OSCryptMockerLinux::GetKeyPtr() {
28 return &key_;
29}
30
31// static
Christos Froussios2d15a8e2017-07-21 16:30:3432void OSCryptMockerLinux::SetUp() {
33 UseMockKeyStorageForTesting(
34 &CreateNewMock, nullptr /* get the key from the provider above */);
Gyuyoung Kim8b084c02018-01-23 13:34:3735 OSCrypt::SetConfig(std::make_unique<os_crypt::Config>());
cfroussios3b5a4e42016-05-31 11:02:1836}
37
38// static
39void OSCryptMockerLinux::TearDown() {
40 UseMockKeyStorageForTesting(nullptr, nullptr);
cfroussiosf29e6722017-05-10 11:23:1741 ClearCacheForTesting();
cfroussios3b5a4e42016-05-31 11:02:1842}
Christos Froussios2d15a8e2017-07-21 16:30:3443
44bool OSCryptMockerLinux::Init() {
45 key_ = "the_encryption_key";
46 return true;
47}