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

Side by Side Diff: components/cryptauth/foreground_eid_generator.h

Issue 2847233003: [EasyUnlock] Move DataWithTimestamp out of ForegroundEidGenerator so it can be shared. (Closed)
Patch Set: fixes 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef COMPONENTS_CRYPTAUTH_BLE_FOREGROUND_EID_GENERATOR_H_ 5 #ifndef COMPONENTS_CRYPTAUTH_BLE_FOREGROUND_EID_GENERATOR_H_
6 #define COMPONENTS_CRYPTAUTH_BLE_FOREGROUND_EID_GENERATOR_H_ 6 #define COMPONENTS_CRYPTAUTH_BLE_FOREGROUND_EID_GENERATOR_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/time/clock.h" 14 #include "base/time/clock.h"
15 #include "components/cryptauth/data_with_timestamp.h"
15 16
16 namespace cryptauth { 17 namespace cryptauth {
17 18
18 class BeaconSeed; 19 class BeaconSeed;
19 class RawEidGenerator; 20 class RawEidGenerator;
20 struct RemoteDevice; 21 struct RemoteDevice;
21 22
22 // Generates ephemeral ID (EID) values that are broadcast for foreground BLE 23 // Generates ephemeral ID (EID) values that are broadcast for foreground BLE
23 // advertisements in the ProximityAuth protocol. 24 // advertisements in the ProximityAuth protocol.
24 // 25 //
25 // When advertising in foreground mode, we don't care about battery consumption 26 // When advertising in foreground mode, we don't care about battery consumption
26 // while advertising. We assume, however, that the scanning side is 27 // while advertising. We assume, however, that the scanning side is
27 // battery-conscious, and is using hardware-based scanning. 28 // battery-conscious, and is using hardware-based scanning.
28 // 29 //
29 // For the inverse of this model, in which advertising is battery-sensitive, see 30 // For the inverse of this model, in which advertising is battery-sensitive, see
30 // BackgroundEidGenerator. 31 // BackgroundEidGenerator.
31 // 32 //
32 // A peripheral-role device advertises a 4-byte advertisement with two parts: a 33 // A peripheral-role device advertises a 4-byte advertisement with two parts: a
33 // 2-byte EID which is specific to the central-role device with which it intends 34 // 2-byte EID which is specific to the central-role device with which it intends
34 // to communicate, and a 2-byte EID which is specific to the peripheral-role 35 // to communicate, and a 2-byte EID which is specific to the peripheral-role
35 // device. 36 // device.
36 // 37 //
37 // This class uses EID seed values synced from the back-end to generate these 38 // This class uses EID seed values synced from the back-end to generate these
38 // EIDs. 39 // EIDs.
39 // 40 //
40 // See go/proximity-auth-ble-advertising. 41 // See go/proximity-auth-ble-advertising.
41 class ForegroundEidGenerator { 42 class ForegroundEidGenerator {
42 public: 43 public:
43 // Stores EID-related data and timestamps at which time this data becomes
44 // active or inactive.
45 struct DataWithTimestamp {
46 DataWithTimestamp(const std::string& data,
47 const int64_t start_timestamp_ms,
48 const int64_t end_timestamp_ms);
49 DataWithTimestamp(const DataWithTimestamp& other);
50
51 bool ContainsTime(const int64_t timestamp_ms) const;
52 std::string DataInHex() const;
53
54 const std::string data;
55 const int64_t start_timestamp_ms;
56 const int64_t end_timestamp_ms;
57 };
58
59 // Data for both a current and adjacent EID. The current EID *must* be 44 // Data for both a current and adjacent EID. The current EID *must* be
60 // supplied, but adjacent data may be null. Each EID consists of a 2-byte EID 45 // supplied, but adjacent data may be null. Each EID consists of a 2-byte EID
61 // value paired with the timestamp at which time this value becomes active or 46 // value paired with the timestamp at which time this value becomes active or
62 // inactive. 47 // inactive.
63 struct EidData { 48 struct EidData {
64 enum AdjacentDataType { NONE, PAST, FUTURE }; 49 enum AdjacentDataType { NONE, PAST, FUTURE };
65 50
66 EidData(const DataWithTimestamp current_data, 51 EidData(const DataWithTimestamp current_data,
67 std::unique_ptr<DataWithTimestamp> adjacent_data); 52 std::unique_ptr<DataWithTimestamp> adjacent_data);
68 ~EidData(); 53 ~EidData();
69 54
70 AdjacentDataType GetAdjacentDataType() const; 55 AdjacentDataType GetAdjacentDataType() const;
71 std::string DataInHex() const; 56 std::string DataInHex() const;
72 57
73 const DataWithTimestamp current_data; 58 const DataWithTimestamp current_data;
74 const std::unique_ptr<DataWithTimestamp> adjacent_data; 59 const std::unique_ptr<DataWithTimestamp> adjacent_data;
75 }; 60 };
76 61
77 // The flag used to denote that a Bluetooth 4.0 device has sent an 62 // The flag used to denote that a Bluetooth 4.0 device has sent an
78 // advertisement. This flag indicates to the recipient that the sender cannot 63 // advertisement. This flag indicates to the recipient that the sender cannot
79 // act as both a central- and peripheral-role device simultaneously, so the 64 // act as both a central- and peripheral-role device simultaneously, so the
80 // recipient should advertise back instead of initializing a connection. 65 // recipient should advertise back instead of initializing a connection.
81 static const int8_t kBluetooth4Flag; 66 static const int8_t kBluetooth4Flag;
82 67
83 ForegroundEidGenerator(); 68 ForegroundEidGenerator();
84 virtual ~ForegroundEidGenerator(); 69 virtual ~ForegroundEidGenerator();
85 70
86 // Generates EID data for the given EID seeds to be used as a background scan 71 // Generates EID data for the given EID seeds to be used as a background scan
87 // filter. In the normal case, two DataWithTimestamp values are returned, one 72 // filter. In the normal case, two DataWithTimestamp values are returned,
88 // for each EID seed rotation period. If data has not been synced from the 73 // one for each EID seed rotation period. If data has not been synced from the
Kyle Horimoto 2017/04/30 03:17:46 Please revert the change.
Tim Song 2017/05/01 22:23:38 Done.
89 // backend recently and EID seeds are unavailable, nullptr is returned. 74 // backend recently and EID seeds are unavailable, nullptr is returned.
90 virtual std::unique_ptr<EidData> GenerateBackgroundScanFilter( 75 virtual std::unique_ptr<EidData> GenerateBackgroundScanFilter(
91 const std::vector<BeaconSeed>& scanning_device_beacon_seeds) const; 76 const std::vector<BeaconSeed>& scanning_device_beacon_seeds) const;
92 77
93 // Generates advertisement data for the given EID seeds. If data has not been 78 // Generates advertisement data for the given EID seeds. If data has not been
94 // synced from the back-end recently and EID seeds are unavailable, nullptr is 79 // synced from the back-end recently and EID seeds are unavailable, nullptr is
95 // returned. 80 // returned.
96 virtual std::unique_ptr<DataWithTimestamp> GenerateAdvertisement( 81 virtual std::unique_ptr<DataWithTimestamp> GenerateAdvertisement(
97 const std::string& advertising_device_public_key, 82 const std::string& advertising_device_public_key,
98 const std::vector<BeaconSeed>& scanning_device_beacon_seeds) const; 83 const std::vector<BeaconSeed>& scanning_device_beacon_seeds) const;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 CryptAuthForegroundEidGeneratorTest, 179 CryptAuthForegroundEidGeneratorTest,
195 GeneratePossibleAdvertisements_NoAdvertisements_SeedsTooFarInPast); 180 GeneratePossibleAdvertisements_NoAdvertisements_SeedsTooFarInPast);
196 FRIEND_TEST_ALL_PREFIXES( 181 FRIEND_TEST_ALL_PREFIXES(
197 CryptAuthForegroundEidGeneratorTest, 182 CryptAuthForegroundEidGeneratorTest,
198 GeneratePossibleAdvertisements_NoAdvertisements_EmptySeeds); 183 GeneratePossibleAdvertisements_NoAdvertisements_EmptySeeds);
199 }; 184 };
200 185
201 } // cryptauth 186 } // cryptauth
202 187
203 #endif // COMPONENTS_CRYPTAUTH_BLE_FOREGROUND_EID_GENERATOR_H_ 188 #endif // COMPONENTS_CRYPTAUTH_BLE_FOREGROUND_EID_GENERATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698