Here is part of the code.
Code: Select all
switch (buf[ISO7816.OFFSET_P1]){
case (byte) 0x01:
switch (buf[ISO7816.OFFSET_P2]){
case (byte) 0x01:
doSingleDES(apdu, DESKey1);
return;
case (byte) 0x02:
doSingleDES(apdu, DESKey2);
return;
case (byte) 0x03:
doSingleDES(apdu, DESKey3);
return;
case (byte) 0x04:
doSingleDES(apdu, DESKey3);
return;
default:
ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
}return;
case (byte) 0x02:
switch (buf[ISO7816.OFFSET_P2]){
case (byte) 0x01:
doEncrypt(apdu, DESKey1);
return;
case (byte) 0x02:
doEncrypt(apdu, DESKey2);
return;
case (byte) 0x03:
doEncrypt(apdu, DESKey3);
return;
case (byte) 0x04:
doEncrypt(apdu, DESKey4);
return;
default:
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
}return;
default:
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
I want to use P1 to select an algorithm and use P2 to select a key for P1.
Q: I want to simplify this nested switch. How can I do that?
Note that I appreciate any suggestion to make my program more efficient.