mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2025-09-09 10:19:47 +02:00
Merge remote-tracking branch 'origin/sop08'
This commit is contained in:
commit
72ca392386
8 changed files with 164 additions and 38 deletions
|
@ -5,6 +5,7 @@
|
|||
package sop.cli.picocli.commands
|
||||
|
||||
import java.io.IOException
|
||||
import java.io.PrintWriter
|
||||
import picocli.CommandLine.*
|
||||
import sop.cli.picocli.SopCLI
|
||||
import sop.enums.EncryptAs
|
||||
|
@ -32,9 +33,14 @@ class EncryptCmd : AbstractSopCmd() {
|
|||
|
||||
@Parameters(index = "0..*", paramLabel = "CERTS") var certs: List<String> = listOf()
|
||||
|
||||
@Option(names = ["--session-key-out"], paramLabel = "SESSIONKEY")
|
||||
var sessionKeyOut: String? = null
|
||||
|
||||
override fun run() {
|
||||
val encrypt = throwIfUnsupportedSubcommand(SopCLI.getSop().encrypt(), "encrypt")
|
||||
|
||||
throwIfOutputExists(sessionKeyOut)
|
||||
|
||||
profile?.let {
|
||||
try {
|
||||
encrypt.profile(it)
|
||||
|
@ -130,7 +136,22 @@ class EncryptCmd : AbstractSopCmd() {
|
|||
|
||||
try {
|
||||
val ready = encrypt.plaintext(System.`in`)
|
||||
ready.writeTo(System.out)
|
||||
val result = ready.writeTo(System.out)
|
||||
|
||||
if (sessionKeyOut == null) {
|
||||
return
|
||||
}
|
||||
|
||||
getOutput(sessionKeyOut).use {
|
||||
if (!result.sessionKey.isPresent) {
|
||||
val errorMsg = getMsg("sop.error.runtime.no_session_key_extracted")
|
||||
throw UnsupportedOption(String.format(errorMsg, "--session-key-out"))
|
||||
}
|
||||
val sessionKey = result.sessionKey.get() ?: return
|
||||
val writer = PrintWriter(it)
|
||||
writer.println(sessionKey)
|
||||
writer.flush()
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue