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

Unified Diff: components/cryptauth/foreground_eid_generator.cc

Issue 2847233003: [EasyUnlock] Move DataWithTimestamp out of ForegroundEidGenerator so it can be shared. (Closed)
Patch Set: Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: components/cryptauth/foreground_eid_generator.cc
diff --git a/components/cryptauth/foreground_eid_generator.cc b/components/cryptauth/foreground_eid_generator.cc
index b7d99da7b49fd3eba1cc6987fb854ec74cda47fd..05481a3ed783580c86763be7218482da12843cd1 100644
--- a/components/cryptauth/foreground_eid_generator.cc
+++ b/components/cryptauth/foreground_eid_generator.cc
@@ -30,8 +30,8 @@ const int64_t ForegroundEidGenerator::kNumMsInBeginningOfEidPeriod =
const int8_t ForegroundEidGenerator::kBluetooth4Flag = 0x01;
ForegroundEidGenerator::EidData::EidData(
- const DataWithTimestamp current_data,
- std::unique_ptr<DataWithTimestamp> adjacent_data)
+ const EidDataWithTimestamp current_data,
+ std::unique_ptr<EidDataWithTimestamp> adjacent_data)
: current_data(current_data), adjacent_data(std::move(adjacent_data)) {}
ForegroundEidGenerator::EidData::~EidData() {}
@@ -59,42 +59,6 @@ std::string ForegroundEidGenerator::EidData::DataInHex() const {
return str + "]";
}
-ForegroundEidGenerator::DataWithTimestamp::DataWithTimestamp(
- const std::string& data,
- const int64_t start_timestamp_ms,
- const int64_t end_timestamp_ms)
- : data(data),
- start_timestamp_ms(start_timestamp_ms),
- end_timestamp_ms(end_timestamp_ms) {
- DCHECK(start_timestamp_ms < end_timestamp_ms);
- DCHECK(data.size());
-}
-
-ForegroundEidGenerator::DataWithTimestamp::DataWithTimestamp(
- const DataWithTimestamp& other)
- : data(other.data),
- start_timestamp_ms(other.start_timestamp_ms),
- end_timestamp_ms(other.end_timestamp_ms) {
- DCHECK(start_timestamp_ms < end_timestamp_ms);
- DCHECK(data.size());
-}
-
-bool ForegroundEidGenerator::DataWithTimestamp::ContainsTime(
- const int64_t timestamp_ms) const {
- return start_timestamp_ms <= timestamp_ms && timestamp_ms < end_timestamp_ms;
-}
-
-std::string ForegroundEidGenerator::DataWithTimestamp::DataInHex() const {
- std::stringstream ss;
- ss << "0x" << std::hex;
-
- for (size_t i = 0; i < data.size(); i++) {
- ss << static_cast<int>(data.data()[i]);
- }
-
- return ss.str();
-}
-
ForegroundEidGenerator::ForegroundEidGenerator()
: ForegroundEidGenerator(base::MakeUnique<RawEidGeneratorImpl>(),
base::MakeUnique<base::DefaultClock>()) {}
@@ -118,24 +82,25 @@ ForegroundEidGenerator::GenerateBackgroundScanFilter(
return nullptr;
}
- std::unique_ptr<DataWithTimestamp> current_eid = GenerateEidDataWithTimestamp(
- scanning_device_beacon_seeds,
- timestamps->current_period_start_timestamp_ms,
- timestamps->current_period_end_timestamp_ms);
+ std::unique_ptr<EidDataWithTimestamp> current_eid =
+ GenerateEidEidDataWithTimestamp(
+ scanning_device_beacon_seeds,
+ timestamps->current_period_start_timestamp_ms,
+ timestamps->current_period_end_timestamp_ms);
if (!current_eid) {
// The current EID could not be generated.
return nullptr;
}
- std::unique_ptr<DataWithTimestamp> adjacent_eid =
- GenerateEidDataWithTimestamp(
+ std::unique_ptr<EidDataWithTimestamp> adjacent_eid =
+ GenerateEidEidDataWithTimestamp(
scanning_device_beacon_seeds,
timestamps->adjacent_period_start_timestamp_ms,
timestamps->adjacent_period_end_timestamp_ms);
return base::WrapUnique(new EidData(*current_eid, std::move(adjacent_eid)));
}
-std::unique_ptr<ForegroundEidGenerator::DataWithTimestamp>
+std::unique_ptr<EidDataWithTimestamp>
ForegroundEidGenerator::GenerateAdvertisement(
const std::string& advertising_device_public_key,
const std::vector<BeaconSeed>& scanning_device_beacon_seeds) const {
@@ -189,7 +154,7 @@ std::vector<std::string> ForegroundEidGenerator::GeneratePossibleAdvertisements(
}
if (timestamps->current_period_start_timestamp_ms != kNoTimestamp) {
- std::unique_ptr<DataWithTimestamp> current_advertisement =
+ std::unique_ptr<EidDataWithTimestamp> current_advertisement =
GenerateAdvertisement(advertising_device_public_key,
scanning_device_beacon_seeds,
timestamps->current_period_start_timestamp_ms,
@@ -199,7 +164,7 @@ std::vector<std::string> ForegroundEidGenerator::GeneratePossibleAdvertisements(
}
}
- std::unique_ptr<DataWithTimestamp> adjacent_advertisement =
+ std::unique_ptr<EidDataWithTimestamp> adjacent_advertisement =
GenerateAdvertisement(advertising_device_public_key,
scanning_device_beacon_seeds,
timestamps->adjacent_period_start_timestamp_ms,
@@ -211,20 +176,20 @@ std::vector<std::string> ForegroundEidGenerator::GeneratePossibleAdvertisements(
return possible_advertisements;
}
-std::unique_ptr<ForegroundEidGenerator::DataWithTimestamp>
+std::unique_ptr<EidDataWithTimestamp>
ForegroundEidGenerator::GenerateAdvertisement(
const std::string& advertising_device_public_key,
const std::vector<BeaconSeed>& scanning_device_beacon_seeds,
const int64_t start_of_period_timestamp_ms,
const int64_t end_of_period_timestamp_ms) const {
- std::unique_ptr<DataWithTimestamp> advertising_device_identifying_data =
- GenerateEidDataWithTimestamp(
+ std::unique_ptr<EidDataWithTimestamp> advertising_device_identifying_data =
+ GenerateEidEidDataWithTimestamp(
scanning_device_beacon_seeds, start_of_period_timestamp_ms,
end_of_period_timestamp_ms, &advertising_device_public_key);
- std::unique_ptr<DataWithTimestamp> scanning_device_identifying_data =
- GenerateEidDataWithTimestamp(scanning_device_beacon_seeds,
- start_of_period_timestamp_ms,
- end_of_period_timestamp_ms);
+ std::unique_ptr<EidDataWithTimestamp> scanning_device_identifying_data =
+ GenerateEidEidDataWithTimestamp(scanning_device_beacon_seeds,
+ start_of_period_timestamp_ms,
+ end_of_period_timestamp_ms);
if (!advertising_device_identifying_data ||
!scanning_device_identifying_data) {
return nullptr;
@@ -232,23 +197,23 @@ ForegroundEidGenerator::GenerateAdvertisement(
std::string full_advertisement = scanning_device_identifying_data->data +
advertising_device_identifying_data->data;
- return base::WrapUnique(new DataWithTimestamp(full_advertisement,
- start_of_period_timestamp_ms,
- end_of_period_timestamp_ms));
+ return base::WrapUnique(new EidDataWithTimestamp(full_advertisement,
+ start_of_period_timestamp_ms,
+ end_of_period_timestamp_ms));
}
-std::unique_ptr<ForegroundEidGenerator::DataWithTimestamp>
-ForegroundEidGenerator::GenerateEidDataWithTimestamp(
+std::unique_ptr<EidDataWithTimestamp>
+ForegroundEidGenerator::GenerateEidEidDataWithTimestamp(
const std::vector<BeaconSeed>& scanning_device_beacon_seeds,
const int64_t start_of_period_timestamp_ms,
const int64_t end_of_period_timestamp_ms) const {
- return GenerateEidDataWithTimestamp(scanning_device_beacon_seeds,
- start_of_period_timestamp_ms,
- end_of_period_timestamp_ms, nullptr);
+ return GenerateEidEidDataWithTimestamp(scanning_device_beacon_seeds,
+ start_of_period_timestamp_ms,
+ end_of_period_timestamp_ms, nullptr);
}
-std::unique_ptr<ForegroundEidGenerator::DataWithTimestamp>
-ForegroundEidGenerator::GenerateEidDataWithTimestamp(
+std::unique_ptr<EidDataWithTimestamp>
+ForegroundEidGenerator::GenerateEidEidDataWithTimestamp(
const std::vector<BeaconSeed>& scanning_device_beacon_seeds,
const int64_t start_of_period_timestamp_ms,
const int64_t end_of_period_timestamp_ms,
@@ -262,7 +227,7 @@ ForegroundEidGenerator::GenerateEidDataWithTimestamp(
std::string eid_data = raw_eid_generator_->GenerateEid(
*eid_seed, start_of_period_timestamp_ms, extra_entropy);
- return base::WrapUnique(new DataWithTimestamp(
+ return base::WrapUnique(new EidDataWithTimestamp(
eid_data, start_of_period_timestamp_ms, end_of_period_timestamp_ms));
}

Powered by Google App Engine
This is Rietveld 408576698