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

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, 7 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 instance =
vabr (Chromium) 2016/05/23 12:38:33 nit: Please use the g_ prefix. Also, consider call
cfroussios 2016/05/30 11:50:17 Done.
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 instance.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

Powered by Google App Engine
This is Rietveld 408576698