Throw an error for incorrect CLAs
This commit is contained in:
parent
22b11b1ee8
commit
995ba68bdf
1 changed files with 33 additions and 29 deletions
|
@ -51,40 +51,44 @@ public class MyApplet extends Applet {
|
||||||
public void process(APDU apdu) {
|
public void process(APDU apdu) {
|
||||||
short length;
|
short length;
|
||||||
byte[] buffer = apdu.getBuffer();
|
byte[] buffer = apdu.getBuffer();
|
||||||
|
|
||||||
|
if (buffer[ISO7816.OFFSET_CLA] != 0x80) {
|
||||||
|
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
|
||||||
|
} else {
|
||||||
|
byte instruction = buffer[ISO7816.OFFSET_INS];
|
||||||
|
|
||||||
byte instruction = buffer[ISO7816.OFFSET_INS];
|
switch (instruction) {
|
||||||
|
case 0x00:
|
||||||
|
case 0x04:
|
||||||
|
byte[] response;
|
||||||
|
length = apdu.setOutgoing();
|
||||||
|
|
||||||
switch (instruction) {
|
if (instruction == 0x00) {
|
||||||
case 0x00:
|
response = AuthorName;
|
||||||
case 0x04:
|
} else {
|
||||||
byte[] response;
|
response = storage;
|
||||||
length = apdu.setOutgoing();
|
}
|
||||||
|
|
||||||
if (instruction == 0x00) {
|
if (length > response.length) {
|
||||||
response = AuthorName;
|
length = (short) response.length;
|
||||||
} else {
|
}
|
||||||
response = storage;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (length > response.length) {
|
apdu.setOutgoingLength(length);
|
||||||
length = (short) response.length;
|
apdu.sendBytesLong(response, (short) 0, length);
|
||||||
}
|
break;
|
||||||
|
case 0x02:
|
||||||
|
length = apdu.setIncomingAndReceive();
|
||||||
|
|
||||||
apdu.setOutgoingLength(length);
|
if (length > 20) {
|
||||||
apdu.sendBytesLong(response, (short) 0, length);
|
// ToDo: Handle too much data.
|
||||||
break;
|
} else {
|
||||||
case 0x02:
|
Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, storage, (short) 0, length);
|
||||||
length = apdu.setIncomingAndReceive();
|
}
|
||||||
|
break;
|
||||||
if (length > 20) {
|
default:
|
||||||
// ToDo: Handle too much data.
|
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
|
||||||
} else {
|
break;
|
||||||
Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, storage, (short) 0, length);
|
}
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue