| 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, | |
| 27 }; | 26 }; |
| 28 | 27 |
| 29 U2fApduResponse(std::vector<uint8_t> message, Status response_status); | 28 U2fApduResponse(std::vector<uint8_t> message, Status response_status); |
| 30 ~U2fApduResponse(); | 29 ~U2fApduResponse(); |
| 31 | 30 |
| 32 // Create a APDU response from the serialized message | 31 // Create a APDU response from the serialized message |
| 33 static std::unique_ptr<U2fApduResponse> CreateFromMessage( | 32 static std::unique_ptr<U2fApduResponse> CreateFromMessage( |
| 34 const std::vector<uint8_t>& data); | 33 const std::vector<uint8_t>& data); |
| 35 std::vector<uint8_t> GetEncodedResponse() const; | 34 std::vector<uint8_t> GetEncodedResponse() const; |
| 36 const std::vector<uint8_t> data() const { return data_; }; | 35 const std::vector<uint8_t> data() const { return data_; }; |
| 37 Status status() const { return response_status_; }; | 36 Status status() const { return response_status_; }; |
| 38 | 37 |
| 39 private: | 38 private: |
| 40 FRIEND_TEST_ALL_PREFIXES(U2fApduTest, TestDeserializeResponse); | 39 FRIEND_TEST_ALL_PREFIXES(U2fApduTest, TestDeserializeResponse); |
| 41 | 40 |
| 42 Status response_status_; | 41 Status response_status_; |
| 43 std::vector<uint8_t> data_; | 42 std::vector<uint8_t> data_; |
| 44 }; | 43 }; |
| 45 | 44 |
| 46 } // namespace device | 45 } // namespace device |
| 47 | 46 |
| 48 #endif // DEVICE_U2F_U2F_APDU_RESPONSE_H_ | 47 #endif // DEVICE_U2F_U2F_APDU_RESPONSE_H_ |
| OLD | NEW |