[M120 Migration][VD] Enable direct rendering for TVPlus
[platform/framework/web/chromium-efl.git] / components / apdu / apdu_response.cc
1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/apdu/apdu_response.h"
6
7 #include <utility>
8
9 #include "base/numerics/safe_conversions.h"
10
11 namespace apdu {
12
13 // static
14 absl::optional<ApduResponse> ApduResponse::CreateFromMessage(
15     base::span<const uint8_t> data) {
16   // Invalid message size, data is appended by status byte.
17   if (data.size() < 2)
18     return absl::nullopt;
19
20   uint16_t status_bytes = data[data.size() - 2] << 8;
21   status_bytes |= data[data.size() - 1];
22
23   return ApduResponse(std::vector<uint8_t>(data.begin(), data.end() - 2),
24                       static_cast<Status>(status_bytes));
25 }
26
27 ApduResponse::ApduResponse(std::vector<uint8_t> data, Status response_status)
28     : data_(std::move(data)), response_status_(response_status) {}
29
30 ApduResponse::ApduResponse(ApduResponse&& that) = default;
31
32 ApduResponse& ApduResponse::operator=(ApduResponse&& that) = default;
33
34 ApduResponse::~ApduResponse() = default;
35
36 std::vector<uint8_t> ApduResponse::GetEncodedResponse() const {
37   std::vector<uint8_t> encoded_response = data_;
38   encoded_response.push_back(
39       base::strict_cast<uint16_t>(response_status_) >> 8 & 0xff);
40   encoded_response.push_back(base::strict_cast<uint16_t>(response_status_) &
41                              0xff);
42   return encoded_response;
43 }
44
45 }  // namespace apdu