Throw an error for unsupported instructions

This commit is contained in:
Manuel Thalmann 2023-10-13 01:25:46 +02:00
parent 39948e42f2
commit 22b11b1ee8

View file

@ -26,12 +26,9 @@ public class MyApplet extends Applet {
/** /**
* Installs this applet. * Installs this applet.
* *
* @param bArray * @param bArray the array containing installation parameters
* the array containing installation parameters * @param bOffset the starting offset in bArray
* @param bOffset * @param bLength the length in bytes of the parameter data in bArray
* the starting offset in bArray
* @param bLength
* the length in bytes of the parameter data in bArray
*/ */
public static void install(byte[] bArray, short bOffset, byte bLength) { public static void install(byte[] bArray, short bOffset, byte bLength) {
new MyApplet(); new MyApplet();
@ -48,8 +45,7 @@ public class MyApplet extends Applet {
* Processes an incoming APDU. * Processes an incoming APDU.
* *
* @see APDU * @see APDU
* @param apdu * @param apdu the incoming APDU
* the incoming APDU
*/ */
@Override @Override
public void process(APDU apdu) { public void process(APDU apdu) {
@ -66,27 +62,28 @@ public class MyApplet extends Applet {
if (instruction == 0x00) { if (instruction == 0x00) {
response = AuthorName; response = AuthorName;
} } else {
else {
response = storage; response = storage;
} }
if (length > response.length) { if (length > response.length) {
length = (short)response.length; length = (short) response.length;
} }
apdu.setOutgoingLength(length); apdu.setOutgoingLength(length);
apdu.sendBytesLong(response, (short)0, length); apdu.sendBytesLong(response, (short) 0, length);
break; break;
case 0x02: case 0x02:
length = apdu.setIncomingAndReceive(); length = apdu.setIncomingAndReceive();
if (length > 20) { if (length > 20) {
// ToDo: Handle too much data. // ToDo: Handle too much data.
} else {
Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, storage, (short) 0, length);
} }
else { break;
Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, storage, (short)0, length); default:
} ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
break; break;
} }
} }