beacon_seed.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #ifndef ASH_COMPONENTS_MULTIDEVICE_BEACON_SEED_H_
  5. #define ASH_COMPONENTS_MULTIDEVICE_BEACON_SEED_H_
  6. #include <google/protobuf/repeated_field.h>
  7. #include <ostream>
  8. #include <string>
  9. #include <vector>
  10. #include "ash/services/device_sync/proto/cryptauth_api.pb.h"
  11. #include "ash/services/device_sync/proto/cryptauth_better_together_device_metadata.pb.h"
  12. #include "base/time/time.h"
  13. namespace ash::multidevice {
  14. // Salt value used to generate ephemeral IDs for bootstrapping connections.
  15. // A BeaconSeed value is valid only between its start and end timestamps.
  16. //
  17. // This class should always be preferred over the cryptauth::BeaconSeed proto
  18. // except when communicating with the CryptAuth server.
  19. class BeaconSeed {
  20. public:
  21. BeaconSeed();
  22. BeaconSeed(const std::string& data,
  23. base::Time start_time,
  24. base::Time end_time);
  25. BeaconSeed(const BeaconSeed& other);
  26. ~BeaconSeed();
  27. const std::string& data() const { return data_; }
  28. base::Time start_time() const { return start_time_; }
  29. base::Time end_time() const { return end_time_; }
  30. bool operator==(const BeaconSeed& other) const;
  31. private:
  32. std::string data_;
  33. base::Time start_time_;
  34. base::Time end_time_;
  35. };
  36. BeaconSeed FromCryptAuthSeed(cryptauth::BeaconSeed cryptauth_seed);
  37. cryptauth::BeaconSeed ToCryptAuthSeed(BeaconSeed multidevice_seed);
  38. BeaconSeed FromCryptAuthV2Seed(cryptauthv2::BeaconSeed cryptauth_seed);
  39. cryptauthv2::BeaconSeed ToCryptAuthV2Seed(BeaconSeed multidevice_seed);
  40. std::vector<cryptauth::BeaconSeed> ToCryptAuthSeedList(
  41. const std::vector<BeaconSeed>& cryptauth_seed_list);
  42. std::vector<BeaconSeed> FromCryptAuthSeedList(
  43. const std::vector<cryptauth::BeaconSeed>& cryptauth_seed_list);
  44. std::vector<BeaconSeed> FromCryptAuthV2SeedRepeatedPtrField(
  45. const google::protobuf::RepeatedPtrField<cryptauthv2::BeaconSeed>&
  46. cryptauth_seed_list);
  47. std::ostream& operator<<(std::ostream& stream, const BeaconSeed& beacon_seed);
  48. } // namespace ash::multidevice
  49. #endif // ASH_COMPONENTS_MULTIDEVICE_BEACON_SEED_H_