File: remote_device.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (78 lines) | stat: -rw-r--r-- 2,815 bytes parent folder | download | duplicates (7)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chromeos/ash/components/multidevice/remote_device.h"

#include "base/base64.h"

namespace ash::multidevice {

// static
std::string RemoteDevice::GenerateDeviceId(const std::string& public_key) {
  return base::Base64Encode(public_key);
}

// static
std::string RemoteDevice::DerivePublicKey(const std::string& device_id) {
  std::string public_key;
  if (base::Base64Decode(device_id, &public_key))
    return public_key;
  return std::string();
}

RemoteDevice::RemoteDevice() : last_update_time_millis(0L) {}

RemoteDevice::RemoteDevice(
    const std::string& user_email,
    const std::string& instance_id,
    const std::string& name,
    const std::string& pii_free_name,
    const std::string& public_key,
    const std::string& persistent_symmetric_key,
    int64_t last_update_time_millis,
    const std::map<SoftwareFeature, SoftwareFeatureState>& software_features,
    const std::vector<BeaconSeed>& beacon_seeds,
    const std::string& bluetooth_public_address)
    : user_email(user_email),
      instance_id(instance_id),
      name(name),
      pii_free_name(pii_free_name),
      public_key(public_key),
      persistent_symmetric_key(persistent_symmetric_key),
      last_update_time_millis(last_update_time_millis),
      software_features(software_features),
      beacon_seeds(beacon_seeds),
      bluetooth_public_address(bluetooth_public_address) {}

RemoteDevice::RemoteDevice(const RemoteDevice& other) = default;

RemoteDevice::~RemoteDevice() {}

std::string RemoteDevice::GetDeviceId() const {
  return RemoteDevice::GenerateDeviceId(public_key);
}

bool RemoteDevice::operator==(const RemoteDevice& other) const {
  return user_email == other.user_email && instance_id == other.instance_id &&
         name == other.name && pii_free_name == other.pii_free_name &&
         public_key == other.public_key &&
         persistent_symmetric_key == other.persistent_symmetric_key &&
         last_update_time_millis == other.last_update_time_millis &&
         software_features == other.software_features &&
         beacon_seeds == other.beacon_seeds &&
         bluetooth_public_address == other.bluetooth_public_address;
}

bool RemoteDevice::operator<(const RemoteDevice& other) const {
  if (!instance_id.empty() || !other.instance_id.empty())
    return instance_id.compare(other.instance_id) < 0;

  // |public_key| can contain null bytes, so use GetDeviceId(), which cannot
  // contain null bytes, to compare devices.
  // Note: Devices that do not have an Instance ID are v1 DeviceSync devices,
  // which should have a public key.
  return GetDeviceId().compare(other.GetDeviceId()) < 0;
}

}  // namespace ash::multidevice