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.
5 #ifndef COMPONENTS_APDU_APDU_RESPONSE_H_
6 #define COMPONENTS_APDU_APDU_RESPONSE_H_
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"
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 {
24 // Status bytes are specified in ISO 7816-4.
25 enum class Status : uint16_t {
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,
34 // Create a APDU response from the serialized message.
35 static absl::optional<ApduResponse> CreateFromMessage(
36 base::span<const uint8_t> data);
38 ApduResponse(std::vector<uint8_t> data, Status response_status);
39 ApduResponse(ApduResponse&& that);
40 ApduResponse& operator=(ApduResponse&& that);
42 ApduResponse(const ApduResponse&) = delete;
43 ApduResponse& operator=(const ApduResponse&) = delete;
47 std::vector<uint8_t> GetEncodedResponse() const;
49 const std::vector<uint8_t>& data() const { return data_; }
50 Status status() const { return response_status_; }
53 FRIEND_TEST_ALL_PREFIXES(ApduTest, TestDeserializeResponse);
55 std::vector<uint8_t> data_;
56 Status response_status_;
61 #endif // COMPONENTS_APDU_APDU_RESPONSE_H_