fake_secure_message_delegate.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2015 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 ASH_COMPONENTS_MULTIDEVICE_FAKE_SECURE_MESSAGE_DELEGATE_H_
  5. #define ASH_COMPONENTS_MULTIDEVICE_FAKE_SECURE_MESSAGE_DELEGATE_H_
  6. #include <memory>
  7. #include "ash/components/multidevice/secure_message_delegate.h"
  8. #include "ash/components/multidevice/secure_message_delegate_impl.h"
  9. namespace ash::multidevice {
  10. // Fake implementation of SecureMessageDelegate used in tests.
  11. // For clarity in tests, all functions in this delegate will invoke their
  12. // callback with the result before returning.
  13. class FakeSecureMessageDelegate : public SecureMessageDelegate {
  14. public:
  15. FakeSecureMessageDelegate();
  16. FakeSecureMessageDelegate(const FakeSecureMessageDelegate&) = delete;
  17. FakeSecureMessageDelegate& operator=(const FakeSecureMessageDelegate&) =
  18. delete;
  19. ~FakeSecureMessageDelegate() override;
  20. // SecureMessageDelegate:
  21. void GenerateKeyPair(GenerateKeyPairCallback callback) override;
  22. void DeriveKey(const std::string& private_key,
  23. const std::string& public_key,
  24. DeriveKeyCallback callback) override;
  25. void CreateSecureMessage(const std::string& payload,
  26. const std::string& key,
  27. const CreateOptions& create_options,
  28. CreateSecureMessageCallback callback) override;
  29. void UnwrapSecureMessage(const std::string& serialized_message,
  30. const std::string& key,
  31. const UnwrapOptions& unwrap_options,
  32. UnwrapSecureMessageCallback callback) override;
  33. // Returns the corresponding private key for the given |public_key|.
  34. std::string GetPrivateKeyForPublicKey(const std::string& public_key);
  35. // Sets the next public key to be returned by GenerateKeyPair(). The
  36. // corresponding private key will be derived from this public key.
  37. void set_next_public_key(const std::string& public_key) {
  38. next_public_key_ = public_key;
  39. }
  40. private:
  41. std::string next_public_key_;
  42. };
  43. class FakeSecureMessageDelegateFactory
  44. : public multidevice::SecureMessageDelegateImpl::Factory {
  45. public:
  46. FakeSecureMessageDelegateFactory() = default;
  47. FakeSecureMessageDelegateFactory(const FakeSecureMessageDelegateFactory&) =
  48. delete;
  49. FakeSecureMessageDelegateFactory& operator=(
  50. const FakeSecureMessageDelegateFactory&) = delete;
  51. ~FakeSecureMessageDelegateFactory() override = default;
  52. multidevice::FakeSecureMessageDelegate* instance() { return instance_; }
  53. private:
  54. // multidevice::SecureMessageDelegateImpl::Factory:
  55. std::unique_ptr<multidevice::SecureMessageDelegate> CreateInstance() override;
  56. multidevice::FakeSecureMessageDelegate* instance_ = nullptr;
  57. };
  58. } // namespace ash::multidevice
  59. #endif // ASH_COMPONENTS_MULTIDEVICE_FAKE_SECURE_MESSAGE_DELEGATE_H_