2023-01-05 03:06:22 +01:00
|
|
|
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2023-01-07 15:23:57 +01:00
|
|
|
package sop.external.operation;
|
2023-01-05 03:06:22 +01:00
|
|
|
|
|
|
|
import sop.Ready;
|
|
|
|
import sop.exception.SOPGPException;
|
2023-01-09 14:56:53 +01:00
|
|
|
import sop.external.ExternalSOP;
|
2023-01-05 03:06:22 +01:00
|
|
|
import sop.operation.ExtractCert;
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2023-01-09 14:56:53 +01:00
|
|
|
import java.util.Properties;
|
2023-01-05 03:06:22 +01:00
|
|
|
|
2023-01-19 17:29:29 +01:00
|
|
|
/**
|
|
|
|
* Implementation of the {@link ExtractCert} operation using an external SOP binary.
|
|
|
|
*/
|
2023-01-07 15:23:57 +01:00
|
|
|
public class ExtractCertExternal implements ExtractCert {
|
2023-01-05 03:06:22 +01:00
|
|
|
|
2023-01-09 19:48:25 +01:00
|
|
|
private final List<String> commandList = new ArrayList<>();
|
|
|
|
private final List<String> envList;
|
2023-01-05 03:06:22 +01:00
|
|
|
|
2023-01-09 14:56:53 +01:00
|
|
|
public ExtractCertExternal(String binary, Properties properties) {
|
2023-01-09 19:48:25 +01:00
|
|
|
this.commandList.add(binary);
|
|
|
|
this.commandList.add("extract-cert");
|
|
|
|
this.envList = ExternalSOP.propertiesToEnv(properties);
|
2023-01-05 03:06:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ExtractCert noArmor() {
|
2023-01-09 19:48:25 +01:00
|
|
|
this.commandList.add("--no-armor");
|
2023-01-05 03:06:22 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-09 14:56:53 +01:00
|
|
|
public Ready key(InputStream keyInputStream) throws SOPGPException.BadData {
|
2023-01-22 15:07:17 +01:00
|
|
|
return ExternalSOP.executeTransformingOperation(Runtime.getRuntime(), commandList, envList, keyInputStream);
|
2023-01-05 03:06:22 +01:00
|
|
|
}
|
|
|
|
}
|