os_crypt_mocker.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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.h"
  5. #include "build/build_config.h"
  6. #include "components/os_crypt/os_crypt.h"
  7. #if defined(USE_LIBSECRET) || defined(USE_KEYRING) || defined(USE_KWALLET)
  8. #include "components/os_crypt/os_crypt_mocker_linux.h"
  9. #endif
  10. // static
  11. void OSCryptMocker::SetUp() {
  12. #if BUILDFLAG(IS_APPLE)
  13. OSCrypt::UseMockKeychainForTesting(true);
  14. #elif defined(USE_LIBSECRET) || defined(USE_KEYRING) || defined(USE_KWALLET)
  15. OSCryptMockerLinux::SetUp();
  16. #elif BUILDFLAG(IS_WIN)
  17. OSCrypt::UseMockKeyForTesting(true);
  18. #endif
  19. }
  20. #if BUILDFLAG(IS_APPLE)
  21. // static
  22. void OSCryptMocker::SetBackendLocked(bool locked) {
  23. OSCrypt::UseLockedMockKeychainForTesting(locked);
  24. }
  25. #endif
  26. #if BUILDFLAG(IS_WIN)
  27. // static
  28. void OSCryptMocker::SetLegacyEncryption(bool legacy) {
  29. OSCrypt::SetLegacyEncryptionForTesting(legacy);
  30. }
  31. void OSCryptMocker::ResetState() {
  32. OSCrypt::ResetStateForTesting();
  33. }
  34. #endif
  35. // static
  36. void OSCryptMocker::TearDown() {
  37. #if BUILDFLAG(IS_APPLE)
  38. OSCrypt::UseMockKeychainForTesting(false);
  39. #elif defined(USE_LIBSECRET) || defined(USE_KEYRING) || defined(USE_KWALLET)
  40. OSCryptMockerLinux::TearDown();
  41. #elif BUILDFLAG(IS_WIN)
  42. OSCrypt::UseMockKeyForTesting(false);
  43. #endif
  44. }