mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-11-22 23:22:05 +01:00
Fix writing out of session key - again
This commit is contained in:
parent
5cde383b1a
commit
9ea9cd22b8
1 changed files with 13 additions and 14 deletions
|
@ -12,17 +12,14 @@ import sop.Verification;
|
||||||
import sop.cli.picocli.SopCLI;
|
import sop.cli.picocli.SopCLI;
|
||||||
import sop.exception.SOPGPException;
|
import sop.exception.SOPGPException;
|
||||||
import sop.operation.Decrypt;
|
import sop.operation.Decrypt;
|
||||||
import sop.util.HexUtil;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
@CommandLine.Command(name = "decrypt",
|
@CommandLine.Command(name = "decrypt",
|
||||||
resourceBundle = "msg_decrypt",
|
resourceBundle = "msg_decrypt",
|
||||||
|
@ -130,18 +127,20 @@ public class DecryptCmd extends AbstractSopCmd {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeSessionKeyOut(DecryptionResult result) throws IOException {
|
private void writeSessionKeyOut(DecryptionResult result) throws IOException {
|
||||||
if (sessionKeyOut != null) {
|
if (sessionKeyOut == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
try (OutputStream outputStream = getOutput(sessionKeyOut)) {
|
try (OutputStream outputStream = getOutput(sessionKeyOut)) {
|
||||||
if (!result.getSessionKey().isPresent()) {
|
if (!result.getSessionKey().isPresent()) {
|
||||||
String errorMsg = getMsg("sop.error.runtime.no_session_key_extracted");
|
String errorMsg = getMsg("sop.error.runtime.no_session_key_extracted");
|
||||||
throw new SOPGPException.UnsupportedOption(String.format(errorMsg, OPT_SESSION_KEY_OUT));
|
throw new SOPGPException.UnsupportedOption(String.format(errorMsg, OPT_SESSION_KEY_OUT));
|
||||||
} else {
|
}
|
||||||
SessionKey sessionKey = result.getSessionKey().get();
|
SessionKey sessionKey = result.getSessionKey().get();
|
||||||
outputStream.write(sessionKey.getAlgorithm());
|
PrintWriter writer = new PrintWriter(outputStream);
|
||||||
// noinspection CharsetObjectCanBeUsed
|
// CHECKSTYLE:OFF
|
||||||
outputStream.write(sessionKey.toString().getBytes(Charset.forName("UTF8")));
|
writer.println(sessionKey.toString());
|
||||||
}
|
// CHECKSTYLE:ON
|
||||||
}
|
writer.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue