public class CommandAPDU
extends java.lang.Object
Overview over APDUs
CLA | INS | P1 | P2 | Lc | Data | Le |
---|---|---|---|---|---|---|
Header (required) | Body (optional) |
APDUs consist of two Parts:
The header consists of four Bytes:
The body is of variable length, depending on the APDU Case and if it's a Standard or an Extended APDU. The Fields in the body have the following meanings:
There are four types of Command APDUs:
The Function
boolean isValidAPDU()
returns true only if all the rules above are followed.
If the APDU isn't valid, the behaviour of the class isn't specified (This
includes exceptions).
Modifier and Type | Field and Description |
---|---|
private byte[] |
data
Contains the bytearray-Representation of this APDU
|
static byte |
INS_GET_PENDING_RESULT |
static byte |
INS_GET_REMAINING_RESULT |
Constructor and Description |
---|
CommandAPDU(byte[] data)
Creates a CommandAPDU object out of the raw bytes of an APDU.
|
CommandAPDU(byte[] header,
byte[] body,
java.lang.Byte le)
Creates a
CommandAPDU object from header, body and le. |
Modifier and Type | Method and Description |
---|---|
byte[] |
getArgumentData()
Returns the Argument Data of this APDU.
|
byte |
getCla()
Returns the CLA byte of the header of this APDU.
|
byte |
getIns()
Returns the INS byte of the header of this APDU.
|
int |
getLc()
Returns the Value of the Lc field of this APDU if present, or
0 otherwise. |
int |
getLe()
Returns the Value of the Le field of this APDU, or
-1 if not
present. |
byte |
getP1()
Returns the P1 byte of the header of this APDU.
|
byte |
getP2()
Returns the P2 byte of the header of this APDU.
|
byte[] |
getRaw()
Returns a Copy of the underlying bytearray.
|
boolean |
hasData()
Returns whether the Data field is present in this APDU.
|
private boolean |
isEmpty(byte[] bs) |
boolean |
isExtendedAPDU()
Returns whether this APDU uses the extended format.
|
boolean |
isValidAPDU()
Checks if the APDU is valid.
|
java.lang.String |
toString() |
public static final byte INS_GET_PENDING_RESULT
public static final byte INS_GET_REMAINING_RESULT
private final byte[] data
public CommandAPDU(byte[] data)
data
- The Bytearray containing the Command APDUpublic CommandAPDU(byte[] header, byte[] body, java.lang.Byte le)
CommandAPDU
object from header, body and le. Does not support extended APDU.header
- The Bytearray containing the header.body
- The Bytearray containing the body. Null if no body.le
- The Bytearray containing the response length expected. Null if no response expected.private boolean isEmpty(byte[] bs)
public boolean isValidAPDU()
true
if the APDU is a correct APDU according to the
standards definition, false
otherwise.public boolean hasData()
true
if the APDU contains a Data field,
false
otherwise.public byte getCla()
public byte getIns()
public byte getP1()
public byte getP2()
public int getLe()
-1
if not
present. The interpretation depends on whether this is a Standard or an
Extended APDU.-1
if not present.
0
is to be interpreted as 65536 (Extended APDU) or
256 (Standard APDU), see
boolean isExtendedAPDU()
.public int getLc()
0
otherwise.0
if not present.public byte[] getArgumentData()
byte[]
with the length getLc()
, filled
with the Argument Data. If no Argument Data is present, an empty
bytearray is returned.public boolean isExtendedAPDU()
true
if this APDU uses the extended length field
notation, false
otherwise.public byte[] getRaw()
byte[]
-Representation of this APDU.public java.lang.String toString()
toString
in class java.lang.Object