mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2025-09-09 02:09:42 +02:00
Wip: working extract-cert, fix generate-key parameter passing
This commit is contained in:
parent
e602cc16cc
commit
efec4d9110
12 changed files with 430 additions and 122 deletions
|
@ -6,6 +6,7 @@ package sop.external.operation;
|
|||
|
||||
import sop.Ready;
|
||||
import sop.exception.SOPGPException;
|
||||
import sop.external.ExternalSOP;
|
||||
import sop.operation.ExtractCert;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -13,16 +14,19 @@ import java.io.InputStream;
|
|||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
public class ExtractCertExternal implements ExtractCert {
|
||||
|
||||
private final String binary;
|
||||
private final Runtime runtime = Runtime.getRuntime();
|
||||
private final Properties environment;
|
||||
|
||||
private boolean noArmor;
|
||||
|
||||
public ExtractCertExternal(String binary) {
|
||||
public ExtractCertExternal(String binary, Properties properties) {
|
||||
this.binary = binary;
|
||||
this.environment = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,7 +36,7 @@ public class ExtractCertExternal implements ExtractCert {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Ready key(InputStream keyInputStream) throws IOException, SOPGPException.BadData {
|
||||
public Ready key(InputStream keyInputStream) throws SOPGPException.BadData {
|
||||
List<String> commandList = new ArrayList<>();
|
||||
|
||||
commandList.add(binary);
|
||||
|
@ -42,11 +46,15 @@ public class ExtractCertExternal implements ExtractCert {
|
|||
commandList.add("--no-armor");
|
||||
}
|
||||
|
||||
List<String> envList = ExternalSOP.propertiesToEnv(environment);
|
||||
|
||||
String[] command = commandList.toArray(new String[0]);
|
||||
String[] env = envList.toArray(new String[0]);
|
||||
|
||||
try {
|
||||
Process process = runtime.exec(command);
|
||||
OutputStream stdOut = process.getOutputStream();
|
||||
InputStream stdIn = process.getInputStream();
|
||||
Process process = runtime.exec(command, env);
|
||||
OutputStream extractOut = process.getOutputStream();
|
||||
InputStream extractIn = process.getInputStream();
|
||||
|
||||
return new Ready() {
|
||||
@Override
|
||||
|
@ -54,12 +62,20 @@ public class ExtractCertExternal implements ExtractCert {
|
|||
byte[] buf = new byte[4096];
|
||||
int r;
|
||||
while ((r = keyInputStream.read(buf)) > 0) {
|
||||
stdOut.write(buf, 0, r);
|
||||
extractOut.write(buf, 0, r);
|
||||
}
|
||||
|
||||
while ((r = stdIn.read(buf)) > 0) {
|
||||
keyInputStream.close();
|
||||
extractOut.close();
|
||||
|
||||
while ((r = extractIn.read(buf)) > 0) {
|
||||
outputStream.write(buf, 0 , r);
|
||||
}
|
||||
|
||||
extractIn.close();
|
||||
outputStream.close();
|
||||
|
||||
ExternalSOP.finish(process);
|
||||
}
|
||||
};
|
||||
} catch (IOException e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue