mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2025-09-08 17:59:43 +02:00
Add RevokeKeyExternal implementation and some basic tests
This commit is contained in:
parent
e6393b44b9
commit
618d123a7b
5 changed files with 143 additions and 1 deletions
|
@ -19,6 +19,7 @@ import sop.external.operation.InlineDetachExternal;
|
|||
import sop.external.operation.InlineSignExternal;
|
||||
import sop.external.operation.InlineVerifyExternal;
|
||||
import sop.external.operation.ListProfilesExternal;
|
||||
import sop.external.operation.RevokeKeyExternal;
|
||||
import sop.external.operation.VersionExternal;
|
||||
import sop.operation.Armor;
|
||||
import sop.operation.Dearmor;
|
||||
|
@ -164,7 +165,7 @@ public class ExternalSOP implements SOP {
|
|||
|
||||
@Override
|
||||
public RevokeKey revokeKey() {
|
||||
return null;
|
||||
return new RevokeKeyExternal(binaryName, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
48
external-sop/src/main/java/sop/external/operation/RevokeKeyExternal.java
vendored
Normal file
48
external-sop/src/main/java/sop/external/operation/RevokeKeyExternal.java
vendored
Normal file
|
@ -0,0 +1,48 @@
|
|||
// 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 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
|
||||
public RevokeKey noArmor() {
|
||||
this.commandList.add("--no-armor");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RevokeKey withKeyPassword(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
|
||||
public Ready keys(InputStream keys) {
|
||||
return ExternalSOP.executeTransformingOperation(Runtime.getRuntime(), commandList, envList, keys);
|
||||
}
|
||||
}
|
11
external-sop/src/test/java/sop/testsuite/external/operation/ExternalRevokeKeyTest.java
vendored
Normal file
11
external-sop/src/test/java/sop/testsuite/external/operation/ExternalRevokeKeyTest.java
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.external.operation;
|
||||
|
||||
import sop.testsuite.operation.RevokeKeyTest;
|
||||
|
||||
public class ExternalRevokeKeyTest extends RevokeKeyTest {
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue