os_crypt_mocker_linux.cc 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #include "components/os_crypt/os_crypt_mocker_linux.h"
  5. #include <memory>
  6. #include "base/base64.h"
  7. #include "base/bind.h"
  8. #include "base/lazy_instance.h"
  9. #include "base/rand_util.h"
  10. #include "components/os_crypt/key_storage_config_linux.h"
  11. #include "components/os_crypt/os_crypt.h"
  12. namespace {
  13. std::unique_ptr<KeyStorageLinux> CreateNewMock() {
  14. return std::make_unique<OSCryptMockerLinux>();
  15. }
  16. }
  17. absl::optional<std::string> OSCryptMockerLinux::GetKeyImpl() {
  18. return key_;
  19. }
  20. std::string* OSCryptMockerLinux::GetKeyPtr() {
  21. return &key_;
  22. }
  23. // static
  24. void OSCryptMockerLinux::SetUp() {
  25. OSCrypt::UseMockKeyStorageForTesting(base::BindOnce(&CreateNewMock));
  26. }
  27. // static
  28. void OSCryptMockerLinux::TearDown() {
  29. OSCrypt::UseMockKeyStorageForTesting(base::NullCallback());
  30. OSCrypt::ClearCacheForTesting();
  31. }
  32. bool OSCryptMockerLinux::Init() {
  33. key_ = "the_encryption_key";
  34. return true;
  35. }