ViewHandlerpublic abstract class ViewHandler extends Object The ViewHandler class offers basic services and contains basic
methods to handle
a Simple TLV List, such as in a Terminal Response data field
or in a BER-TLV
element (Envelope data field or Proactive command).
The byte at offset 0 of a handler is the tag of the first Simple TLV. |
Fields Summary |
---|
protected static final byte | BER_TLV_TAG_OFFSETOffset of BER_TLV_TAG. | protected static final byte | OFFSET_LCOffset of Lc in the APDU buffer. | protected static final byte | TPUD_OFFSETOffset of TPDUD. | private static final byte | DEVICE_ID_TAGTag of DEVICE_ID field. | private static final byte | DEVICE_ID_LENGTHLength of DEVICE_ID field. | private static final byte | ADDRESS_TAGTag of ADDRESS field. | private static final byte | SMS_TPDU_TAGTag of SMS_TPDU. | short | currentTLVOffsetOffset of first occurrence of TLV. | short | firstTLVOffsetOffset of first occurrence of TLV. | public static AccessSAT | SATAccessorReference to SAT Accessor. | public static ToolkitInterface | currentTIReference to TI which is now serviced. |
Constructors Summary |
---|
ViewHandler()Constructor.
| ViewHandler(byte[] buffer, short offset, short length)Builds a new ViewHandler object.
|
Methods Summary |
---|
public byte | compareValue(short valueOffset, byte[] compareBuffer, short compareOffset, short compareLength)Compares the last found TLV element with a buffer.
Notes:
- If
compareOffset or
compareLength parameter is negative
an ArrayIndexOutOfBoundsException
exception is thrown and no compare is performed.
- If
compareOffset+compareLength is
greater than compareBuffer.length , the length
of the compareBuffer array an
ArrayIndexOutOfBoundsException exception
is thrown and no compare is performed.
byte[] buffer = getAPDUBuffer();
short Lc = (short)(buffer[OFFSET_LC] & 0xFF);
short TLVOffset = getLastTLVOffset(buffer, Lc);
if (TLVOffset >= Lc) {
ToolkitException.throwIt(ToolkitException.UNAVAILABLE_ELEMENT);
}
short TLVLength = (short)(buffer[(short)(TLVOffset + 1)] & 0xFF);
if (valueOffset > TLVLength || valueOffset < 0) {
ToolkitException.throwIt(ToolkitException.OUT_OF_TLV_BOUNDARIES);
}
return Util.arrayCompare(buffer,
(short)(currentTLVOffset + 2 + valueOffset),
compareBuffer, compareOffset, compareLength);
| public short | copy(byte[] dstBuffer, short dstOffset, short dstLength)Copies the simple TLV list contained in the handler to the
destination byte array.
Notes:
- If
dstOffset or
dstLength parameter is negative
an ArrayIndexOutOfBoundsException
exception is thrown and no copy is performed.
- If
dstOffset+dstLength is greater
than dstBuffer.length , the length
of the dstBuffer array an
ArrayIndexOutOfBoundsException
exception is thrown and no copy is performed.
byte[] buffer = getAPDUBuffer();
short TLVLength =
(short)(buffer[(short)(currentTLVOffset + 1)] & 0xFF);
if (TLVLength < dstLength) {
// if length is greater than the TLV length itself, then
// throw exception
ToolkitException.throwIt(ToolkitException.OUT_OF_TLV_BOUNDARIES);
}
// copy the current TLV list
Util.arrayCopy(buffer, (short)(currentTLVOffset+2), dstBuffer,
dstOffset, dstLength);
return (short)(dstOffset + dstLength);
| public short | copyValue(short valueOffset, byte[] dstBuffer, short dstOffset, short dstLength)Copies a part of the last TLV element which has been found, into a
destination buffer.
Notes:
- If
dstOffset or
dstLength parameter is negative an
ArrayIndexOutOfBoundsException
exception is thrown and no copy is performed.
- If
dstOffset+dstLength is
greater than dstBuffer.length , the length
of the dstBuffer array an
ArrayIndexOutOfBoundsException exception
is thrown and no copy is performed.
byte[] buffer = getAPDUBuffer();
short Lc = (short)(buffer[OFFSET_LC] & 0xFF);
short TLVOffset = getLastTLVOffset(buffer, Lc);
if (TLVOffset >= Lc) {
ToolkitException.throwIt(ToolkitException.UNAVAILABLE_ELEMENT);
}
short TLVLength = (short)(buffer[(short)(TLVOffset + 1)] & 0xFF);
if (valueOffset > TLVLength || valueOffset < 0) {
ToolkitException.throwIt(ToolkitException.OUT_OF_TLV_BOUNDARIES);
}
Util.arrayCopy(buffer,
(short)(currentTLVOffset + 2 + valueOffset),
dstBuffer, dstOffset, dstLength);
return buffer[(short)(TLVOffset + 2 + valueOffset)];
| public byte | findAndCompareValue(byte tag, byte[] compareBuffer, short compareOffset)Looks for the first occurrence of a TLV element
from beginning of a TLV
list and compare its value with a buffer.
If no TLV element is found, the
UNAVAILABLE_ELEMENT exception is thrown.
If the method is successful then the corresponding TLV
becomes current, else no TLV is selected.
This search method is Comprehension Required flag independent.
Notes:
- If
compareOffset parameter is
negative or compareOffset
is greater than compareBuffer.length ,
the length of the compareBuffer
array an ArrayIndexOutOfBoundsException
exception is thrown and no find is performed.
byte[] buffer = getAPDUBuffer();
short Lc = (short)(buffer[OFFSET_LC] & 0xFF);
short TLVOffset = getTLVOffset(buffer, tag, Lc, (byte)1);
if (TLVOffset >= Lc) {
// TLV not found
ToolkitException.throwIt(ToolkitException.UNAVAILABLE_ELEMENT);
}
// this is the current TLV
currentTLVOffset = TLVOffset;
short length = buffer[(short)(TLVOffset+1)];
return Util.arrayCompare(buffer, (short)(TLVOffset+2), compareBuffer,
compareOffset, length);
| public byte | findAndCompareValue(byte tag, byte occurrence, short valueOffset, byte[] compareBuffer, short compareOffset, short compareLength)Looks for the indicated occurrence of a TLV element from the
beginning of a TLV list and compare its value with a buffer.
If no TLV element is found, the UNAVAILABLE_ELEMENT
exception is thrown.
If the method is successful then the corresponding TLV becomes
current, else no TLV is selected.
This search method is Comprehension Required flag independent.
Notes:
- If
compareOffset or
compareLength parameter is
negative an ArrayIndexOutOfBoundsException
exception is thrown and no find and compare is performed.
- If
compareOffset+compareLength is
greater than compareBuffer.length , the length
of the compareBuffer array an
ArrayIndexOutOfBoundsException exception
is thrown and no find and compare is performed.
byte[] buffer = getAPDUBuffer();
short Lc = (short)(buffer[OFFSET_LC] & 0xFF);
short TLVOffset = getTLVOffset(buffer, tag, Lc, occurrence);
if (TLVOffset >= Lc) {
// TLV not found
ToolkitException.throwIt(ToolkitException.UNAVAILABLE_ELEMENT);
}
// this is the current TLV
currentTLVOffset = TLVOffset;
short length = buffer[(short)(TLVOffset+1)];
if ((valueOffset < 0) || (short)
(valueOffset + compareLength) > length) {
ToolkitException.throwIt(ToolkitException.OUT_OF_TLV_BOUNDARIES);
}
return Util.arrayCompare(buffer, (short)(TLVOffset+2+valueOffset),
compareBuffer, compareOffset, compareLength);
| public short | findAndCopyValue(byte tag, byte[] dstBuffer, short dstOffset)Looks for the first occurrence of a TLV element from the beginning
of a TLV
list and copy its value into a destination buffer.
If no TLV element is found, the UNAVAILABLE_ELEMENT
exception is thrown.
If the method is successful then the corresponding TLV becomes current,
else no TLV is selected.
This search method is Comprehension Required flag independent.
Notes:
- If
dstOffset parameter is negative or
dstOffset
is greater than dstBuffer.length , the
length of the dstBuffer
array an ArrayIndexOutOfBoundsException
exception is thrown and no find is performed.
// this method could potentialy use the other
// findAndCopyValue() method. The only problem is the length
// parameter required by that method
byte[] buffer = getAPDUBuffer();
short Lc = (short)(buffer[OFFSET_LC] & 0xFF);
short TLVOffset = getTLVOffset(buffer, tag, Lc, (short)1);
if (TLVOffset >= Lc) {
// TLV not found
ToolkitException.throwIt(ToolkitException.UNAVAILABLE_ELEMENT);
}
currentTLVOffset = TLVOffset;
short length = buffer[(short)(TLVOffset+1)];
Util.arrayCopy(buffer, (short)(TLVOffset+2), dstBuffer,
dstOffset, length);
return (short)(dstOffset + length);
| public short | findAndCopyValue(byte tag, byte occurrence, short valueOffset, byte[] dstBuffer, short dstOffset, short dstLength)Looks for the indicated occurrence of a TLV element from the
beginning of a TLV
list and copy its value into a destination buffer.
If no TLV element is found, the UNAVAILABLE_ELEMENT
exception is thrown.
If the method is successful then the corresponding TLV becomes current,
else no TLV is selected.
This search method is Comprehension Required flag independent.
Notes:
- If
dstOffset or
dstLength parameter is negative
an ArrayIndexOutOfBoundsException
exception is thrown and no copy is performed.
- If
dstOffset+dstLength is greater
than dstBuffer.length , the length
of the dstBuffer array an
ArrayIndexOutOfBoundsException exception
is thrown and no copy is performed.
byte[] buffer = getAPDUBuffer();
short Lc = (short)(buffer[OFFSET_LC] & 0xFF);
short TLVOffset = getTLVOffset(buffer, tag, Lc, occurrence);
if (TLVOffset >= Lc) {
// TLV not found
ToolkitException.throwIt(ToolkitException.UNAVAILABLE_ELEMENT);
}
// this is the current TLV
currentTLVOffset = TLVOffset;
short length = buffer[(short)(TLVOffset+1)];
if ((valueOffset < 0) || (short)(valueOffset + dstLength) > length) {
ToolkitException.throwIt(ToolkitException.OUT_OF_TLV_BOUNDARIES);
}
Util.arrayCopy(buffer, (short)(TLVOffset+2+valueOffset),
dstBuffer, dstOffset, dstLength);
return (short)(dstOffset + length);
| public byte | findTLV(byte tag, byte occurrence)Looks for the indicated occurrence of a TLV element from the beginning of
the TLV list (handler buffer). If the method is successful then the
corresponding TLV becomes current, else no TLV is selected.
This search method is Comprehension Required flag independent.
byte count = 0; // count of occurances
byte[] buffer = getAPDUBuffer();
short Lc = (short)(buffer[OFFSET_LC] & 0xFF);
short TLVOffset = getTLVOffset(buffer, tag, Lc, occurrence);
if (TLVOffset >= Lc)
return ToolkitConstants.TLV_NOT_FOUND; // not found
currentTLVOffset = TLVOffset;
if ((byte)(buffer[TLVOffset] & ToolkitConstants.TAG_SET_CR) ==
ToolkitConstants.TAG_SET_CR)
return ToolkitConstants.TLV_FOUND_CR_SET;
return ToolkitConstants.TLV_FOUND_CR_NOT_SET;
| public static byte[] | getAPDUBuffer(byte[] buffer)Copies the APDUBuffer content into provided buffer.
short len = SATAccessor.getAPDUBufferLength();
for (short i = 0; i < len; i++) {
buffer[i] = SATAccessor.getAPDUBufferByte(i);
}
return buffer;
| public static byte[] | getAPDUBuffer()Copies the APDUBuffer content into current buffer.
return getAPDUBuffer(currentTI.getAPDUBuffer());
| protected short | getLastTLVOffset(byte[] buffer, short Lc)Helper method for getValue... and
copyValue... .
short offset = firstTLVOffset;
short lastTLVOffset;
do {
lastTLVOffset = offset;
// advance to next TLV
offset++;
short length = buffer[offset];
offset = (short)(offset + length + 1);
} while (offset < Lc);
return lastTLVOffset;
| public short | getLength()Returns the length of the TLV list.
byte[] buffer = getAPDUBuffer();
short length = (short)(buffer[(short)(currentTLVOffset + 1)] & 0xFF);
return length;
| protected short | getTLVOffset(byte[] buffer, byte tag, short Lc, short occurrence)Helper method for findAndCompareValue .
byte count = 0; // count of occurances
short offset = firstTLVOffset;
tag = (byte)(tag & 0x7F);
while (offset < Lc) {
if ((byte)(buffer[offset] & 0x7F) == tag) {
count++;
if (count != occurrence) {
continue;
}
return offset;
} else {
// advance to next TLV
offset++;
short length = buffer[offset];
offset = (short)(offset + length + 1);
}
}
return offset; // not found
| public byte | getValueByte(short valueOffset)Gets a byte from the last TLV element which has been found in the
handler.
byte[] buffer = getAPDUBuffer();
short Lc = (short)(buffer[OFFSET_LC] & 0xFF);
short TLVOffset = getLastTLVOffset(buffer, Lc);
if (TLVOffset >= Lc) {
ToolkitException.throwIt(ToolkitException.UNAVAILABLE_ELEMENT);
}
short TLVLength = (short)(buffer[(short)(TLVOffset + 1)] & 0xFF);
if (valueOffset > TLVLength) {
ToolkitException.throwIt(ToolkitException.OUT_OF_TLV_BOUNDARIES);
}
// return the byte at offset
return buffer[(short)(TLVOffset + 2 + valueOffset)];
| public short | getValueLength()Gets the binary length of the value field for the last TLV element
which has been found in the handler.
byte[] buffer = getAPDUBuffer();
short Lc = (short)(buffer[OFFSET_LC] & 0xFF);
short TLVOffset = getLastTLVOffset(buffer, Lc);
if (TLVOffset >= Lc) {
ToolkitException.throwIt(ToolkitException.UNAVAILABLE_ELEMENT);
}
return (short)(buffer[(short)
(TLVOffset + 1)] & 0xFF); // return the length
| public static void | setAPDUBuffer(byte[] buffer, short length)Copies content of provided buffer into the APDUBuffer.
for (short i = 0; i < length; i++) {
SATAccessor.setAPDUBufferByte(i, buffer[i]);
}
| public static void | setAPDUBuffer(short length)Copies content of current buffer into the APDUBuffer.
setAPDUBuffer(currentTI.getAPDUBuffer(), length);
| public static void | setOutBufferData(short length)Sets the data in the out buffer.
setAPDUBuffer(length);
SATAccessor.setOutBufferData(length);
|
|