#include "chrome/browser/webauthn/cablev2_devices.h"
#include <array>
#include <string>
#include <string_view>
#include <vector>
#include "base/base64.h"
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/i18n/time_formatting.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/device_info_sync_service_factory.h"
#include "chrome/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/sync_device_info/device_info.h"
#include "components/sync_device_info/device_info_sync_service.h"
#include "components/sync_device_info/device_info_tracker.h"
#include "device/fido/cable/cable_discovery_data.h"
#include "device/fido/cable/v2_constants.h"
#include "device/fido/cable/v2_handshake.h"
#include "device/fido/features.h"
#include "third_party/icu/source/i18n/unicode/timezone.h"
Pairing;
namespace cablev2 {
namespace {
template <size_t N>
bool CopyBytestring(std::array<uint8_t, N>* out, const std::string* value) { … }
bool CopyBytestring(std::vector<uint8_t>* out, const std::string* value) { … }
bool CopyString(std::string* out, const std::string* value) { … }
const char kWebAuthnCablePairingsPrefName[] = …;
const char kPairingPrefName[] = …;
const char kPairingPrefContactId[] = …;
const char kPairingPrefEncodedTunnelServer[] = …;
const char kPairingPrefId[] = …;
const char kPairingPrefSecret[] = …;
const char kPairingPrefPublicKey[] = …;
const char kPairingPrefTime[] = …;
const char kPairingPrefNewImpl[] = …;
static std::string NameForDisplay(std::string_view raw_name) { … }
void DeletePairingByPublicKey(base::Value::List& list,
const std::string& public_key_base64) { … }
std::vector<std::unique_ptr<Pairing>> GetSyncedDevices(Profile* const profile) { … }
std::vector<std::unique_ptr<Pairing>> GetLinkedDevices(Profile* const profile) { … }
std::string FindUniqueName(const std::string& orig_name,
base::span<const std::string_view> existing_names) { … }
}
std::unique_ptr<Pairing> PairingFromSyncedDevice(
const syncer::DeviceInfo* device,
const base::Time& now) { … }
void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { … }
KnownDevices::KnownDevices() = default;
KnownDevices::~KnownDevices() = default;
std::unique_ptr<KnownDevices> KnownDevices::FromProfile(Profile* profile) { … }
std::vector<std::unique_ptr<Pairing>> MergeDevices(
std::unique_ptr<KnownDevices> known_devices,
const icu::Locale* locale) { … }
std::vector<std::string_view> KnownDevices::Names() const { … }
void AddPairing(Profile* profile, std::unique_ptr<Pairing> pairing) { … }
void DeletePairingByPublicKey(
PrefService* pref_service,
std::array<uint8_t, device::kP256X962Length> public_key) { … }
bool RenamePairing(
PrefService* pref_service,
const std::array<uint8_t, device::kP256X962Length>& public_key,
const std::string& new_name,
base::span<const std::string_view> existing_names) { … }
}