Encapsulation of a smartcard command Application Protocol Data Unit (APDU)
The command APDU is the communication message sent from a card reader to a smartcard. This class encapsulates a command 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 this format is found in ISO/IEC 7816-3 and ISO/IEC 7816-4.
- Invariant
- Stored fields are all within range for the APDU format.
Thread safety: This class is immutable, and thus fully thread-safe post-construction.
- See also
- ResponseAPDU for the response equivalent, and SmartcardAPI for related functionality
|
| CommandAPDU () |
| Construct a null APDU - only compulsory fields are present, and everything is set to zero.
|
|
| CommandAPDU (int CLA, int INS, int P1, int P2) |
| Construct an APDU as per ISO/IEC 7816-3 case 1 (i.e. no Lc, Le or command-data fields) More...
|
|
| CommandAPDU (int CLA, int INS, int P1, int P2, int Ne) |
| Construct an APDU as per ISO/IEC 7816-3 case 2 (i.e. Le field present, but no Lc or command-data fields) More...
|
|
| CommandAPDU (int CLA, int INS, int P1, int P2, @NonNull byte[] data) |
| Construct an APDU as per ISO/IEC 7816-3 case 3 (i.e. Lc and command-data fields present, but no Le field) More...
|
|
| CommandAPDU (int CLA, int INS, int P1, int P2, @NonNull byte[] data, int Ne) |
| Construct an APDU as per ISO/IEC 7816-3 case 4 (i.e. Lc, command-data and Le fields all present) More...
|
|
| CommandAPDU (@NonNull byte[] stream) |
| Extract APDU data from a byte stream. More...
|
|
short | CLA () |
| Query the instruction class (type of smartcard command) More...
|
|
byte [] | commandData () |
| Copy the command data, if present. More...
|
|
boolean | commandDataPresent () |
| Are the Lc and command-data fields present in this APDU? More...
|
|
byte [] | get () |
| Copy the entire APDU in byte-array format. More...
|
|
byte [] | header () |
| Copy the four header fields CLA, INS, P1 and P2 in byte-array format. More...
|
|
String | hexDump () |
| Obtain a hex dump of the entire APDU. More...
|
|
short | INS () |
| Query the instruction code (indication of specific command) More...
|
|
byte [] | Lc () |
| Query the encoded length in bytes of the command data (Lc), if present. More...
|
|
byte [] | Le () |
| Query the encoded maximum expected response length (Le) in bytes. More...
|
|
boolean | Le_Present () |
| Is the encoded maximum expected response length field (Le) present in this APDU? More...
|
|
int | Nc () |
| Query the length of the command data (Nc), if there is any. More...
|
|
int | Ne () |
| Query the maximum expected response length (Ne) in bytes. More...
|
|
short | P1 () |
| Query the first parameter byte for the command. More...
|
|
short | P2 () |
| Query the second parameter byte for the command. More...
|
|
boolean | shortEncoding () |
| Are the Lc and Le fields using the "short" encoding? More...
|
|
Extract APDU data from a byte stream.
The first four bytes of the stream are used to construct the CLA, INS, P1 and P2 fields respectively.
If no data is present beyond the first four bytes, then Nc = Ne = 0 and parsing is considered successful.
Otherwise, the remaining bytes are used to populate the optional Lc field, the optional command-data field, and the optional Le field. The following combinations are tested, in the following order:
- Short Lc, Nc bytes of command data, no Le
- Short Lc, Nc bytes of command data, short Le
- Extended Lc, Nc bytes of command data, no Le
- Extended Lc, Nc bytes of command data, extended Le
- No Lc, no command data, short Le
- No Lc, no command data, extended Le If none of the combinations match then parsing is considered to have failed.
- Parameters
-
stream | APDU data stream; must contain a valid command APDU (and only that APDU - no additional leading or trailing bytes are permitted) |
- Exceptions
-
InvalidArgument | if the stream could not be parsed successfully |