OLD | NEW |
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 |
OLD | NEW |