Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: components/cryptauth/remote_device.cc

Issue 2859053003: [EasyUnlock] Add beacon_seeds to RemoteDevice. (Closed)
Patch Set: load beacon seed in RemoteDevice Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 "components/cryptauth/remote_device.h" 5 #include "components/cryptauth/remote_device.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 8
9 namespace cryptauth { 9 namespace cryptauth {
10 10
11 RemoteDevice::RemoteDevice() {} 11 RemoteDevice::RemoteDevice() {}
12 12
13 RemoteDevice::RemoteDevice(const std::string& user_id, 13 RemoteDevice::RemoteDevice(const std::string& user_id,
14 const std::string& name, 14 const std::string& name,
15 const std::string& public_key, 15 const std::string& public_key,
16 const std::string& bluetooth_address, 16 const std::string& bluetooth_address,
17 const std::string& persistent_symmetric_key, 17 const std::string& persistent_symmetric_key,
18 std::string sign_in_challenge) 18 std::string sign_in_challenge)
19 : user_id(user_id), 19 : user_id(user_id),
20 name(name), 20 name(name),
21 public_key(public_key), 21 public_key(public_key),
22 bluetooth_address(bluetooth_address), 22 bluetooth_address(bluetooth_address),
23 persistent_symmetric_key(persistent_symmetric_key), 23 persistent_symmetric_key(persistent_symmetric_key),
24 sign_in_challenge(sign_in_challenge) {} 24 sign_in_challenge(sign_in_challenge) {}
25 25
26 RemoteDevice::RemoteDevice(const RemoteDevice& other) = default; 26 RemoteDevice::RemoteDevice(const RemoteDevice& other) = default;
27 27
28 RemoteDevice::~RemoteDevice() {} 28 RemoteDevice::~RemoteDevice() {}
29 29
30 void RemoteDevice::LoadBeaconSeeds(
31 const std::vector<BeaconSeed>& beacon_seeds) {
32 this->are_beacon_seeds_loaded = true;
Ryan Hansberry 2017/05/19 18:28:43 nit: remove 'this'
Tim Song 2017/05/19 21:19:34 This is to disambiguate the member variable of |be
33 this->beacon_seeds = beacon_seeds;
Ryan Hansberry 2017/05/19 18:28:43 same here
Tim Song 2017/05/19 21:19:34 Same here.
34 }
35
30 std::string RemoteDevice::GetDeviceId() const { 36 std::string RemoteDevice::GetDeviceId() const {
31 std::string to_return; 37 std::string to_return;
32 base::Base64Encode(public_key, &to_return); 38 base::Base64Encode(public_key, &to_return);
33 return to_return; 39 return to_return;
34 } 40 }
35 41
36 std::string RemoteDevice::GetTruncatedDeviceIdForLogs() const { 42 std::string RemoteDevice::GetTruncatedDeviceIdForLogs() const {
37 return RemoteDevice::TruncateDeviceIdForLogs(GetDeviceId()); 43 return RemoteDevice::TruncateDeviceIdForLogs(GetDeviceId());
38 } 44 }
39 45
40 bool RemoteDevice::operator==(const RemoteDevice& other) const { 46 bool RemoteDevice::operator==(const RemoteDevice& other) const {
41 return user_id == other.user_id 47 bool are_beacon_seeds_equal = false;
42 && name == other.name 48 if (are_beacon_seeds_loaded) {
Ryan Hansberry 2017/05/19 18:28:43 These nested ifs are tough to read. Can you break
Tim Song 2017/05/19 21:19:34 Done.
43 && public_key == other.public_key 49 if (beacon_seeds.size() == other.beacon_seeds.size()) {
44 && bluetooth_address == other.bluetooth_address 50 are_beacon_seeds_equal = true;
45 && persistent_symmetric_key == other.persistent_symmetric_key 51 for (size_t i = 0; i < beacon_seeds.size(); ++i) {
46 && sign_in_challenge == other.sign_in_challenge; 52 const BeaconSeed& our_seed = beacon_seeds[i];
53 const BeaconSeed& their_seed = other.beacon_seeds[i];
54 if (our_seed.start_time_millis() != their_seed.start_time_millis() ||
55 our_seed.end_time_millis() != their_seed.end_time_millis() ||
56 our_seed.data() != their_seed.data()) {
57 are_beacon_seeds_equal = false;
58 break;
59 }
60 }
61 }
62 } else {
63 are_beacon_seeds_equal = !other.are_beacon_seeds_loaded;
64 }
65
66 return user_id == other.user_id && name == other.name &&
67 public_key == other.public_key &&
68 bluetooth_address == other.bluetooth_address &&
69 persistent_symmetric_key == other.persistent_symmetric_key &&
70 sign_in_challenge == other.sign_in_challenge && are_beacon_seeds_equal;
47 } 71 }
48 72
49 bool RemoteDevice::operator<(const RemoteDevice& other) const { 73 bool RemoteDevice::operator<(const RemoteDevice& other) const {
50 // |public_key| is the only field guaranteed to be set and is also unique to 74 // |public_key| is the only field guaranteed to be set and is also unique to
51 // each RemoteDevice. However, since it can contain null bytes, use 75 // each RemoteDevice. However, since it can contain null bytes, use
52 // GetDeviceId(), which cannot contain null bytes, to compare devices. 76 // GetDeviceId(), which cannot contain null bytes, to compare devices.
53 return GetDeviceId().compare(other.GetDeviceId()) < 0; 77 return GetDeviceId().compare(other.GetDeviceId()) < 0;
54 } 78 }
55 79
56 // static 80 // static
57 std::string RemoteDevice::TruncateDeviceIdForLogs(const std::string& full_id) { 81 std::string RemoteDevice::TruncateDeviceIdForLogs(const std::string& full_id) {
58 if (full_id.length() <= 10) { 82 if (full_id.length() <= 10) {
59 return full_id; 83 return full_id;
60 } 84 }
61 85
62 return full_id.substr(0, 5) 86 return full_id.substr(0, 5)
63 + "..." 87 + "..."
64 + full_id.substr(full_id.length() - 5, full_id.length()); 88 + full_id.substr(full_id.length() - 5, full_id.length());
65 } 89 }
66 90
67 } // namespace cryptauth 91 } // namespace cryptauth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698