diff --git a/hwb1/src/hwb1/MyApplet.java b/hwb1/src/hwb1/MyApplet.java index 06696e3..02c5513 100644 --- a/hwb1/src/hwb1/MyApplet.java +++ b/hwb1/src/hwb1/MyApplet.java @@ -51,40 +51,44 @@ public class MyApplet extends Applet { public void process(APDU apdu) { short length; 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) { - case 0x00: - case 0x04: - byte[] response; - length = apdu.setOutgoing(); + if (instruction == 0x00) { + response = AuthorName; + } else { + response = storage; + } - if (instruction == 0x00) { - response = AuthorName; - } else { - response = storage; - } + if (length > response.length) { + length = (short) response.length; + } - if (length > response.length) { - length = (short) response.length; - } + apdu.setOutgoingLength(length); + apdu.sendBytesLong(response, (short) 0, length); + break; + case 0x02: + length = apdu.setIncomingAndReceive(); - apdu.setOutgoingLength(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; - default: - ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); - break; + 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; + } } } }