Index: components/cryptauth/remote_device.cc |
diff --git a/components/cryptauth/remote_device.cc b/components/cryptauth/remote_device.cc |
index 19665df742a95b4edba9531b4c92e17c59265e06..1c1672dc8feb4a429bb807bf8b5fbea4d9f6de08 100644 |
--- a/components/cryptauth/remote_device.cc |
+++ b/components/cryptauth/remote_device.cc |
@@ -27,6 +27,12 @@ RemoteDevice::RemoteDevice(const RemoteDevice& other) = default; |
RemoteDevice::~RemoteDevice() {} |
+void RemoteDevice::LoadBeaconSeeds( |
+ const std::vector<BeaconSeed>& beacon_seeds) { |
+ 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
|
+ 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.
|
+} |
+ |
std::string RemoteDevice::GetDeviceId() const { |
std::string to_return; |
base::Base64Encode(public_key, &to_return); |
@@ -38,12 +44,30 @@ std::string RemoteDevice::GetTruncatedDeviceIdForLogs() const { |
} |
bool RemoteDevice::operator==(const RemoteDevice& other) const { |
- return user_id == other.user_id |
- && name == other.name |
- && public_key == other.public_key |
- && bluetooth_address == other.bluetooth_address |
- && persistent_symmetric_key == other.persistent_symmetric_key |
- && sign_in_challenge == other.sign_in_challenge; |
+ bool are_beacon_seeds_equal = false; |
+ 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.
|
+ if (beacon_seeds.size() == other.beacon_seeds.size()) { |
+ are_beacon_seeds_equal = true; |
+ for (size_t i = 0; i < beacon_seeds.size(); ++i) { |
+ const BeaconSeed& our_seed = beacon_seeds[i]; |
+ const BeaconSeed& their_seed = other.beacon_seeds[i]; |
+ if (our_seed.start_time_millis() != their_seed.start_time_millis() || |
+ our_seed.end_time_millis() != their_seed.end_time_millis() || |
+ our_seed.data() != their_seed.data()) { |
+ are_beacon_seeds_equal = false; |
+ break; |
+ } |
+ } |
+ } |
+ } else { |
+ are_beacon_seeds_equal = !other.are_beacon_seeds_loaded; |
+ } |
+ |
+ return user_id == other.user_id && name == other.name && |
+ public_key == other.public_key && |
+ bluetooth_address == other.bluetooth_address && |
+ persistent_symmetric_key == other.persistent_symmetric_key && |
+ sign_in_challenge == other.sign_in_challenge && are_beacon_seeds_equal; |
} |
bool RemoteDevice::operator<(const RemoteDevice& other) const { |