mirror of
https://codeberg.org/PGPainless/cert-d-pgpainless.git
synced 2024-09-27 18:49:31 +02:00
Implement armor option for export command
This commit is contained in:
parent
338530b1bc
commit
6a16d0cff5
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
package pgp.cert_d.cli.commands;
|
package pgp.cert_d.cli.commands;
|
||||||
|
|
||||||
|
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
||||||
import org.bouncycastle.util.io.Streams;
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -13,28 +14,40 @@ import picocli.CommandLine;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
@CommandLine.Command(name = "export",
|
@CommandLine.Command(name = "export",
|
||||||
resourceBundle = "msg_export")
|
resourceBundle = "msg_export")
|
||||||
public class Export implements Runnable {
|
public class Export implements Runnable {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(Get.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(Export.class);
|
||||||
|
|
||||||
|
@CommandLine.Option(names = {"-a", "--armor"})
|
||||||
|
boolean armor = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Iterator<Certificate> certificates = PGPCertDCli.getCertificateDirectory()
|
Iterator<Certificate> certificates = PGPCertDCli.getCertificateDirectory()
|
||||||
.getCertificates();
|
.getCertificates();
|
||||||
|
OutputStream out = armor ? new ArmoredOutputStream(System.out) : System.out;
|
||||||
while (certificates.hasNext()) {
|
while (certificates.hasNext()) {
|
||||||
try {
|
try {
|
||||||
Certificate certificate = certificates.next();
|
Certificate certificate = certificates.next();
|
||||||
InputStream inputStream = certificate.getInputStream();
|
InputStream inputStream = certificate.getInputStream();
|
||||||
Streams.pipeAll(inputStream, System.out);
|
Streams.pipeAll(inputStream, out);
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.error("IO Error", e);
|
LOGGER.error("IO Error", e);
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (armor) {
|
||||||
|
try {
|
||||||
|
out.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue