[M120 Migration][VD] Enable direct rendering for TVPlus
[platform/framework/web/chromium-efl.git] / components / apdu / apdu_response.h
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 #ifndef COMPONENTS_APDU_APDU_RESPONSE_H_
6 #define COMPONENTS_APDU_APDU_RESPONSE_H_
7
8 #include <stdint.h>
9
10 #include <vector>
11
12 #include "base/component_export.h"
13 #include "base/containers/span.h"
14 #include "base/gtest_prod_util.h"
15 #include "third_party/abseil-cpp/absl/types/optional.h"
16
17 namespace apdu {
18
19 // APDU responses are defined as part of ISO 7816-4. Serialized responses
20 // consist of a data field of varying length, up to a maximum 65536, and a
21 // two byte status field.
22 class COMPONENT_EXPORT(APDU) ApduResponse {
23  public:
24   // Status bytes are specified in ISO 7816-4.
25   enum class Status : uint16_t {
26     SW_NO_ERROR = 0x9000,
27     SW_CONDITIONS_NOT_SATISFIED = 0x6985,
28     SW_COMMAND_NOT_ALLOWED = 0x6986,
29     SW_WRONG_DATA = 0x6A80,
30     SW_WRONG_LENGTH = 0x6700,
31     SW_INS_NOT_SUPPORTED = 0x6D00,
32   };
33
34   // Create a APDU response from the serialized message.
35   static absl::optional<ApduResponse> CreateFromMessage(
36       base::span<const uint8_t> data);
37
38   ApduResponse(std::vector<uint8_t> data, Status response_status);
39   ApduResponse(ApduResponse&& that);
40   ApduResponse& operator=(ApduResponse&& that);
41
42   ApduResponse(const ApduResponse&) = delete;
43   ApduResponse& operator=(const ApduResponse&) = delete;
44
45   ~ApduResponse();
46
47   std::vector<uint8_t> GetEncodedResponse() const;
48
49   const std::vector<uint8_t>& data() const { return data_; }
50   Status status() const { return response_status_; }
51
52  private:
53   FRIEND_TEST_ALL_PREFIXES(ApduTest, TestDeserializeResponse);
54
55   std::vector<uint8_t> data_;
56   Status response_status_;
57 };
58
59 }  // namespace apdu
60
61 #endif  // COMPONENTS_APDU_APDU_RESPONSE_H_