mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2025-09-09 18:29:48 +02:00
Kotlin conversion: GenerateKeyExternal
This commit is contained in:
parent
01abae4d08
commit
9b79a49bb5
2 changed files with 38 additions and 78 deletions
38
external-sop/src/main/kotlin/sop/external/operation/GenerateKeyExternal.kt
vendored
Normal file
38
external-sop/src/main/kotlin/sop/external/operation/GenerateKeyExternal.kt
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.external.operation
|
||||
|
||||
import java.util.Properties
|
||||
import sop.Ready
|
||||
import sop.external.ExternalSOP
|
||||
import sop.operation.GenerateKey
|
||||
|
||||
/** Implementation of the [GenerateKey] operation using an external SOP binary. */
|
||||
class GenerateKeyExternal(binary: String, environment: Properties) : GenerateKey {
|
||||
|
||||
private val commandList = mutableListOf(binary, "generate-key")
|
||||
private val envList = ExternalSOP.propertiesToEnv(environment).toMutableList()
|
||||
|
||||
private var argCounter = 0
|
||||
|
||||
override fun noArmor(): GenerateKey = apply { commandList.add("--no-armor") }
|
||||
|
||||
override fun userId(userId: String): GenerateKey = apply { commandList.add(userId) }
|
||||
|
||||
override fun withKeyPassword(password: String): GenerateKey = apply {
|
||||
commandList.add("--with-key-password=@ENV:KEY_PASSWORD_$argCounter")
|
||||
envList.add("KEY_PASSWORD_$argCounter=$password")
|
||||
argCounter += 1
|
||||
}
|
||||
|
||||
override fun profile(profile: String): GenerateKey = apply {
|
||||
commandList.add("--profile=$profile")
|
||||
}
|
||||
|
||||
override fun signingOnly(): GenerateKey = apply { commandList.add("--signing-only") }
|
||||
|
||||
override fun generate(): Ready =
|
||||
ExternalSOP.executeProducingOperation(Runtime.getRuntime(), commandList, envList)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue