summaryrefslogtreecommitdiff
path: root/chromium/components/cryptauth/ble/ble_advertisement_generator.h
blob: 38b8d8f01f9665372033fb9f2a1dc0547fa7fc41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_CRYPTAUTH_BLE_ADVERTISEMENT_GENERATOR_H_
#define COMPONENTS_CRYPTAUTH_BLE_ADVERTISEMENT_GENERATOR_H_

#include <memory>

#include "base/macros.h"
#include "components/cryptauth/foreground_eid_generator.h"

namespace chromeos {
namespace tether {
class BleAdvertiserImplTest;
class AdHocBleAdvertiserImplTest;
}  // namespace tether
}  // namespace chromeos

namespace cryptauth {

class LocalDeviceDataProvider;
class RemoteBeaconSeedFetcher;

// Generates advertisements for the ProximityAuth BLE advertisement scheme.
class BleAdvertisementGenerator {
 public:
  // Generates an advertisement from the current device to the device with ID
  // |device_id|. The generated advertisement should be used immediately since
  // it is based on the current timestamp.
  static std::unique_ptr<DataWithTimestamp> GenerateBleAdvertisement(
      const std::string& device_id,
      LocalDeviceDataProvider* local_device_data_provider,
      RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher);

  virtual ~BleAdvertisementGenerator();

 protected:
  BleAdvertisementGenerator();

  virtual std::unique_ptr<DataWithTimestamp> GenerateBleAdvertisementInternal(
      const std::string& device_id,
      LocalDeviceDataProvider* local_device_data_provider,
      RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher);

 private:
  friend class CryptAuthBleAdvertisementGeneratorTest;
  friend class chromeos::tether::BleAdvertiserImplTest;
  friend class chromeos::tether::AdHocBleAdvertiserImplTest;

  static BleAdvertisementGenerator* instance_;

  static void SetInstanceForTesting(BleAdvertisementGenerator* test_generator);

  void SetEidGeneratorForTesting(
      std::unique_ptr<ForegroundEidGenerator> test_eid_generator);

  std::unique_ptr<ForegroundEidGenerator> eid_generator_;

  DISALLOW_COPY_AND_ASSIGN(BleAdvertisementGenerator);
};

}  // namespace cryptauth

#endif  // COMPONENTS_CRYPTAUTH_BLE_ADVERTISEMENT_GENERATOR_H_