/** * Shows a dialog message to the user and returns the pressed button. * * @param message text to display to the user * @return {@link Button} that was pressed by the user * @throws IOException when communication fails */ public Button dialog(String message) throws IOException, UserCancelExcption { Map<String, Object> m = JSONProtocol.cmd("dialog"); m.put("text", message); pipe.send(m); Map<String, Object> r = pipe.recv(); if (!JSONProtocol.check(m, r) || !r.containsKey("button")) { throw new IOException("Unknown button pressed"); } return Button.valueOf(((String) r.get("button")).toUpperCase()); }
/** * Shows the response of the APDU to the user. * * <p>Normally this requires the verification of a PIN code beforehand. * * @param message text to display to the user * @param apdu APDU to send to the terminal * @return {@link Button} that was pressed by the user * @throws IOException when communication fails */ public Button decrypt(String message, byte[] apdu) throws IOException, UserCancelExcption { Map<String, Object> m = JSONProtocol.cmd("decrypt"); m.put("text", message); m.put("bytes", HexUtils.bin2hex(apdu)); pipe.send(m); Map<String, Object> r = pipe.recv(); if (JSONProtocol.check(m, r)) { return Button.valueOf(((String) r.get("button")).toUpperCase()); } else { throw new IOException("Unknown button pressed"); } }