Encapsulation of a smartcard response Application Protocol Data Unit (APDU)
The response APDU is the communication message sent from a smartcard to a card reader. This class encapsulates a response APDU, ensuring its validity at construction-time, and guaranteeing it remains valid for the lifetime of the object. The get() method provides read-only access to the raw APDU data.
Additional information may be found at: https://en.wikipedia.org/wiki/Smart_card_application_protocol_data_unit
The full specification of the format is defined in ISO/IEC 7816-3 and ISO/IEC 7816-4.
Thread safety: This class is immutable, and thus fully thread-safe post-construction.
Public Member Functions | |
ResponseAPDU () | |
Construct an empty APDU - no response data, and status set to 0x6F00. More... | |
ResponseAPDU (@NonNull byte[] data, int SW1, int SW2) | |
Create an APDU containing given data and status values. More... | |
ResponseAPDU (@NonNull byte[] stream) | |
Extract APDU data from a byte stream. More... | |
byte [] | get () |
Copy the entire APDU in byte-array format. More... | |
String | hexDump () |
Obtain a hex dump of the entire APDU. More... | |
byte [] | responseData () |
Copy the response data field, if present. More... | |
int | responseDataSize () |
Query the size in bytes of the response (excluding SW1 and SW2) | |
String | statusString () |
Description of the status value stored in fields SW1 and SW2. More... | |
boolean | successComplete () |
Return whether the response indicates successful processing of the command with no further data remaining. More... | |
boolean | successIncomplete () |
Return whether the response indicates successful processing of the command, but there is more data remaining. More... | |
short | SW1 () |
Query the first command processing status byte (SW1) More... | |
short | SW2 () |
Query the second command processing status byte (SW2) More... | |
Static Public Member Functions | |
static String | statusString (int SW1, int SW2) |
String description of a given response status. More... | |
Static Public Attributes | |
static final int | MaxResponseLength |
Maximum permitted response length (excluding status bytes) | |
ResponseAPDU | ( | ) |
Construct an empty APDU - no response data, and status set to 0x6F00.
This constructor should only be used when it is necessary to return a sentinel value, and that some other indication (e.g. an error code parameter) is supplied to a user to notify them that the value is invalid.
ResponseAPDU | ( | @NonNull byte [] | data, |
int | SW1, | ||
int | SW2 | ||
) |
Create an APDU containing given data and status values.
data | Response data; length must not exceed MaxResponseLength |
SW1 | First status byte - e.g. 0x90 for success. Valid ranges are 0x61-0x6F and 0x90-0x9F. |
SW2 | Second status byte - e.g. 0x00 for success. Valid range is 0-255. |
IllegalArgumentException | if SW1 or SW2 are out of range, or if data is too long |
ResponseAPDU | ( | @NonNull byte [] | stream | ) |
Extract APDU data from a byte stream.
The last two bytes in the array are used to construct the SW1 and SW2 fields; the remainder is treated as response data.
stream | APDU data stream; length must be at least 2 bytes, and at most MaxResponseLength + 2 |
IllegalArgumentException | if data length is illegal, or if the second-last byte holds an invalid value for SW1 |
byte [] get | ( | ) |
Copy the entire APDU in byte-array format.
String hexDump | ( | ) |
Obtain a hex dump of the entire APDU.
byte [] responseData | ( | ) |
Copy the response data field, if present.
String statusString | ( | ) |
Description of the status value stored in fields SW1 and SW2.
|
static |
String description of a given response status.
SW1 | First status byte, valid ranges 0x61-0x6F and 0x90-0x9F |
SW2 | Second status byte, valid range 0-255 |
IllegalArgumentException | if either of the parameters are out of range |
boolean successComplete | ( | ) |
Return whether the response indicates successful processing of the command with no further data remaining.
boolean successIncomplete | ( | ) |
Return whether the response indicates successful processing of the command, but there is more data remaining.
short SW1 | ( | ) |
Query the first command processing status byte (SW1)
short SW2 | ( | ) |
Query the second command processing status byte (SW2)