Add list-profiles command

This commit is contained in:
Paul Schaub 2023-04-11 15:06:37 +02:00
parent 17b305924c
commit 83a003e80f
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
14 changed files with 216 additions and 0 deletions

View file

@ -18,6 +18,7 @@ import sop.external.operation.GenerateKeyExternal;
import sop.external.operation.InlineDetachExternal;
import sop.external.operation.InlineSignExternal;
import sop.external.operation.InlineVerifyExternal;
import sop.external.operation.ListProfilesExternal;
import sop.external.operation.VersionExternal;
import sop.operation.Armor;
import sop.operation.Dearmor;
@ -30,6 +31,7 @@ import sop.operation.GenerateKey;
import sop.operation.InlineDetach;
import sop.operation.InlineSign;
import sop.operation.InlineVerify;
import sop.operation.ListProfiles;
import sop.operation.Version;
import javax.annotation.Nonnull;
@ -154,6 +156,11 @@ public class ExternalSOP implements SOP {
return new ArmorExternal(binaryName, properties);
}
@Override
public ListProfiles listProfiles() {
return new ListProfilesExternal(binaryName, properties);
}
@Override
public Dearmor dearmor() {
return new DearmorExternal(binaryName, properties);

View file

@ -51,6 +51,12 @@ public class GenerateKeyExternal implements GenerateKey {
return this;
}
@Override
public GenerateKey profile(String profile) {
commandList.add("--profile=" + profile);
return this;
}
@Override
public Ready generate()
throws SOPGPException.MissingArg, SOPGPException.UnsupportedAsymmetricAlgo {

View file

@ -0,0 +1,47 @@
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package sop.external.operation;
import sop.external.ExternalSOP;
import sop.operation.ListProfiles;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
public class ListProfilesExternal extends ListProfiles {
private final List<String> commandList = new ArrayList<>();
private final List<String> envList;
public ListProfilesExternal(String binary, Properties properties) {
this.commandList.add(binary);
this.commandList.add("list-profiles");
this.envList = ExternalSOP.propertiesToEnv(properties);
}
@Override
public List<String> ofCommand(String command) {
commandList.add(command);
try {
String output = new String(ExternalSOP.executeProducingOperation(Runtime.getRuntime(), commandList, envList).getBytes());
return Arrays.asList(output.split("\n"));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public List<String> global() {
try {
String output = new String(ExternalSOP.executeProducingOperation(Runtime.getRuntime(), commandList, envList).getBytes());
return Arrays.asList(output.split("\n"));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

View file

@ -0,0 +1,13 @@
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package sop.testsuite.external.operation;
import org.junit.jupiter.api.condition.EnabledIf;
import sop.testsuite.operation.ListProfilesTest;
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
public class ExternalListProfilesTest extends ListProfilesTest {
}