Throw an error for unsupported instructions
This commit is contained in:
parent
39948e42f2
commit
22b11b1ee8
|
@ -22,16 +22,13 @@ import static hwb1.MyAppletStrings.*;
|
|||
name = "MyAppletStrings")
|
||||
public class MyApplet extends Applet {
|
||||
private byte[] storage = null;
|
||||
|
||||
|
||||
/**
|
||||
* Installs this applet.
|
||||
*
|
||||
* @param bArray
|
||||
* the array containing installation parameters
|
||||
* @param bOffset
|
||||
* the starting offset in bArray
|
||||
* @param bLength
|
||||
* the length in bytes of the parameter data in bArray
|
||||
* @param bArray the array containing installation parameters
|
||||
* @param bOffset 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) {
|
||||
new MyApplet();
|
||||
|
@ -48,8 +45,7 @@ public class MyApplet extends Applet {
|
|||
* Processes an incoming APDU.
|
||||
*
|
||||
* @see APDU
|
||||
* @param apdu
|
||||
* the incoming APDU
|
||||
* @param apdu the incoming APDU
|
||||
*/
|
||||
@Override
|
||||
public void process(APDU apdu) {
|
||||
|
@ -61,33 +57,34 @@ public class MyApplet extends Applet {
|
|||
switch (instruction) {
|
||||
case 0x00:
|
||||
case 0x04:
|
||||
byte[] response;
|
||||
byte[] response;
|
||||
length = apdu.setOutgoing();
|
||||
|
||||
|
||||
if (instruction == 0x00) {
|
||||
response = AuthorName;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
response = storage;
|
||||
}
|
||||
|
||||
if (length > response.length) {
|
||||
length = (short)response.length;
|
||||
length = (short) response.length;
|
||||
}
|
||||
|
||||
apdu.setOutgoingLength(length);
|
||||
apdu.sendBytesLong(response, (short)0, length);
|
||||
apdu.sendBytesLong(response, (short) 0, length);
|
||||
break;
|
||||
case 0x02:
|
||||
length = apdu.setIncomingAndReceive();
|
||||
|
||||
if (length > 20) {
|
||||
// ToDo: Handle too much data.
|
||||
}
|
||||
else {
|
||||
Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, storage, (short)0, length);
|
||||
}
|
||||
break;
|
||||
length = apdu.setIncomingAndReceive();
|
||||
|
||||
if (length > 20) {
|
||||
// ToDo: Handle too much data.
|
||||
} else {
|
||||
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