Commit 2fa37b3d authored by Josh Nohle's avatar Josh Nohle Committed by Commit Bot

[DeviceSync v2] Make CryptAuthDevice members public except IID

This allows us to build the CryptAuthDevice incrementally which is more
natural given the DeviceSync v2 flow.

Bug: 951969
Change-Id: I2863047f95da0ddd46d913fcb06175dd4f441386
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1652681Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Josh Nohle <nohle@chromium.org>
Cr-Commit-Position: refs/heads/master@{#670213}
parent 44909961
......@@ -111,6 +111,11 @@ base::Optional<CryptAuthDevice> CryptAuthDevice::FromDictionary(
*better_together_device_metadata, *feature_states);
}
CryptAuthDevice::CryptAuthDevice(const std::string& instance_id)
: instance_id_(instance_id) {
DCHECK(!instance_id.empty());
}
CryptAuthDevice::CryptAuthDevice(
const std::string& instance_id,
const std::string& device_name,
......@@ -120,16 +125,13 @@ CryptAuthDevice::CryptAuthDevice(
better_together_device_metadata,
const std::map<multidevice::SoftwareFeature,
multidevice::SoftwareFeatureState>& feature_states)
: instance_id_(instance_id),
device_name_(device_name),
device_better_together_public_key_(device_better_together_public_key),
last_update_time_(last_update_time),
better_together_device_metadata_(better_together_device_metadata),
feature_states_(feature_states) {
: device_name(device_name),
device_better_together_public_key(device_better_together_public_key),
last_update_time(last_update_time),
better_together_device_metadata(better_together_device_metadata),
feature_states(feature_states),
instance_id_(instance_id) {
DCHECK(!instance_id.empty());
DCHECK(!device_name.empty());
DCHECK(!device_better_together_public_key.empty());
DCHECK(!last_update_time.is_null());
}
CryptAuthDevice::CryptAuthDevice(const CryptAuthDevice&) = default;
......@@ -139,28 +141,27 @@ CryptAuthDevice::~CryptAuthDevice() = default;
base::Value CryptAuthDevice::AsDictionary() const {
base::Value dict(base::Value::Type::DICTIONARY);
dict.SetKey(kInstanceIdDictKey, util::EncodeAsValueString(instance_id_));
dict.SetKey(kDeviceNameDictKey, util::EncodeAsValueString(device_name_));
dict.SetKey(kDeviceNameDictKey, util::EncodeAsValueString(device_name));
dict.SetKey(kDeviceBetterTogetherPublicKeyDictKey,
util::EncodeAsValueString(device_better_together_public_key_));
dict.SetKey(kLastUpdateTimeDictKey, ::util::TimeToValue(last_update_time_));
util::EncodeAsValueString(device_better_together_public_key));
dict.SetKey(kLastUpdateTimeDictKey, ::util::TimeToValue(last_update_time));
dict.SetKey(
kBetterTogetherDeviceMetadataDictKey,
util::EncodeProtoMessageAsValueString(&better_together_device_metadata_));
dict.SetKey(kFeatureStatesDictKey,
FeatureStatesToDictionary(feature_states_));
util::EncodeProtoMessageAsValueString(&better_together_device_metadata));
dict.SetKey(kFeatureStatesDictKey, FeatureStatesToDictionary(feature_states));
return dict;
}
bool CryptAuthDevice::operator==(const CryptAuthDevice& other) const {
return instance_id_ == other.instance_id_ &&
device_name_ == other.device_name_ &&
device_better_together_public_key_ ==
other.device_better_together_public_key_ &&
last_update_time_ == other.last_update_time_ &&
better_together_device_metadata_.SerializeAsString() ==
other.better_together_device_metadata_.SerializeAsString() &&
feature_states_ == other.feature_states_;
device_name == other.device_name &&
device_better_together_public_key ==
other.device_better_together_public_key &&
last_update_time == other.last_update_time &&
better_together_device_metadata.SerializeAsString() ==
other.better_together_device_metadata.SerializeAsString() &&
feature_states == other.feature_states;
}
bool CryptAuthDevice::operator!=(const CryptAuthDevice& other) const {
......
......@@ -28,20 +28,7 @@ class CryptAuthDevice {
// |instance_id|: The Instance ID, used as a unique device identifier. Cannot
// be empty.
// |device_name|: The name known to the CryptAuth server or which was assigned
// by the user to the device. Might contain personally identifiable
// information. Cannot be empty.
// |device_better_together_public_key|: The device's
// "DeviceSync:BetterTogether" public key that is enrolled with
// CryptAuth--known as CryptAuthKeyBundle::kDeviceSyncBetterTogether on
// Chrome OS. This is not to be confused with the shared, unenrolled group
// public key. Cannot be empty.
// |last_update_time|: The last time the device updated its information with
// the CryptAuth server. Cannot be null.
// |better_together_device_metadata|: Device metadata relevant to the suite of
// multi-device ("Better Together") features.
// |feature_states|: A map from the multi-device feature type (example:
// kBetterTogetherHost) to feature state (example: kEnabled).
explicit CryptAuthDevice(const std::string& instance_id);
CryptAuthDevice(
const std::string& instance_id,
const std::string& device_name,
......@@ -58,25 +45,6 @@ class CryptAuthDevice {
const std::string& instance_id() const { return instance_id_; }
const std::string& device_name() const { return device_name_; }
const std::string& device_better_together_public_key() const {
return device_better_together_public_key_;
}
const base::Time& last_update_time() const { return last_update_time_; }
const cryptauthv2::BetterTogetherDeviceMetadata&
better_together_device_metadata() const {
return better_together_device_metadata_;
}
const std::map<multidevice::SoftwareFeature,
multidevice::SoftwareFeatureState>&
feature_states() const {
return feature_states_;
}
// Converts CryptAuthDevice to a dictionary-type Value of the form
// {
// "instance_id": |instance_id_|,
......@@ -93,14 +61,30 @@ class CryptAuthDevice {
bool operator==(const CryptAuthDevice& other) const;
bool operator!=(const CryptAuthDevice& other) const;
// The name known to the CryptAuth server or which was assigned by the user to
// the device. Might contain personally identifiable information.
std::string device_name;
// The device's "DeviceSync:BetterTogether" public key that is enrolled with
// CryptAuth--known as CryptAuthKeyBundle::kDeviceSyncBetterTogether on Chrome
// OS. This is not to be confused with the shared, unenrolled group public
// key.
std::string device_better_together_public_key;
// The last time the device updated its information with the CryptAuth server.
base::Time last_update_time;
// Device metadata relevant to the suite of multi-device ("Better Together")
// features.
cryptauthv2::BetterTogetherDeviceMetadata better_together_device_metadata;
// A map from the multi-device feature type (example: kBetterTogetherHost) to
// feature state (example: kEnabled).
std::map<multidevice::SoftwareFeature, multidevice::SoftwareFeatureState>
feature_states;
private:
std::string instance_id_;
std::string device_name_;
std::string device_better_together_public_key_;
base::Time last_update_time_;
cryptauthv2::BetterTogetherDeviceMetadata better_together_device_metadata_;
std::map<multidevice::SoftwareFeature, multidevice::SoftwareFeatureState>
feature_states_;
};
} // namespace device_sync
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment