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

Unified 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: More fix for non-linux 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 side-by-side diff with in-line comments
Download patch
Index: components/os_crypt/os_crypt_mocker_linux.cc
diff --git a/components/os_crypt/os_crypt_mocker_linux.cc b/components/os_crypt/os_crypt_mocker_linux.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cedd3b048cc1f2d4cfa5af8d85108c2c104aa530
--- /dev/null
+++ b/components/os_crypt/os_crypt_mocker_linux.cc
@@ -0,0 +1,52 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/os_crypt/os_crypt_mocker_linux.h"
+
+#include "base/base64.h"
+#include "base/rand_util.h"
+#include "components/os_crypt/os_crypt.h"
+
+namespace {
Lei Zhang 2016/05/20 21:15:33 Add blank line after.
cfroussios 2016/05/23 09:31:22 Done.
+KeyStorageLinux* GetKeyStorage() {
+ return OSCryptMockerLinux::GetInstance();
+}
+
+std::string* GetPassword() {
+ return OSCryptMockerLinux::GetInstance()->GetKeyPtr();
+}
+}
Lei Zhang 2016/05/20 21:15:33 Add blank line before, add // namespace
cfroussios 2016/05/23 09:31:22 Done.
+
+std::string OSCryptMockerLinux::GetKey() {
+ if (key_.empty())
+ base::Base64Encode(base::RandBytesAsString(16), &key_);
+ return key_;
+}
+
+bool OSCryptMockerLinux::Init() {
+ return true;
+}
+
+void OSCryptMockerLinux::ResetTo(base::StringPiece new_key) {
+ key_ = new_key.as_string();
+}
+
+std::string* OSCryptMockerLinux::GetKeyPtr() {
+ return &key_;
+}
+
+// static
+OSCryptMockerLinux* OSCryptMockerLinux::GetInstance() {
+ return base::Singleton<OSCryptMockerLinux>::get();
Lei Zhang 2016/05/20 21:15:33 Can we use a lazy instance instead? See comment in
cfroussios 2016/05/23 09:31:22 Done.
+}
+
+// static
+void OSCryptMockerLinux::SetUpWithSingleton() {
+ UseMockKeyStorageForTesting(&GetKeyStorage, &GetPassword);
+}
+
+// static
+void OSCryptMockerLinux::TearDown() {
+ UseMockKeyStorageForTesting(nullptr, nullptr);
+}

Powered by Google App Engine
This is Rietveld 408576698