mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-11-19 05:52:04 +01:00
Kotlin conversion: RevokeKeyExternal
This commit is contained in:
parent
f2204dfd4d
commit
832a455c4c
2 changed files with 31 additions and 52 deletions
|
@ -1,52 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.external.operation;
|
||||
|
||||
import sop.Ready;
|
||||
import sop.exception.SOPGPException;
|
||||
import sop.external.ExternalSOP;
|
||||
import sop.operation.RevokeKey;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
public class RevokeKeyExternal implements RevokeKey {
|
||||
|
||||
private final List<String> commandList = new ArrayList<>();
|
||||
private final List<String> envList;
|
||||
|
||||
private int withKeyPasswordCounter = 0;
|
||||
|
||||
public RevokeKeyExternal(String binary, Properties environment) {
|
||||
this.commandList.add(binary);
|
||||
this.commandList.add("revoke-key");
|
||||
this.envList = ExternalSOP.propertiesToEnv(environment);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public RevokeKey noArmor() {
|
||||
this.commandList.add("--no-armor");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public RevokeKey withKeyPassword(@Nonnull byte[] password) throws SOPGPException.UnsupportedOption, SOPGPException.PasswordNotHumanReadable {
|
||||
String envVar = "KEY_PASSWORD_" + withKeyPasswordCounter++;
|
||||
commandList.add("--with-key-password=@ENV:" + envVar);
|
||||
envList.add(envVar + "=" + new String(password));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public Ready keys(@Nonnull InputStream keys) {
|
||||
return ExternalSOP.executeTransformingOperation(Runtime.getRuntime(), commandList, envList, keys);
|
||||
}
|
||||
}
|
31
external-sop/src/main/kotlin/sop/external/operation/RevokeKeyExternal.kt
vendored
Normal file
31
external-sop/src/main/kotlin/sop/external/operation/RevokeKeyExternal.kt
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.external.operation
|
||||
|
||||
import java.io.InputStream
|
||||
import java.util.Properties
|
||||
import sop.Ready
|
||||
import sop.external.ExternalSOP
|
||||
import sop.operation.RevokeKey
|
||||
|
||||
/** Implementation of the [RevokeKey] operation using an external SOP binary. */
|
||||
class RevokeKeyExternal(binary: String, environment: Properties) : RevokeKey {
|
||||
|
||||
private val commandList = mutableListOf(binary, "revoke-key")
|
||||
private val envList = ExternalSOP.propertiesToEnv(environment).toMutableList()
|
||||
|
||||
private var argCount = 0
|
||||
|
||||
override fun noArmor(): RevokeKey = apply { commandList.add("--no-armor") }
|
||||
|
||||
override fun withKeyPassword(password: ByteArray): RevokeKey = apply {
|
||||
commandList.add("--with-key-password=@ENV:KEY_PASSWORD_$argCount")
|
||||
envList.add("KEY_PASSWORD_$argCount=${String(password)}")
|
||||
argCount += 1
|
||||
}
|
||||
|
||||
override fun keys(keys: InputStream): Ready =
|
||||
ExternalSOP.executeTransformingOperation(Runtime.getRuntime(), commandList, envList, keys)
|
||||
}
|
Loading…
Reference in a new issue