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