feat: reorg card cli util

This commit is contained in:
2023-05-20 23:48:52 +08:00
parent 4c97436470
commit 2314062147

View File

@@ -84,13 +84,7 @@ public class CardCliUtil {
final String outputs;
final String errorOutputs;
try {
final List<String> commandList = new ArrayList<>(pb.command());
for (int i = 0; i < commandList.size(); i++) {
final String c = commandList.get(i);
if (StringUtil.equals("--pin", c) && ((i + 1) < commandList.size())) {
commandList.set(i + 1, "******");
}
}
final List<String> commandList = getDesensitizedCommands(pb);
log.info("Run command: " + StringUtil.join(commandList, " "));
final Process p = pb.start();
final byte[] outputsBytes = IOUtil.readToBytes(p.getInputStream());
@@ -104,8 +98,19 @@ public class CardCliUtil {
if (StringUtil.isNotEmpty(StringUtil.trim(errorOutputs))) {
log.error("Error outputs: " + errorOutputs);
}
throw new RuntimeException("Outputs is empty!");
throw new RuntimeException("Outputs is empty! Please insert or reinsert your card.");
}
return outputs;
}
private static List<String> getDesensitizedCommands(ProcessBuilder pb) {
final List<String> commandList = new ArrayList<>(pb.command());
for (int i = 0; i < commandList.size(); i++) {
final String c = commandList.get(i);
if (StringUtil.equals("--pin", c) && ((i + 1) < commandList.size())) {
commandList.set(i + 1, "******");
}
}
return commandList;
}
}