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

Side by Side Diff: device/u2f/u2f_device.cc

Issue 2743623006: Modify U2F apdu classes to use unique pointers (Closed)
Patch Set: Created 3 years, 9 months 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
« device/u2f/u2f_apdu_unittest.cc ('K') | « device/u2f/u2f_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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "u2f_apdu_command.h" 6 #include "u2f_apdu_command.h"
7 #include "u2f_device.h" 7 #include "u2f_device.h"
8 8
9 namespace device { 9 namespace device {
10 10
11 U2fDevice::U2fDevice() : weak_factory_(this) {} 11 U2fDevice::U2fDevice() : weak_factory_(this) {}
12 12
13 U2fDevice::~U2fDevice() {} 13 U2fDevice::~U2fDevice() {}
14 14
15 void U2fDevice::Register(const std::vector<uint8_t>& app_param, 15 void U2fDevice::Register(const std::vector<uint8_t>& app_param,
16 U2fDevice::ProtocolVersion version, 16 U2fDevice::ProtocolVersion version,
17 const std::vector<uint8_t>& challenge_param, 17 const std::vector<uint8_t>& challenge_param,
18 const MessageCallback& callback) { 18 const MessageCallback& callback) {
19 scoped_refptr<U2fApduCommand> register_cmd = 19 std::unique_ptr<U2fApduCommand> register_cmd =
20 U2fApduCommand::CreateRegister(app_param, challenge_param); 20 U2fApduCommand::CreateRegister(app_param, challenge_param);
21 if (!register_cmd) { 21 if (!register_cmd) {
22 callback.Run(ReturnCode::INVALID_PARAMS, std::vector<uint8_t>()); 22 callback.Run(ReturnCode::INVALID_PARAMS, std::vector<uint8_t>());
23 return; 23 return;
24 } 24 }
25 DeviceTransact(std::move(register_cmd), 25 DeviceTransact(std::move(register_cmd),
26 base::Bind(&U2fDevice::OnRegisterComplete, 26 base::Bind(&U2fDevice::OnRegisterComplete,
27 weak_factory_.GetWeakPtr(), callback)); 27 weak_factory_.GetWeakPtr(), callback));
28 } 28 }
29 29
30 void U2fDevice::Sign(const std::vector<uint8_t>& app_param, 30 void U2fDevice::Sign(const std::vector<uint8_t>& app_param,
31 const std::vector<uint8_t>& challenge_param, 31 const std::vector<uint8_t>& challenge_param,
32 const std::vector<uint8_t>& key_handle, 32 const std::vector<uint8_t>& key_handle,
33 const MessageCallback& callback) { 33 const MessageCallback& callback) {
34 scoped_refptr<U2fApduCommand> sign_cmd = 34 std::unique_ptr<U2fApduCommand> sign_cmd =
35 U2fApduCommand::CreateSign(app_param, challenge_param, key_handle); 35 U2fApduCommand::CreateSign(app_param, challenge_param, key_handle);
36 if (!sign_cmd) { 36 if (!sign_cmd) {
37 callback.Run(ReturnCode::INVALID_PARAMS, std::vector<uint8_t>()); 37 callback.Run(ReturnCode::INVALID_PARAMS, std::vector<uint8_t>());
38 return; 38 return;
39 } 39 }
40 DeviceTransact(std::move(sign_cmd), 40 DeviceTransact(std::move(sign_cmd),
41 base::Bind(&U2fDevice::OnSignComplete, 41 base::Bind(&U2fDevice::OnSignComplete,
42 weak_factory_.GetWeakPtr(), callback)); 42 weak_factory_.GetWeakPtr(), callback));
43 } 43 }
44 44
45 void U2fDevice::Version(const VersionCallback& callback) { 45 void U2fDevice::Version(const VersionCallback& callback) {
46 scoped_refptr<U2fApduCommand> version_cmd = U2fApduCommand::CreateVersion(); 46 std::unique_ptr<U2fApduCommand> version_cmd = U2fApduCommand::CreateVersion();
47 if (!version_cmd) { 47 if (!version_cmd) {
48 callback.Run(false, ProtocolVersion::UNKNOWN); 48 callback.Run(false, ProtocolVersion::UNKNOWN);
49 return; 49 return;
50 } 50 }
51 DeviceTransact(std::move(version_cmd), 51 DeviceTransact(std::move(version_cmd),
52 base::Bind(&U2fDevice::OnVersionComplete, 52 base::Bind(&U2fDevice::OnVersionComplete,
53 weak_factory_.GetWeakPtr(), callback)); 53 weak_factory_.GetWeakPtr(), callback));
54 } 54 }
55 55
56 void U2fDevice::OnRegisterComplete( 56 void U2fDevice::OnRegisterComplete(
57 const MessageCallback& callback, 57 const MessageCallback& callback,
58 bool success, 58 bool success,
59 scoped_refptr<U2fApduResponse> register_response) { 59 std::unique_ptr<U2fApduResponse> register_response) {
60 NOTIMPLEMENTED(); 60 NOTIMPLEMENTED();
61 } 61 }
62 62
63 void U2fDevice::OnSignComplete(const MessageCallback& callback, 63 void U2fDevice::OnSignComplete(const MessageCallback& callback,
64 bool success, 64 bool success,
65 scoped_refptr<U2fApduResponse> sign_response) { 65 std::unique_ptr<U2fApduResponse> sign_response) {
66 NOTIMPLEMENTED(); 66 NOTIMPLEMENTED();
67 } 67 }
68 68
69 void U2fDevice::OnVersionComplete( 69 void U2fDevice::OnVersionComplete(
70 const VersionCallback& callback, 70 const VersionCallback& callback,
71 bool success, 71 bool success,
72 scoped_refptr<U2fApduResponse> version_response) { 72 std::unique_ptr<U2fApduResponse> version_response) {
73 if (success && version_response && 73 if (success && version_response &&
74 version_response->status() == U2fApduResponse::Status::SW_NO_ERROR && 74 version_response->status() == U2fApduResponse::Status::SW_NO_ERROR &&
75 version_response->data() == 75 version_response->data() ==
76 std::vector<uint8_t>({'U', '2', 'F', '_', 'V', '2'})) { 76 std::vector<uint8_t>({'U', '2', 'F', '_', 'V', '2'})) {
77 callback.Run(success, ProtocolVersion::U2F_V2); 77 callback.Run(success, ProtocolVersion::U2F_V2);
78 return; 78 return;
79 } 79 }
80 callback.Run(success, ProtocolVersion::UNKNOWN); 80 callback.Run(success, ProtocolVersion::UNKNOWN);
81 } 81 }
82 82
83 void U2fDevice::OnLegacyVersionComplete( 83 void U2fDevice::OnLegacyVersionComplete(
84 const VersionCallback& callback, 84 const VersionCallback& callback,
85 bool success, 85 bool success,
86 scoped_refptr<U2fApduResponse> legacy_version_response) { 86 std::unique_ptr<U2fApduResponse> legacy_version_response) {
87 NOTIMPLEMENTED(); 87 NOTIMPLEMENTED();
88 } 88 }
89 89
90 } // namespace device 90 } // namespace device
OLDNEW
« device/u2f/u2f_apdu_unittest.cc ('K') | « device/u2f/u2f_device.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698