Refactor format of the MyApplet.java
file
This commit is contained in:
parent
6070b53cdf
commit
88dc8bb094
1 changed files with 52 additions and 51 deletions
|
@ -29,13 +29,13 @@ public class MyApplet extends Applet {
|
|||
* @param bLength the length in bytes of the parameter data in bArray
|
||||
*/
|
||||
public static void install(byte[] buffer, short offset, byte length) {
|
||||
byte aidLength = buffer[offset];
|
||||
byte aidLength = buffer[offset];
|
||||
|
||||
short controlInfoOffset = (short)(offset + 1 + aidLength);
|
||||
byte controlInfoLength = buffer[controlInfoOffset];
|
||||
short controlInfoOffset = (short)(offset + 1 + aidLength);
|
||||
byte controlInfoLength = buffer[controlInfoOffset];
|
||||
|
||||
short dataOffset = (short)(controlInfoOffset + 1 + controlInfoLength);
|
||||
byte dataLength = buffer[dataOffset];
|
||||
short dataOffset = (short)(controlInfoOffset + 1 + controlInfoLength);
|
||||
byte dataLength = buffer[dataOffset];
|
||||
|
||||
new MyApplet(buffer, (short)(dataOffset + 1), dataLength);
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ public class MyApplet extends Applet {
|
|||
|
||||
public boolean select() {
|
||||
if (pin.getTriesRemaining() == 0) {
|
||||
ISOException.throwIt(SW_VERIFICATION_FAILED);
|
||||
return false;
|
||||
} else {
|
||||
return super.select();
|
||||
|
@ -62,8 +63,8 @@ public class MyApplet extends Applet {
|
|||
}
|
||||
|
||||
public void deselect() {
|
||||
super.deselect();
|
||||
pin.reset();
|
||||
super.deselect();
|
||||
pin.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,61 +83,61 @@ public class MyApplet extends Applet {
|
|||
if (buffer[ISO7816.OFFSET_CLA] != (byte)0x80) {
|
||||
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
|
||||
} else {
|
||||
boolean authenticationRequired = false;
|
||||
boolean authenticationRequired = false;
|
||||
byte instruction = buffer[ISO7816.OFFSET_INS];
|
||||
|
||||
switch (instruction) {
|
||||
case 0x04:
|
||||
case 0x02:
|
||||
authenticationRequired = !pin.isValidated();
|
||||
break;
|
||||
case 0x02:
|
||||
case 0x04:
|
||||
authenticationRequired = !pin.isValidated();
|
||||
break;
|
||||
}
|
||||
|
||||
if (authenticationRequired) {
|
||||
ISOException.throwIt(SW_PIN_VERIFICATION_REQUIRED);
|
||||
ISOException.throwIt(SW_PIN_VERIFICATION_REQUIRED);
|
||||
}
|
||||
else {
|
||||
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;
|
||||
length = (short)response.length;
|
||||
} else {
|
||||
response = storage;
|
||||
if (instruction == 0x00) {
|
||||
response = authorName;
|
||||
length = (short)response.length;
|
||||
} else {
|
||||
response = storage;
|
||||
|
||||
if (length > response.length) {
|
||||
ISOException.throwIt((short)(ISO7816.SW_CORRECT_LENGTH_00 | response.length));
|
||||
}
|
||||
}
|
||||
if (length > response.length) {
|
||||
ISOException.throwIt((short)(ISO7816.SW_CORRECT_LENGTH_00 | response.length));
|
||||
}
|
||||
}
|
||||
|
||||
apdu.setOutgoingLength(length);
|
||||
apdu.sendBytesLong(response, (short) 0, length);
|
||||
break;
|
||||
case 0x02:
|
||||
length = apdu.setIncomingAndReceive();
|
||||
storage = new byte[length];
|
||||
|
||||
if (length > 20) {
|
||||
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
|
||||
} else {
|
||||
Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, storage, (short) 0, length);
|
||||
}
|
||||
break;
|
||||
case 0x20:
|
||||
length = apdu.setIncomingAndReceive();
|
||||
|
||||
if (!pin.check(buffer, (short) ISO7816.OFFSET_CDATA, (byte)length)) {
|
||||
ISOException.throwIt(SW_VERIFICATION_FAILED);
|
||||
}
|
||||
apdu.setOutgoingLength(length);
|
||||
apdu.sendBytesLong(response, (short) 0, length);
|
||||
break;
|
||||
default:
|
||||
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
|
||||
break;
|
||||
}
|
||||
case 0x02:
|
||||
length = apdu.setIncomingAndReceive();
|
||||
storage = new byte[length];
|
||||
|
||||
if (length > 20) {
|
||||
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
|
||||
} else {
|
||||
Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, storage, (short) 0, length);
|
||||
}
|
||||
break;
|
||||
case 0x20:
|
||||
length = apdu.setIncomingAndReceive();
|
||||
|
||||
if (!pin.check(buffer, (short) ISO7816.OFFSET_CDATA, (byte)length)) {
|
||||
ISOException.throwIt(SW_VERIFICATION_FAILED);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ISOException.throwIt(ISO7816.SW_NO_ERROR);
|
||||
|
|
Loading…
Reference in a new issue