1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROMEOS_COMPONENTS_MULTIDEVICE_BEACON_SEED_H_
6 #define CHROMEOS_COMPONENTS_MULTIDEVICE_BEACON_SEED_H_
7 
8 #include <google/protobuf/repeated_field.h>
9 #include <ostream>
10 #include <string>
11 #include <vector>
12 
13 #include "base/time/time.h"
14 #include "chromeos/services/device_sync/proto/cryptauth_api.pb.h"
15 #include "chromeos/services/device_sync/proto/cryptauth_better_together_device_metadata.pb.h"
16 
17 namespace chromeos {
18 
19 namespace multidevice {
20 
21 // Salt value used to generate ephemeral IDs for bootstrapping connections.
22 // A BeaconSeed value is valid only between its start and end timestamps.
23 //
24 // This class should always be preferred over the cryptauth::BeaconSeed proto
25 // except when communicating with the CryptAuth server.
26 class BeaconSeed {
27  public:
28   BeaconSeed();
29   BeaconSeed(const std::string& data,
30              base::Time start_time,
31              base::Time end_time);
32   BeaconSeed(const BeaconSeed& other);
33   ~BeaconSeed();
34 
data()35   const std::string& data() const { return data_; }
start_time()36   base::Time start_time() const { return start_time_; }
end_time()37   base::Time end_time() const { return end_time_; }
38 
39   bool operator==(const BeaconSeed& other) const;
40 
41  private:
42   std::string data_;
43   base::Time start_time_;
44   base::Time end_time_;
45 };
46 
47 BeaconSeed FromCryptAuthSeed(cryptauth::BeaconSeed cryptauth_seed);
48 cryptauth::BeaconSeed ToCryptAuthSeed(BeaconSeed multidevice_seed);
49 
50 BeaconSeed FromCryptAuthV2Seed(cryptauthv2::BeaconSeed cryptauth_seed);
51 cryptauthv2::BeaconSeed ToCryptAuthV2Seed(BeaconSeed multidevice_seed);
52 
53 std::vector<cryptauth::BeaconSeed> ToCryptAuthSeedList(
54     const std::vector<BeaconSeed>& cryptauth_seed_list);
55 std::vector<BeaconSeed> FromCryptAuthSeedList(
56     const std::vector<cryptauth::BeaconSeed>& cryptauth_seed_list);
57 
58 std::vector<BeaconSeed> FromCryptAuthV2SeedRepeatedPtrField(
59     const google::protobuf::RepeatedPtrField<cryptauthv2::BeaconSeed>&
60         cryptauth_seed_list);
61 
62 std::ostream& operator<<(std::ostream& stream, const BeaconSeed& beacon_seed);
63 
64 }  // namespace multidevice
65 
66 }  // namespace chromeos
67 
68 #endif  // CHROMEOS_COMPONENTS_MULTIDEVICE_BEACON_SEED_H_
69