| Code with Finding: |
class APDUSenderPanel {
public APDUSenderPanel(CardService service) {
super(new GridLayout(3, 1));
this.service = service;
this.wrapper = null;
JPanel beginPanel = new JPanel(new FlowLayout());
beginPanel.setBorder(BorderFactory.createTitledBorder(PANEL_BORDER,
"Begin APDU"));
bApduField = new CommandAPDUField();
beginPanel.add(bApduField);
JPanel endPanel = new JPanel(new FlowLayout());
endPanel.setBorder(BorderFactory.createTitledBorder(PANEL_BORDER,
"End APDU"));
eApduField = new CommandAPDUField();
copyButton = new JButton("Copy");
copyButton.addActionListener(this);
endPanel.add(copyButton);
endPanel.add(eApduField);
JPanel controlPanel = new JPanel(new FlowLayout());
smCheckBox = new JCheckBox();
sendButton = new JButton("Send");
sendButton.addActionListener(this);
controlPanel.add(new JLabel("Wrap: "));
controlPanel.add(smCheckBox);
controlPanel.add(new JLabel(" Send APDUs: "));
controlPanel.add(sendButton);
add(beginPanel);
add(endPanel);
add(controlPanel);
}
}
class APDUSenderPanel {
private void sendAll(byte[] a, byte[] b, byte[] c, int offset,
boolean isWrapped) {
int n = a.length - offset;
Apdu apdu;
if (n > 0) {
int min = Math.min(a[offset] & 0x000000FF, b[offset] & 0x000000FF);
int max = Math.max(a[offset] & 0x000000FF, b[offset] & 0x000000FF);
for (int i = min; i <= max; i++) {
c[offset] = (byte) i;
sendAll(a, b, c, offset + 1, isWrapped);
}
} else {
apdu = new Apdu(c);
if (isWrapped) {
apdu.wrapWith(wrapper);
}
byte[] rapdu = service.sendAPDU(apdu);
if (isWrapped) {
rapdu = wrapper.unwrap(rapdu, rapdu.length);
System.out.println("PLAIN TEXT RAPDU: "
+ Hex.bytesToHexString(rapdu));
}
}
}
}
|