Fix compilation error triggered with -Werror=sign-compare
[chromium-blink-merge.git] / chromeos / dbus / fake_cryptohome_client.h
blob6c1ea8eefb81656809dc1c0773c2f1cd49757453
1 // Copyright 2013 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.
5 #ifndef CHROMEOS_DBUS_FAKE_CRYPTOHOME_CLIENT_H_
6 #define CHROMEOS_DBUS_FAKE_CRYPTOHOME_CLIENT_H_
8 #include <map>
10 #include "base/basictypes.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chromeos/dbus/cryptohome_client.h"
14 namespace chromeos {
16 class CHROMEOS_EXPORT FakeCryptohomeClient : public CryptohomeClient {
17 public:
18 FakeCryptohomeClient();
19 virtual ~FakeCryptohomeClient();
21 virtual void Init(dbus::Bus* bus) OVERRIDE;
22 virtual void SetAsyncCallStatusHandlers(
23 const AsyncCallStatusHandler& handler,
24 const AsyncCallStatusWithDataHandler& data_handler) OVERRIDE;
25 virtual void ResetAsyncCallStatusHandlers() OVERRIDE;
26 virtual void WaitForServiceToBeAvailable(
27 const WaitForServiceToBeAvailableCallback& callback) OVERRIDE;
28 virtual void IsMounted(const BoolDBusMethodCallback& callback) OVERRIDE;
29 virtual bool Unmount(bool* success) OVERRIDE;
30 virtual void AsyncCheckKey(const std::string& username,
31 const std::string& key,
32 const AsyncMethodCallback& callback) OVERRIDE;
33 virtual void AsyncMigrateKey(const std::string& username,
34 const std::string& from_key,
35 const std::string& to_key,
36 const AsyncMethodCallback& callback) OVERRIDE;
37 virtual void AsyncRemove(const std::string& username,
38 const AsyncMethodCallback& callback) OVERRIDE;
39 virtual void GetSystemSalt(const GetSystemSaltCallback& callback) OVERRIDE;
40 virtual void GetSanitizedUsername(
41 const std::string& username,
42 const StringDBusMethodCallback& callback) OVERRIDE;
43 virtual std::string BlockingGetSanitizedUsername(
44 const std::string& username) OVERRIDE;
45 virtual void AsyncMount(const std::string& username,
46 const std::string& key,
47 int flags,
48 const AsyncMethodCallback& callback) OVERRIDE;
49 virtual void AsyncAddKey(const std::string& username,
50 const std::string& key,
51 const std::string& new_key,
52 const AsyncMethodCallback& callback) OVERRIDE;
53 virtual void AsyncMountGuest(const AsyncMethodCallback& callback) OVERRIDE;
54 virtual void AsyncMountPublic(const std::string& public_mount_id,
55 int flags,
56 const AsyncMethodCallback& callback) OVERRIDE;
57 virtual void TpmIsReady(const BoolDBusMethodCallback& callback) OVERRIDE;
58 virtual void TpmIsEnabled(const BoolDBusMethodCallback& callback) OVERRIDE;
59 virtual bool CallTpmIsEnabledAndBlock(bool* enabled) OVERRIDE;
60 virtual void TpmGetPassword(
61 const StringDBusMethodCallback& callback) OVERRIDE;
62 virtual void TpmIsOwned(const BoolDBusMethodCallback& callback) OVERRIDE;
63 virtual bool CallTpmIsOwnedAndBlock(bool* owned) OVERRIDE;
64 virtual void TpmIsBeingOwned(const BoolDBusMethodCallback& callback) OVERRIDE;
65 virtual bool CallTpmIsBeingOwnedAndBlock(bool* owning) OVERRIDE;
66 virtual void TpmCanAttemptOwnership(
67 const VoidDBusMethodCallback& callback) OVERRIDE;
68 virtual void TpmClearStoredPassword(
69 const VoidDBusMethodCallback& callback) OVERRIDE;
70 virtual bool CallTpmClearStoredPasswordAndBlock() OVERRIDE;
71 virtual void Pkcs11IsTpmTokenReady(
72 const BoolDBusMethodCallback& callback) OVERRIDE;
73 virtual void Pkcs11GetTpmTokenInfo(
74 const Pkcs11GetTpmTokenInfoCallback& callback) OVERRIDE;
75 virtual void Pkcs11GetTpmTokenInfoForUser(
76 const std::string& username,
77 const Pkcs11GetTpmTokenInfoCallback& callback) OVERRIDE;
78 virtual bool InstallAttributesGet(const std::string& name,
79 std::vector<uint8>* value,
80 bool* successful) OVERRIDE;
81 virtual bool InstallAttributesSet(const std::string& name,
82 const std::vector<uint8>& value,
83 bool* successful) OVERRIDE;
84 virtual bool InstallAttributesFinalize(bool* successful) OVERRIDE;
85 virtual void InstallAttributesIsReady(
86 const BoolDBusMethodCallback& callback) OVERRIDE;
87 virtual bool InstallAttributesIsInvalid(bool* is_invalid) OVERRIDE;
88 virtual bool InstallAttributesIsFirstInstall(bool* is_first_install) OVERRIDE;
89 virtual void TpmAttestationIsPrepared(
90 const BoolDBusMethodCallback& callback) OVERRIDE;
91 virtual void TpmAttestationIsEnrolled(
92 const BoolDBusMethodCallback& callback) OVERRIDE;
93 virtual void AsyncTpmAttestationCreateEnrollRequest(
94 chromeos::attestation::PrivacyCAType pca_type,
95 const AsyncMethodCallback& callback) OVERRIDE;
96 virtual void AsyncTpmAttestationEnroll(
97 chromeos::attestation::PrivacyCAType pca_type,
98 const std::string& pca_response,
99 const AsyncMethodCallback& callback) OVERRIDE;
100 virtual void AsyncTpmAttestationCreateCertRequest(
101 chromeos::attestation::PrivacyCAType pca_type,
102 attestation::AttestationCertificateProfile certificate_profile,
103 const std::string& user_id,
104 const std::string& request_origin,
105 const AsyncMethodCallback& callback) OVERRIDE;
106 virtual void AsyncTpmAttestationFinishCertRequest(
107 const std::string& pca_response,
108 attestation::AttestationKeyType key_type,
109 const std::string& user_id,
110 const std::string& key_name,
111 const AsyncMethodCallback& callback) OVERRIDE;
112 virtual void TpmAttestationDoesKeyExist(
113 attestation::AttestationKeyType key_type,
114 const std::string& user_id,
115 const std::string& key_name,
116 const BoolDBusMethodCallback& callback) OVERRIDE;
117 virtual void TpmAttestationGetCertificate(
118 attestation::AttestationKeyType key_type,
119 const std::string& user_id,
120 const std::string& key_name,
121 const DataMethodCallback& callback) OVERRIDE;
122 virtual void TpmAttestationGetPublicKey(
123 attestation::AttestationKeyType key_type,
124 const std::string& user_id,
125 const std::string& key_name,
126 const DataMethodCallback& callback) OVERRIDE;
127 virtual void TpmAttestationRegisterKey(
128 attestation::AttestationKeyType key_type,
129 const std::string& user_id,
130 const std::string& key_name,
131 const AsyncMethodCallback& callback) OVERRIDE;
132 virtual void TpmAttestationSignEnterpriseChallenge(
133 attestation::AttestationKeyType key_type,
134 const std::string& user_id,
135 const std::string& key_name,
136 const std::string& domain,
137 const std::string& device_id,
138 attestation::AttestationChallengeOptions options,
139 const std::string& challenge,
140 const AsyncMethodCallback& callback) OVERRIDE;
141 virtual void TpmAttestationSignSimpleChallenge(
142 attestation::AttestationKeyType key_type,
143 const std::string& user_id,
144 const std::string& key_name,
145 const std::string& challenge,
146 const AsyncMethodCallback& callback) OVERRIDE;
147 virtual void TpmAttestationGetKeyPayload(
148 attestation::AttestationKeyType key_type,
149 const std::string& user_id,
150 const std::string& key_name,
151 const DataMethodCallback& callback) OVERRIDE;
152 virtual void TpmAttestationSetKeyPayload(
153 attestation::AttestationKeyType key_type,
154 const std::string& user_id,
155 const std::string& key_name,
156 const std::string& payload,
157 const BoolDBusMethodCallback& callback) OVERRIDE;
158 virtual void TpmAttestationDeleteKeys(
159 attestation::AttestationKeyType key_type,
160 const std::string& user_id,
161 const std::string& key_prefix,
162 const BoolDBusMethodCallback& callback) OVERRIDE;
163 virtual void CheckKeyEx(
164 const cryptohome::AccountIdentifier& id,
165 const cryptohome::AuthorizationRequest& auth,
166 const cryptohome::CheckKeyRequest& request,
167 const ProtobufMethodCallback& callback) OVERRIDE;
168 virtual void MountEx(
169 const cryptohome::AccountIdentifier& id,
170 const cryptohome::AuthorizationRequest& auth,
171 const cryptohome::MountRequest& request,
172 const ProtobufMethodCallback& callback) OVERRIDE;
173 virtual void AddKeyEx(
174 const cryptohome::AccountIdentifier& id,
175 const cryptohome::AuthorizationRequest& auth,
176 const cryptohome::AddKeyRequest& request,
177 const ProtobufMethodCallback& callback) OVERRIDE;
178 virtual void UpdateKeyEx(
179 const cryptohome::AccountIdentifier& id,
180 const cryptohome::AuthorizationRequest& auth,
181 const cryptohome::UpdateKeyRequest& request,
182 const ProtobufMethodCallback& callback) OVERRIDE;
183 virtual void RemoveKeyEx(const cryptohome::AccountIdentifier& id,
184 const cryptohome::AuthorizationRequest& auth,
185 const cryptohome::RemoveKeyRequest& request,
186 const ProtobufMethodCallback& callback) OVERRIDE;
188 // Changes the behavior of WaitForServiceToBeAvailable(). This method runs
189 // pending callbacks if is_available is true.
190 void SetServiceIsAvailable(bool is_available);
192 // Sets the unmount result of Unmount() call.
193 void set_unmount_result(bool result) {
194 unmount_result_= result;
197 // Sets the system salt which will be returned from GetSystemSalt(). By
198 // default, GetSystemSalt() returns the value generated by
199 // GetStubSystemSalt().
200 void set_system_salt(const std::vector<uint8>& system_salt) {
201 system_salt_ = system_salt;
204 // Returns the stub system salt as raw bytes. (not as a string encoded in the
205 // format used by SystemSaltGetter::ConvertRawSaltToHexString()).
206 static std::vector<uint8> GetStubSystemSalt();
208 private:
209 // Posts tasks which return fake results to the UI thread.
210 void ReturnAsyncMethodResult(const AsyncMethodCallback& callback,
211 bool returns_data);
213 // This method is used to implement ReturnAsyncMethodResult.
214 void ReturnAsyncMethodResultInternal(const AsyncMethodCallback& callback,
215 bool returns_data);
217 void ReturnProtobufMethodCallback(const std::string& user_id,
218 const ProtobufMethodCallback& callback);
220 bool service_is_available_;
221 int async_call_id_;
222 AsyncCallStatusHandler async_call_status_handler_;
223 AsyncCallStatusWithDataHandler async_call_status_data_handler_;
224 int tpm_is_ready_counter_;
225 bool unmount_result_;
226 std::vector<uint8> system_salt_;
228 std::vector<WaitForServiceToBeAvailableCallback>
229 pending_wait_for_service_to_be_available_callbacks_;
231 // A stub store for InstallAttributes, mapping an attribute name to the
232 // associated data blob. Used to implement InstallAttributesSet and -Get.
233 std::map<std::string, std::vector<uint8> > install_attrs_;
234 bool locked_;
235 base::WeakPtrFactory<FakeCryptohomeClient> weak_ptr_factory_;
237 DISALLOW_COPY_AND_ASSIGN(FakeCryptohomeClient);
240 } // namespace chromeos
242 #endif // CHROMEOS_DBUS_FAKE_CRYPTOHOME_CLIENT_H_