mock_owner_key_util.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright (c) 2012 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_OWNERSHIP_MOCK_OWNER_KEY_UTIL_H_
  5. #define COMPONENTS_OWNERSHIP_MOCK_OWNER_KEY_UTIL_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include <vector>
  9. #include "base/compiler_specific.h"
  10. #include "components/ownership/owner_key_util.h"
  11. #include "components/ownership/ownership_export.h"
  12. namespace crypto {
  13. class RSAPrivateKey;
  14. }
  15. namespace ownership {
  16. // Implementation of OwnerKeyUtil which should be used only for
  17. // testing.
  18. class OWNERSHIP_EXPORT MockOwnerKeyUtil : public OwnerKeyUtil {
  19. public:
  20. MockOwnerKeyUtil();
  21. MockOwnerKeyUtil(const MockOwnerKeyUtil&) = delete;
  22. MockOwnerKeyUtil& operator=(const MockOwnerKeyUtil&) = delete;
  23. // OwnerKeyUtil implementation:
  24. bool ImportPublicKey(std::vector<uint8_t>* output) override;
  25. crypto::ScopedSECKEYPrivateKey FindPrivateKeyInSlot(
  26. const std::vector<uint8_t>& key,
  27. PK11SlotInfo* slot) override;
  28. bool IsPublicKeyPresent() override;
  29. // Clears the public and private keys.
  30. void Clear();
  31. // Configures the mock to return the given public key.
  32. void SetPublicKey(const std::vector<uint8_t>& key);
  33. // Sets the public key to use from the given private key, but doesn't
  34. // configure the private key.
  35. void SetPublicKeyFromPrivateKey(const crypto::RSAPrivateKey& key);
  36. // Sets the private key (also configures the public key).
  37. void SetPrivateKey(std::unique_ptr<crypto::RSAPrivateKey> key);
  38. private:
  39. ~MockOwnerKeyUtil() override;
  40. std::vector<uint8_t> public_key_;
  41. crypto::ScopedSECKEYPrivateKey private_key_;
  42. };
  43. } // namespace ownership
  44. #endif // COMPONENTS_OWNERSHIP_MOCK_OWNER_KEY_UTIL_H_