os_crypt_mocker_linux.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #ifndef COMPONENTS_OS_CRYPT_OS_CRYPT_MOCKER_LINUX_H_
  5. #define COMPONENTS_OS_CRYPT_OS_CRYPT_MOCKER_LINUX_H_
  6. #include <string>
  7. #include "base/strings/string_piece.h"
  8. #include "components/os_crypt/key_storage_linux.h"
  9. #include "third_party/abseil-cpp/absl/types/optional.h"
  10. // Holds and serves a password from memory.
  11. class OSCryptMockerLinux : public KeyStorageLinux {
  12. public:
  13. OSCryptMockerLinux() = default;
  14. OSCryptMockerLinux(const OSCryptMockerLinux&) = delete;
  15. OSCryptMockerLinux& operator=(const OSCryptMockerLinux&) = delete;
  16. ~OSCryptMockerLinux() override = default;
  17. // Get a pointer to the stored password. OSCryptMockerLinux owns the pointer.
  18. std::string* GetKeyPtr();
  19. // Inject the mocking scheme into OSCrypt.
  20. static void SetUp();
  21. // Restore OSCrypt to its real behaviour.
  22. static void TearDown();
  23. protected:
  24. // KeyStorageLinux
  25. bool Init() override;
  26. absl::optional<std::string> GetKeyImpl() override;
  27. private:
  28. std::string key_;
  29. };
  30. #endif // COMPONENTS_OS_CRYPT_OS_CRYPT_MOCKER_LINUX_H_