package mixconfig.tools.dataretention.smartcard.commands; import javax.smartcardio.CommandAPDU; import mixconfig.tools.dataretention.smartcard.ApduConstants; import mixconfig.tools.dataretention.smartcard.Helpers; public class AbstractCommand { /** * Code of the ANONCardApplet (CLA) */ protected byte apduClass = ApduConstants.CLA_ANON; /** * Instruction Code (INS) */ protected byte instruction = 0; /** * P1 */ protected byte p1 = 0x00; /** * P2 */ protected byte p2 = 0x00; /** * The data (LC = arguments.length) */ protected byte[] arguments = {}; /** * The maximal length of the expected return value (LE) */ protected byte expectedReturnDataLength = 0; /** * The unformatted answer of the ANONCardApplet */ protected byte[] rawResponse; public CommandAPDU buildCommandApdu() { CommandAPDU commandApdu = new CommandAPDU(apduClass, instruction, p1, p2, arguments, expectedReturnDataLength); return commandApdu; } public void setResponse(byte[] responseData, int sw1, int sw2) throws ErrorCodeException { // SW1/SW2 0..255 if (sw1 == 0x90 && sw2 == 0x00 || sw1 == 0x61) { rawResponse = responseData; } else { throw new ErrorCodeException("Error" + Helpers.bytesToHexDigits(responseData) + "Status: " + Helpers.bytesToHexDigits(new byte[] { (byte) sw1, (byte) sw2 })); } } }