Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(798)

Side by Side Diff: components/cryptauth/remote_device.cc

Issue 2590713002: [CrOS Tether] Add a static TruncateDeviceIdForLogs() function. (Closed)
Patch Set: Fix style and variable name. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/cryptauth/remote_device.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/cryptauth/remote_device.h" 5 #include "components/cryptauth/remote_device.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 8
9 namespace cryptauth { 9 namespace cryptauth {
10 10
(...skipping 12 matching lines...) Expand all
23 bluetooth_type(bluetooth_type), 23 bluetooth_type(bluetooth_type),
24 bluetooth_address(bluetooth_address), 24 bluetooth_address(bluetooth_address),
25 persistent_symmetric_key(persistent_symmetric_key), 25 persistent_symmetric_key(persistent_symmetric_key),
26 sign_in_challenge(sign_in_challenge) {} 26 sign_in_challenge(sign_in_challenge) {}
27 27
28 RemoteDevice::RemoteDevice(const RemoteDevice& other) = default; 28 RemoteDevice::RemoteDevice(const RemoteDevice& other) = default;
29 29
30 RemoteDevice::~RemoteDevice() {} 30 RemoteDevice::~RemoteDevice() {}
31 31
32 std::string RemoteDevice::GetDeviceId() const { 32 std::string RemoteDevice::GetDeviceId() const {
33 std::string to_return; 33 std::string to_return;
34 base::Base64Encode(public_key, &to_return); 34 base::Base64Encode(public_key, &to_return);
35 return to_return; 35 return to_return;
36 } 36 }
37 37
38 std::string RemoteDevice::GetTruncatedDeviceIdForLogs() const { 38 std::string RemoteDevice::GetTruncatedDeviceIdForLogs() const {
39 std::string id = GetDeviceId(); 39 return RemoteDevice::TruncateDeviceIdForLogs(GetDeviceId());
40 if (id.length() <= 10) {
41 return id;
42 }
43
44 return id.substr(0, 5) + "..." + id.substr(id.length() - 5, id.length());
45 } 40 }
46 41
47 bool RemoteDevice::operator==(const RemoteDevice& other) const { 42 bool RemoteDevice::operator==(const RemoteDevice& other) const {
48 return user_id == other.user_id 43 return user_id == other.user_id
49 && name == other.name 44 && name == other.name
50 && public_key == other.public_key 45 && public_key == other.public_key
51 && bluetooth_type == other.bluetooth_type 46 && bluetooth_type == other.bluetooth_type
52 && bluetooth_address == other.bluetooth_address 47 && bluetooth_address == other.bluetooth_address
53 && persistent_symmetric_key == other.persistent_symmetric_key 48 && persistent_symmetric_key == other.persistent_symmetric_key
54 && sign_in_challenge == other.sign_in_challenge; 49 && sign_in_challenge == other.sign_in_challenge;
50 }
51
52 // static
53 std::string RemoteDevice::TruncateDeviceIdForLogs(const std::string& full_id) {
54 if (full_id.length() <= 10) {
55 return full_id;
56 }
57
58 return full_id.substr(0, 5)
59 + "..."
60 + full_id.substr(full_id.length() - 5, full_id.length());
55 } 61 }
56 62
57 } // namespace cryptauth 63 } // namespace cryptauth
OLDNEW
« no previous file with comments | « components/cryptauth/remote_device.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698