AbstractIso7816CommandBuilder extends AbstractApduCommandBuilder { protected ApduRequest setApduRequest( byte cla, SeCommand command, byte p1, byte p2, byte[] dataIn, Byte le) { boolean case4; if (dataIn != null && le != null && le != 0) { throw new IllegalArgumentException( "Le must be equal to 0 when not null and ingoing data are present."); } byte[] apdu = allocateBuffer(dataIn, le); apdu[0] = cla; apdu[1] = command.getInstructionByte(); apdu[2] = p1; apdu[3] = p2; if (dataIn != null) { apdu[4] = (byte) dataIn.length; System.arraycopy(dataIn, 0, apdu, 5, dataIn.length); if (le != null) { case4 = true; apdu[apdu.length - 1] = le; } else { case4 = false; } } else { if (le != null) { apdu[4] = le; } else { apdu[4] = (byte) 0x00; } case4 = false; } return new ApduRequest(command.getName(), apdu, case4); } AbstractIso7816CommandBuilder(SeCommand commandReference, ApduRequest request);   }
@Test(expected = IllegalArgumentException.class) public void testSetApduRequestDatainLeNon0() { Iso7816CommandBuilder iso7816CommandBuilder = new Iso7816CommandBuilder(CommandRef.COMMAND_1, null); ApduRequest apduRequest = iso7816CommandBuilder.setApduRequest( (byte) 0xCC, CommandRef.COMMAND_1, (byte) 0xB1, (byte) 0xB2, ByteArrayUtil.fromHex("11223344"), (byte) 1); }
@Test public void testSetApduRequestCase1() { Iso7816CommandBuilder iso7816CommandBuilder = new Iso7816CommandBuilder(CommandRef.COMMAND_1, null); ApduRequest apduRequest = iso7816CommandBuilder.setApduRequest( (byte) 0xCC, CommandRef.COMMAND_1, (byte) 0xB1, (byte) 0xB2, null, null); logger.info("APDU case1: {}", ByteArrayUtil.toHex(apduRequest.getBytes())); Assert.assertArrayEquals(ByteArrayUtil.fromHex("CC 11 B1 B2 00"), apduRequest.getBytes()); Assert.assertFalse(apduRequest.isCase4()); }
@Test public void testSetApduRequestCase2() { Iso7816CommandBuilder iso7816CommandBuilder = new Iso7816CommandBuilder(CommandRef.COMMAND_1, null); ApduRequest apduRequest = iso7816CommandBuilder.setApduRequest( (byte) 0xCC, CommandRef.COMMAND_1, (byte) 0xB1, (byte) 0xB2, null, (byte) 6); logger.info("APDU case2: {}", ByteArrayUtil.toHex(apduRequest.getBytes())); Assert.assertArrayEquals(ByteArrayUtil.fromHex("CC 11 B1 B2 06"), apduRequest.getBytes()); Assert.assertFalse(apduRequest.isCase4()); }
@Test public void testSetApduRequestCase3() { Iso7816CommandBuilder iso7816CommandBuilder = new Iso7816CommandBuilder(CommandRef.COMMAND_1, null); ApduRequest apduRequest = iso7816CommandBuilder.setApduRequest( (byte) 0xCC, CommandRef.COMMAND_1, (byte) 0xB1, (byte) 0xB2, ByteArrayUtil.fromHex("11223344"), null); logger.info("APDU case3: {}", ByteArrayUtil.toHex(apduRequest.getBytes())); Assert.assertArrayEquals( ByteArrayUtil.fromHex("CC 11 B1 B2 04 11223344"), apduRequest.getBytes()); Assert.assertFalse(apduRequest.isCase4()); }
@Test public void testSetApduRequestCase4() { Iso7816CommandBuilder iso7816CommandBuilder = new Iso7816CommandBuilder(CommandRef.COMMAND_1, null); ApduRequest apduRequest = iso7816CommandBuilder.setApduRequest( (byte) 0xCC, CommandRef.COMMAND_1, (byte) 0xB1, (byte) 0xB2, ByteArrayUtil.fromHex("11223344"), (byte) 0); logger.info("APDU case4: {}", ByteArrayUtil.toHex(apduRequest.getBytes())); Assert.assertArrayEquals( ByteArrayUtil.fromHex("CC 11 B1 B2 04 11223344 00"), apduRequest.getBytes()); Assert.assertTrue(apduRequest.isCase4()); }
@Test public void testSetApduRequest() { Iso7816CommandBuilder iso7816CommandBuilder = new Iso7816CommandBuilder(CommandRef.COMMAND_1, null); ApduRequest apduRequest = iso7816CommandBuilder.setApduRequest( (byte) 0xCC, CommandRef.COMMAND_1, (byte) 0xB1, (byte) 0xB2, ByteArrayUtil.fromHex("11223344"), (byte) 0); Assert.assertArrayEquals(ByteArrayUtil.fromHex("CC11B1B2041122334400"), apduRequest.getBytes()); }