unexportable_key.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (c) 2021 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 "crypto/unexportable_key.h"
  5. #include "base/check.h"
  6. #include "build/build_config.h"
  7. namespace crypto {
  8. UnexportableSigningKey::~UnexportableSigningKey() = default;
  9. UnexportableKeyProvider::~UnexportableKeyProvider() = default;
  10. #if BUILDFLAG(IS_WIN)
  11. std::unique_ptr<UnexportableKeyProvider> GetUnexportableKeyProviderWin();
  12. #endif
  13. static std::unique_ptr<UnexportableKeyProvider> (*g_mock_provider)() = nullptr;
  14. std::unique_ptr<UnexportableKeyProvider> GetUnexportableKeyProvider() {
  15. if (g_mock_provider) {
  16. return g_mock_provider();
  17. }
  18. #if BUILDFLAG(IS_WIN)
  19. return GetUnexportableKeyProviderWin();
  20. #else
  21. return nullptr;
  22. #endif
  23. }
  24. namespace internal {
  25. void SetUnexportableKeyProviderForTesting(
  26. std::unique_ptr<UnexportableKeyProvider> (*func)()) {
  27. if (g_mock_provider) {
  28. // Nesting ScopedMockUnexportableSigningKeyForTesting is not supported.
  29. CHECK(!func);
  30. g_mock_provider = nullptr;
  31. } else {
  32. g_mock_provider = func;
  33. }
  34. }
  35. } // namespace internal
  36. } // namespace crypto