[M120 Migration][VD] Enable direct rendering for TVPlus
[platform/framework/web/chromium-efl.git] / components / ownership / mock_owner_key_util.h
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_OWNERSHIP_MOCK_OWNER_KEY_UTIL_H_
6 #define COMPONENTS_OWNERSHIP_MOCK_OWNER_KEY_UTIL_H_
7
8 #include <stdint.h>
9
10 #include <memory>
11 #include <vector>
12
13 #include "base/compiler_specific.h"
14 #include "components/ownership/owner_key_util.h"
15 #include "components/ownership/ownership_export.h"
16
17 namespace crypto {
18 class RSAPrivateKey;
19 }
20
21 namespace ownership {
22
23 // Implementation of OwnerKeyUtil which should be used only for
24 // testing.
25 class OWNERSHIP_EXPORT MockOwnerKeyUtil : public OwnerKeyUtil {
26  public:
27   MockOwnerKeyUtil();
28
29   MockOwnerKeyUtil(const MockOwnerKeyUtil&) = delete;
30   MockOwnerKeyUtil& operator=(const MockOwnerKeyUtil&) = delete;
31
32   // OwnerKeyUtil implementation:
33   scoped_refptr<PublicKey> ImportPublicKey() override;
34   crypto::ScopedSECKEYPrivateKey GenerateKeyPair(PK11SlotInfo* slot) override;
35   crypto::ScopedSECKEYPrivateKey FindPrivateKeyInSlot(
36       const std::vector<uint8_t>& key,
37       PK11SlotInfo* slot) override;
38   bool IsPublicKeyPresent() override;
39
40   // Clears the public and private keys.
41   void Clear();
42
43   // Configures the mock to return the given public key.
44   void SetPublicKey(const std::vector<uint8_t>& key);
45
46   // Sets the public key to use from the given private key, but doesn't
47   // configure the private key.
48   void SetPublicKeyFromPrivateKey(const crypto::RSAPrivateKey& key);
49
50   // Imports the private key into NSS, so it can be found later.
51   // Also extracts the public key and sets it for this mock object (equivalent
52   // to calling `SetPublicKeyFromPrivateKey`).
53   void ImportPrivateKeyAndSetPublicKey(
54       std::unique_ptr<crypto::RSAPrivateKey> key);
55
56   // Makes next `fail_times` number of calls to OwnerKeyUtil::GenerateKeyPair
57   // fail.
58   void SimulateGenerateKeyFailure(int fail_times);
59
60  private:
61   ~MockOwnerKeyUtil() override;
62
63   int generate_key_fail_times_ = 0;
64   std::vector<uint8_t> public_key_;
65   crypto::ScopedSECKEYPrivateKey private_key_;
66 };
67
68 }  // namespace ownership
69
70 #endif  // COMPONENTS_OWNERSHIP_MOCK_OWNER_KEY_UTIL_H_