public final class CommandAPDU extends Object implements Serializable
Note that when the expected length of the response APDU is specified in the constructors, the actual length (Ne) must be specified, not its encoded form (Le). Similarly, getNe() returns the actual value Ne. In other words, a value of 0 means "no data in the response APDU" rather than "maximum length."
This class supports both the short and extended forms of length encoding for Ne and Nc. However, note that not all terminals and Smart Cards are capable of accepting APDUs that use the extended form.
For the header bytes CLA, INS, P1, and P2 the Java type int
is used to represent the 8 bit unsigned values. In the constructors, only
the 8 lowest bits of the int
value specified by the application
are significant. The accessor methods always return the byte as an unsigned
value between 0 and 255.
Instances of this class are immutable. Where data is passed in or out via byte arrays, defensive cloning is performed.
ResponseAPDU
,
CardChannel.transmit
,
Serialized FormConstructor and Description |
---|
CommandAPDU(byte[] apdu)
Constructs a CommandAPDU from a byte array containing the complete
APDU contents (header and body).
|
CommandAPDU(byte[] apdu,
int apduOffset,
int apduLength)
Constructs a CommandAPDU from a byte array containing the complete
APDU contents (header and body).
|
CommandAPDU(ByteBuffer apdu)
Creates a CommandAPDU from the ByteBuffer containing the complete APDU
contents (header and body).
|
CommandAPDU(int cla,
int ins,
int p1,
int p2)
Constructs a CommandAPDU from the four header bytes.
|
CommandAPDU(int cla,
int ins,
int p1,
int p2,
byte[] data)
Constructs a CommandAPDU from the four header bytes and command data.
|
CommandAPDU(int cla,
int ins,
int p1,
int p2,
byte[] data,
int ne)
Constructs a CommandAPDU from the four header bytes, command data,
and expected response data length.
|
CommandAPDU(int cla,
int ins,
int p1,
int p2,
byte[] data,
int dataOffset,
int dataLength)
Constructs a CommandAPDU from the four header bytes and command data.
|
CommandAPDU(int cla,
int ins,
int p1,
int p2,
byte[] data,
int dataOffset,
int dataLength,
int ne)
Constructs a CommandAPDU from the four header bytes, command data,
and expected response data length.
|
CommandAPDU(int cla,
int ins,
int p1,
int p2,
int ne)
Constructs a CommandAPDU from the four header bytes and the expected
response data length.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj)
Compares the specified object with this command APDU for equality.
|
byte[] |
getBytes()
Returns a copy of the bytes in this APDU.
|
int |
getCLA()
Returns the value of the class byte CLA.
|
byte[] |
getData()
Returns a copy of the data bytes in the command body.
|
int |
getINS()
Returns the value of the instruction byte INS.
|
int |
getNc()
Returns the number of data bytes in the command body (Nc) or 0 if this
APDU has no body.
|
int |
getNe()
Returns the maximum number of expected data bytes in a response
APDU (Ne).
|
int |
getP1()
Returns the value of the parameter byte P1.
|
int |
getP2()
Returns the value of the parameter byte P2.
|
int |
hashCode()
Returns the hash code value for this command APDU.
|
String |
toString()
Returns a string representation of this command APDU.
|
public CommandAPDU(byte[] apdu)
Note that the apdu bytes are copied to protect against subsequent modification.
apdu
- the complete command APDUNullPointerException
- if apdu is nullIllegalArgumentException
- if apdu does not contain a valid
command APDUpublic CommandAPDU(byte[] apdu, int apduOffset, int apduLength)
apduOffset
in the byte array and is apduLength
bytes long.
Note that the apdu bytes are copied to protect against subsequent modification.
apdu
- the complete command APDUapduOffset
- the offset in the byte array at which the apdu
data beginsapduLength
- the length of the APDUNullPointerException
- if apdu is nullIllegalArgumentException
- if apduOffset or apduLength are
negative or if apduOffset + apduLength are greater than apdu.length,
or if the specified bytes are not a valid APDUpublic CommandAPDU(ByteBuffer apdu)
position
must be set to the start of the APDU,
its limit
to the end of the APDU. Upon return, the buffer's
position
is equal to its limit; its limit remains unchanged.
Note that the data in the ByteBuffer is copied to protect against subsequent modification.
apdu
- the ByteBuffer containing the complete APDUNullPointerException
- if apdu is nullIllegalArgumentException
- if apdu does not contain a valid
command APDUpublic CommandAPDU(int cla, int ins, int p1, int p2)
cla
- the class byte CLAins
- the instruction byte INSp1
- the parameter byte P1p2
- the parameter byte P2public CommandAPDU(int cla, int ins, int p1, int p2, int ne)
cla
- the class byte CLAins
- the instruction byte INSp1
- the parameter byte P1p2
- the parameter byte P2ne
- the maximum number of expected data bytes in a response APDUIllegalArgumentException
- if ne is negative or greater than
65536public CommandAPDU(int cla, int ins, int p1, int p2, byte[] data)
data
is null or
its length is 0, the APDU is encoded as ISO 7816 case 1.
Note that the data bytes are copied to protect against subsequent modification.
cla
- the class byte CLAins
- the instruction byte INSp1
- the parameter byte P1p2
- the parameter byte P2data
- the byte array containing the data bytes of the command bodyIllegalArgumentException
- if data.length is greater than 65535public CommandAPDU(int cla, int ins, int p1, int p2, byte[] data, int dataOffset, int dataLength)
dataLength
is 0, the APDU is encoded as ISO 7816 case 1.
Note that the data bytes are copied to protect against subsequent modification.
cla
- the class byte CLAins
- the instruction byte INSp1
- the parameter byte P1p2
- the parameter byte P2data
- the byte array containing the data bytes of the command bodydataOffset
- the offset in the byte array at which the data
bytes of the command body begindataLength
- the number of the data bytes in the command bodyNullPointerException
- if data is null and dataLength is not 0IllegalArgumentException
- if dataOffset or dataLength are
negative or if dataOffset + dataLength are greater than data.length
or if dataLength is greater than 65535public CommandAPDU(int cla, int ins, int p1, int p2, byte[] data, int ne)
data
is non-null and as 0 otherwise. If Ne or Nc
are zero, the APDU is encoded as case 1, 2, or 3 per ISO 7816.
Note that the data bytes are copied to protect against subsequent modification.
cla
- the class byte CLAins
- the instruction byte INSp1
- the parameter byte P1p2
- the parameter byte P2data
- the byte array containing the data bytes of the command bodyne
- the maximum number of expected data bytes in a response APDUIllegalArgumentException
- if data.length is greater than 65535
or if ne is negative or greater than 65536public CommandAPDU(int cla, int ins, int p1, int p2, byte[] data, int dataOffset, int dataLength, int ne)
dataLength
.
If Ne or Nc
are zero, the APDU is encoded as case 1, 2, or 3 per ISO 7816.
Note that the data bytes are copied to protect against subsequent modification.
cla
- the class byte CLAins
- the instruction byte INSp1
- the parameter byte P1p2
- the parameter byte P2data
- the byte array containing the data bytes of the command bodydataOffset
- the offset in the byte array at which the data
bytes of the command body begindataLength
- the number of the data bytes in the command bodyne
- the maximum number of expected data bytes in a response APDUNullPointerException
- if data is null and dataLength is not 0IllegalArgumentException
- if dataOffset or dataLength are
negative or if dataOffset + dataLength are greater than data.length,
or if ne is negative or greater than 65536,
or if dataLength is greater than 65535public int getCLA()
public int getINS()
public int getP1()
public int getP2()
public int getNc()
getData().length
.public byte[] getData()
public int getNe()
public byte[] getBytes()
public String toString()
public boolean equals(Object obj)
equals
in class Object
obj
- the object to be compared for equality with this command APDUObject.hashCode()
,
HashMap
public int hashCode()
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
Copyright © 2005, 2015, Oracle and/or its affiliates. All rights reserved.