mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-10-31 22:16:00 +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) {
|
||||||
try (OutputStream outputStream = getOutput(sessionKeyOut)) {
|
return;
|
||||||
if (!result.getSessionKey().isPresent()) {
|
}
|
||||||
String errorMsg = getMsg("sop.error.runtime.no_session_key_extracted");
|
try (OutputStream outputStream = getOutput(sessionKeyOut)) {
|
||||||
throw new SOPGPException.UnsupportedOption(String.format(errorMsg, OPT_SESSION_KEY_OUT));
|
if (!result.getSessionKey().isPresent()) {
|
||||||
} else {
|
String errorMsg = getMsg("sop.error.runtime.no_session_key_extracted");
|
||||||
SessionKey sessionKey = result.getSessionKey().get();
|
throw new SOPGPException.UnsupportedOption(String.format(errorMsg, OPT_SESSION_KEY_OUT));
|
||||||
outputStream.write(sessionKey.getAlgorithm());
|
|
||||||
// noinspection CharsetObjectCanBeUsed
|
|
||||||
outputStream.write(sessionKey.toString().getBytes(Charset.forName("UTF8")));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
SessionKey sessionKey = result.getSessionKey().get();
|
||||||
|
PrintWriter writer = new PrintWriter(outputStream);
|
||||||
|
// CHECKSTYLE:OFF
|
||||||
|
writer.println(sessionKey.toString());
|
||||||
|
// CHECKSTYLE:ON
|
||||||
|
writer.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue