Fields Summary |
---|
static final byte | x0Constant that is used to avoid '(short) x' notation. |
static final byte | x1Constant that is used to avoid '(short) x' notation. |
static final byte | x2Constant that is used to avoid '(short) x' notation. |
static final byte | x3Constant that is used to avoid '(short) x' notation. |
static final byte | x4Constant that is used to avoid '(short) x' notation. |
static final byte | x5Constant that is used to avoid '(short) x' notation. |
static final byte | x6Constant that is used to avoid '(short) x' notation. |
static final byte | x8Constant that is used to avoid '(short) x' notation. |
static final byte | INS_SELECTINS byte for command APDU. |
static final byte | INS_READINS byte for command APDU. |
DFile | topRoot DF for entire file structure. |
DFile | baseRoot DF for WIM application. All relative paths start from
here. |
File | currentCurrently selected file. |
Methods Summary |
---|
private void | checkDataSize(short expectedSize, APDU apdu)Verifies that APDU contains correct number of data bytes.
if (expectedSize != apdu.setIncomingAndReceive()) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
|
static short | getDERSize(short i)Returns the size of DER object for given value size.
if (i < 128) {
return (short) (i + 2);
}
return (short) (i + 3);
|
File | getFile(byte[] data, short index, short l)Returns file object specified by path in the buffer.
// path must contain even number of bytes
if (l < 2 || l % 2 != 0) {
return null;
}
l = (short) (l / 2);
short id = Util.getShort(data, index);
File x;
if (l == 1) {
x = base;
} else {
if (id == top.id) {
x = top;
} else {
if (id == (short) 0x3fff) {
x = base;
} else {
return null;
}
}
index += 2;
l--;
}
while (l != 0) {
if (! x.isDF()) {
return null;
}
File f = ((DFile) x).getFile(Util.getShort(data, index));
if (f == null || f.parent != x) {
return null;
}
x = f;
index += 2;
l--;
}
return x;
|
void | init()Initialises the WIM data structures.
Parser.init(Data.Files);
top = (DFile) readFile(null);
if (base == null) {
ISOException.throwIt((short) 0x9001);
}
|
public static void | install(byte[] bArray, short bOffset, byte bLength)To create an instance of the Applet subclass, the JCRE will call
this static method first.
new ACLApplet();
|
public void | process(APDU apdu)Main entry point.
byte[] data = apdu.getBuffer();
byte CLA = (byte) (data[ISO7816.OFFSET_CLA] & 0xF0);
byte INS = data[ISO7816.OFFSET_INS];
if (CLA == 0 &&
INS == (byte)(0xA4) &&
data[ISO7816.OFFSET_P1] == 4) {
return;
}
if (CLA != (byte) 0x00) {
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
}
switch (INS) {
case INS_SELECT:
selectFile(apdu);
return;
case INS_READ:
read(apdu);
return;
}
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
|
static short | putLength(byte[] data, short offset, short length)Places encoded length of DER object into the buffer.
if (length >= 128) {
data[offset++] = (byte) 0x81;
}
data[offset++] = (byte) length;
return offset;
|
void | read(APDU apdu)Handles READ BINARY APDU.
if (current.isDF()) {
ISOException.throwIt(ISO7816.SW_COMMAND_NOT_ALLOWED);
}
EFile f = (EFile) current;
byte[] data = apdu.getBuffer();
short offset = Util.getShort(data, x2);
if (offset < 0 || offset > f.length) {
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
}
short len = (short) (data[x4] & 0xff);
if ((short)(offset + len) > f.length) {
//ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
len = (short)(f.length - offset);
if (len < 0) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
}
apdu.setOutgoing();
apdu.setOutgoingLength(len);
apdu.sendBytesLong(f.data, (short) (f.offset + offset), len);
|
File | readFile(DFile parent)Creates new file object.
short id = Parser.getShort();
short type = Parser.getByte();
short length = Parser.getShort();
if ((type & File.DIR) == 0) {
EFile f;
if ((type & File.EMPTY) == 0) {
f = new EFile(parent, id, type, Parser.offset, length,
Data.Files);
Parser.skip(length);
} else {
type &= ~File.EMPTY;
byte[] data = new byte[length];
short dlen = Parser.getShort();
Util.arrayCopyNonAtomic(Data.Files, Parser.offset, data,
(short) 0, dlen);
f = new EFile(parent, id, type, (short) 0, length, data);
Parser.skip(dlen);
}
return f;
}
DFile f = new DFile(parent, id, type);
File[] files = new File[length];
for (short i = 0; i < length; i++) {
files[i] = readFile(f);
}
f.files = files;
if (type == File.WIM) {
base = f;
}
return f;
|
public boolean | select()Called by the JCRE to inform this applet that it has been
selected. When invoked first time initialises the file system.
if (top == null) {
init();
}
current = base;
return true;
|
File | select(short id)Selects the file specified by file identifier.
DFile f;
if (current.isDF()) {
f = (DFile) current;
} else {
f = current.parent;
}
File x = f.getFile(id);
if (x != null) {
return x;
}
f = f.parent;
if (f == null) {
return null;
}
return f.getFile(id);
|
void | selectFile(APDU apdu)Handles SELECT FILE APDU.
byte[] data = apdu.getBuffer();
/* if (Util.getShort(data, x2) != 0) {
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
}
*/
checkDataSize(x2, apdu);
File f = select(Util.getShort(data, x5));
if (f == null) {
ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);
}
current = f;
if (current.isDF()) {
Util.setShort(data, x0, (short) 0x6f00);
apdu.setOutgoingAndSend(x0, x2);
} else {
Util.setShort(data, x0, (short) 0x6f04);
Util.setShort(data, x2, (short) 0x8002);
Util.setShort(data, x4, ((EFile) current).length);
apdu.setOutgoingAndSend(x0, x6);
}
|