OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/dbus/fake_cryptohome_client.h" | 5 #include "chromeos/dbus/fake_cryptohome_client.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include "base/bind.h" | 10 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
9 #include "base/location.h" | 12 #include "base/location.h" |
10 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
11 #include "base/path_service.h" | 14 #include "base/path_service.h" |
12 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
13 #include "chromeos/chromeos_paths.h" | 16 #include "chromeos/chromeos_paths.h" |
14 #include "chromeos/dbus/cryptohome/key.pb.h" | 17 #include "chromeos/dbus/cryptohome/key.pb.h" |
15 #include "chromeos/dbus/cryptohome/rpc.pb.h" | 18 #include "chromeos/dbus/cryptohome/rpc.pb.h" |
16 #include "third_party/cros_system_api/dbus/service_constants.h" | 19 #include "third_party/cros_system_api/dbus/service_constants.h" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 kStubSlot)); | 227 kStubSlot)); |
225 } | 228 } |
226 | 229 |
227 void FakeCryptohomeClient::Pkcs11GetTpmTokenInfoForUser( | 230 void FakeCryptohomeClient::Pkcs11GetTpmTokenInfoForUser( |
228 const std::string& username, | 231 const std::string& username, |
229 const Pkcs11GetTpmTokenInfoCallback& callback) { | 232 const Pkcs11GetTpmTokenInfoCallback& callback) { |
230 Pkcs11GetTpmTokenInfo(callback); | 233 Pkcs11GetTpmTokenInfo(callback); |
231 } | 234 } |
232 | 235 |
233 bool FakeCryptohomeClient::InstallAttributesGet(const std::string& name, | 236 bool FakeCryptohomeClient::InstallAttributesGet(const std::string& name, |
234 std::vector<uint8>* value, | 237 std::vector<uint8_t>* value, |
235 bool* successful) { | 238 bool* successful) { |
236 if (install_attrs_.find(name) != install_attrs_.end()) { | 239 if (install_attrs_.find(name) != install_attrs_.end()) { |
237 *value = install_attrs_[name]; | 240 *value = install_attrs_[name]; |
238 *successful = true; | 241 *successful = true; |
239 } else { | 242 } else { |
240 value->clear(); | 243 value->clear(); |
241 *successful = false; | 244 *successful = false; |
242 } | 245 } |
243 return true; | 246 return true; |
244 } | 247 } |
245 | 248 |
246 bool FakeCryptohomeClient::InstallAttributesSet( | 249 bool FakeCryptohomeClient::InstallAttributesSet( |
247 const std::string& name, | 250 const std::string& name, |
248 const std::vector<uint8>& value, | 251 const std::vector<uint8_t>& value, |
249 bool* successful) { | 252 bool* successful) { |
250 install_attrs_[name] = value; | 253 install_attrs_[name] = value; |
251 *successful = true; | 254 *successful = true; |
252 return true; | 255 return true; |
253 } | 256 } |
254 | 257 |
255 bool FakeCryptohomeClient::InstallAttributesFinalize(bool* successful) { | 258 bool FakeCryptohomeClient::InstallAttributesFinalize(bool* successful) { |
256 locked_ = true; | 259 locked_ = true; |
257 *successful = true; | 260 *successful = true; |
258 | 261 |
(...skipping 14 matching lines...) Expand all Loading... |
273 // scope. | 276 // scope. |
274 google::protobuf::io::StringOutputStream result_stream(&result); | 277 google::protobuf::io::StringOutputStream result_stream(&result); |
275 google::protobuf::io::CodedOutputStream result_output(&result_stream); | 278 google::protobuf::io::CodedOutputStream result_output(&result_stream); |
276 | 279 |
277 // These tags encode a variable-length value on the wire, which can be | 280 // These tags encode a variable-length value on the wire, which can be |
278 // used to encode strings, bytes and messages. We only needs constants | 281 // used to encode strings, bytes and messages. We only needs constants |
279 // for tag numbers 1 and 2 (see install_attributes.proto). | 282 // for tag numbers 1 and 2 (see install_attributes.proto). |
280 const int kVarLengthTag1 = (1 << 3) | 0x2; | 283 const int kVarLengthTag1 = (1 << 3) | 0x2; |
281 const int kVarLengthTag2 = (2 << 3) | 0x2; | 284 const int kVarLengthTag2 = (2 << 3) | 0x2; |
282 | 285 |
283 typedef std::map<std::string, std::vector<uint8> >::const_iterator Iter; | 286 typedef std::map<std::string, std::vector<uint8_t>>::const_iterator Iter; |
284 for (Iter it = install_attrs_.begin(); it != install_attrs_.end(); ++it) { | 287 for (Iter it = install_attrs_.begin(); it != install_attrs_.end(); ++it) { |
285 std::string attr; | 288 std::string attr; |
286 { | 289 { |
287 google::protobuf::io::StringOutputStream attr_stream(&attr); | 290 google::protobuf::io::StringOutputStream attr_stream(&attr); |
288 google::protobuf::io::CodedOutputStream attr_output(&attr_stream); | 291 google::protobuf::io::CodedOutputStream attr_output(&attr_stream); |
289 | 292 |
290 attr_output.WriteVarint32(kVarLengthTag1); | 293 attr_output.WriteVarint32(kVarLengthTag1); |
291 attr_output.WriteVarint32(it->first.size()); | 294 attr_output.WriteVarint32(it->first.size()); |
292 attr_output.WriteString(it->first); | 295 attr_output.WriteString(it->first); |
293 attr_output.WriteVarint32(kVarLengthTag2); | 296 attr_output.WriteVarint32(kVarLengthTag2); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 service_is_available_ = is_available; | 548 service_is_available_ = is_available; |
546 if (is_available) { | 549 if (is_available) { |
547 std::vector<WaitForServiceToBeAvailableCallback> callbacks; | 550 std::vector<WaitForServiceToBeAvailableCallback> callbacks; |
548 callbacks.swap(pending_wait_for_service_to_be_available_callbacks_); | 551 callbacks.swap(pending_wait_for_service_to_be_available_callbacks_); |
549 for (size_t i = 0; i < callbacks.size(); ++i) | 552 for (size_t i = 0; i < callbacks.size(); ++i) |
550 callbacks[i].Run(is_available); | 553 callbacks[i].Run(is_available); |
551 } | 554 } |
552 } | 555 } |
553 | 556 |
554 // static | 557 // static |
555 std::vector<uint8> FakeCryptohomeClient::GetStubSystemSalt() { | 558 std::vector<uint8_t> FakeCryptohomeClient::GetStubSystemSalt() { |
556 const char kStubSystemSalt[] = "stub_system_salt"; | 559 const char kStubSystemSalt[] = "stub_system_salt"; |
557 return std::vector<uint8>(kStubSystemSalt, | 560 return std::vector<uint8_t>(kStubSystemSalt, |
558 kStubSystemSalt + arraysize(kStubSystemSalt) - 1); | 561 kStubSystemSalt + arraysize(kStubSystemSalt) - 1); |
559 } | 562 } |
560 | 563 |
561 void FakeCryptohomeClient::ReturnProtobufMethodCallback( | 564 void FakeCryptohomeClient::ReturnProtobufMethodCallback( |
562 const cryptohome::BaseReply& reply, | 565 const cryptohome::BaseReply& reply, |
563 const ProtobufMethodCallback& callback) { | 566 const ProtobufMethodCallback& callback) { |
564 base::MessageLoop::current()->PostTask( | 567 base::MessageLoop::current()->PostTask( |
565 FROM_HERE, | 568 FROM_HERE, |
566 base::Bind(callback, | 569 base::Bind(callback, |
567 DBUS_METHOD_CALL_SUCCESS, | 570 DBUS_METHOD_CALL_SUCCESS, |
568 true, | 571 true, |
(...skipping 27 matching lines...) Expand all Loading... |
596 FROM_HERE, | 599 FROM_HERE, |
597 base::Bind(async_call_status_data_handler_, | 600 base::Bind(async_call_status_data_handler_, |
598 async_call_id_, | 601 async_call_id_, |
599 true, | 602 true, |
600 std::string())); | 603 std::string())); |
601 } | 604 } |
602 ++async_call_id_; | 605 ++async_call_id_; |
603 } | 606 } |
604 | 607 |
605 } // namespace chromeos | 608 } // namespace chromeos |
OLD | NEW |