Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: components/os_crypt/os_crypt_mocker_linux.cc

Issue 1973483002: OSCrypt for POSIX uses libsecret to store a randomised encryption key. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Recommendations Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/lazy_instance.h"
9 #include "base/rand_util.h"
10 #include "components/os_crypt/os_crypt.h"
11
12 namespace {
13
14 static base::LazyInstance<OSCryptMockerLinux>::Leaky g_mocker =
15 LAZY_INSTANCE_INITIALIZER;
16
17 KeyStorageLinux* GetKeyStorage() {
18 return OSCryptMockerLinux::GetInstance();
19 }
20
21 std::string* GetPassword() {
22 return OSCryptMockerLinux::GetInstance()->GetKeyPtr();
23 }
24
25 } // namespace
26
27 std::string OSCryptMockerLinux::GetKey() {
28 if (key_.empty())
29 base::Base64Encode(base::RandBytesAsString(16), &key_);
30 return key_;
31 }
32
33 bool OSCryptMockerLinux::Init() {
34 return true;
35 }
36
37 void OSCryptMockerLinux::ResetTo(base::StringPiece new_key) {
38 key_ = new_key.as_string();
39 }
40
41 std::string* OSCryptMockerLinux::GetKeyPtr() {
42 return &key_;
43 }
44
45 // static
46 OSCryptMockerLinux* OSCryptMockerLinux::GetInstance() {
47 return g_mocker.Pointer();
48 }
49
50 // static
51 void OSCryptMockerLinux::SetUpWithSingleton() {
52 UseMockKeyStorageForTesting(&GetKeyStorage, &GetPassword);
53 }
54
55 // static
56 void OSCryptMockerLinux::TearDown() {
57 UseMockKeyStorageForTesting(nullptr, nullptr);
58 }
OLDNEW
« no previous file with comments | « components/os_crypt/os_crypt_mocker_linux.h ('k') | components/os_crypt/os_crypt_util_linux_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698