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

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

Issue 2743623006: Modify U2F apdu classes to use unique pointers (Closed)
Patch Set: Use more concise form of base::Passed 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
« no previous file with comments | « device/u2f/u2f_apdu_response.h ('k') | device/u2f/u2f_apdu_unittest.cc » ('j') | 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/memory/ptr_util.h"
6
5 #include "u2f_apdu_response.h" 7 #include "u2f_apdu_response.h"
6 8
7 namespace device { 9 namespace device {
8 scoped_refptr<U2fApduResponse> U2fApduResponse::CreateFromMessage( 10 std::unique_ptr<U2fApduResponse> U2fApduResponse::CreateFromMessage(
9 const std::vector<uint8_t>& message) { 11 const std::vector<uint8_t>& message) {
10 uint16_t status_bytes; 12 uint16_t status_bytes;
11 Status response_status; 13 Status response_status;
12 14
13 // Invalid message size, data is appended by status byte 15 // Invalid message size, data is appended by status byte
14 if (message.size() < 2) 16 if (message.size() < 2)
15 return nullptr; 17 return nullptr;
16 status_bytes = message[message.size() - 2] << 8; 18 status_bytes = message[message.size() - 2] << 8;
17 status_bytes |= message[message.size() - 1]; 19 status_bytes |= message[message.size() - 1];
18 response_status = static_cast<Status>(status_bytes); 20 response_status = static_cast<Status>(status_bytes);
19 std::vector<uint8_t> data(message.begin(), message.end() - 2); 21 std::vector<uint8_t> data(message.begin(), message.end() - 2);
20 22
21 return make_scoped_refptr( 23 return base::MakeUnique<U2fApduResponse>(std::move(data), response_status);
22 new U2fApduResponse(std::move(data), response_status));
23 } 24 }
24 25
25 U2fApduResponse::U2fApduResponse(std::vector<uint8_t> message, 26 U2fApduResponse::U2fApduResponse(std::vector<uint8_t> message,
26 Status response_status) 27 Status response_status)
27 : response_status_(response_status), data_(std::move(message)) {} 28 : response_status_(response_status), data_(std::move(message)) {}
28 29
29 U2fApduResponse::~U2fApduResponse() {} 30 U2fApduResponse::~U2fApduResponse() {}
30 31
31 } // namespace device 32 } // namespace device
OLDNEW
« no previous file with comments | « device/u2f/u2f_apdu_response.h ('k') | device/u2f/u2f_apdu_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698