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 #ifndef DEVICE_U2F_U2F_APDU_RESPONSE_H_ | 5 #ifndef DEVICE_U2F_U2F_APDU_RESPONSE_H_ |
6 #define DEVICE_U2F_U2F_APDU_RESPONSE_H_ | 6 #define DEVICE_U2F_U2F_APDU_RESPONSE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 | 13 |
14 namespace device { | 14 namespace device { |
15 | 15 |
16 // APDU responses are defined as part of ISO 7816-4. Serialized responses | 16 // APDU responses are defined as part of ISO 7816-4. Serialized responses |
17 // consist of a data field of varying length, up to a maximum 65536, and a | 17 // consist of a data field of varying length, up to a maximum 65536, and a |
18 // two byte status field. | 18 // two byte status field. |
19 class U2fApduResponse { | 19 class U2fApduResponse { |
20 public: | 20 public: |
21 // Status bytes are specified in ISO 7816-4 | 21 // Status bytes are specified in ISO 7816-4 |
22 enum class Status : uint16_t { | 22 enum class Status : uint16_t { |
23 SW_NO_ERROR = 0x9000, | 23 SW_NO_ERROR = 0x9000, |
24 SW_CONDITIONS_NOT_SATISFIED = 0x6985, | 24 SW_CONDITIONS_NOT_SATISFIED = 0x6985, |
25 SW_WRONG_DATA = 0x6A80, | 25 SW_WRONG_DATA = 0x6A80, |
| 26 SW_WRONG_LENGTH = 0x6700, |
26 }; | 27 }; |
27 | 28 |
28 U2fApduResponse(std::vector<uint8_t> message, Status response_status); | 29 U2fApduResponse(std::vector<uint8_t> message, Status response_status); |
29 ~U2fApduResponse(); | 30 ~U2fApduResponse(); |
30 | 31 |
31 // Create a APDU response from the serialized message | 32 // Create a APDU response from the serialized message |
32 static std::unique_ptr<U2fApduResponse> CreateFromMessage( | 33 static std::unique_ptr<U2fApduResponse> CreateFromMessage( |
33 const std::vector<uint8_t>& data); | 34 const std::vector<uint8_t>& data); |
34 std::vector<uint8_t> GetEncodedResponse() const; | 35 std::vector<uint8_t> GetEncodedResponse() const; |
35 const std::vector<uint8_t> data() const { return data_; }; | 36 const std::vector<uint8_t> data() const { return data_; }; |
36 Status status() const { return response_status_; }; | 37 Status status() const { return response_status_; }; |
37 | 38 |
38 private: | 39 private: |
39 FRIEND_TEST_ALL_PREFIXES(U2fApduTest, TestDeserializeResponse); | 40 FRIEND_TEST_ALL_PREFIXES(U2fApduTest, TestDeserializeResponse); |
40 | 41 |
41 Status response_status_; | 42 Status response_status_; |
42 std::vector<uint8_t> data_; | 43 std::vector<uint8_t> data_; |
43 }; | 44 }; |
44 | 45 |
45 } // namespace device | 46 } // namespace device |
46 | 47 |
47 #endif // DEVICE_U2F_U2F_APDU_RESPONSE_H_ | 48 #endif // DEVICE_U2F_U2F_APDU_RESPONSE_H_ |
OLD | NEW |