Add Export command

This commit is contained in:
Paul Schaub 2022-07-04 13:19:36 +02:00
parent 1efb2598a2
commit fca9a8ef91
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
3 changed files with 43 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import org.pgpainless.certificate_store.CertificateReader;
import org.pgpainless.certificate_store.SharedPGPCertificateDirectoryAdapter;
import pgp.cert_d.BaseDirectoryProvider;
import pgp.cert_d.SharedPGPCertificateDirectoryImpl;
import pgp.cert_d.cli.commands.Export;
import pgp.cert_d.cli.commands.Get;
import pgp.cert_d.cli.commands.Insert;
import pgp.cert_d.cli.commands.Import;
@ -25,6 +26,7 @@ import java.sql.SQLException;
name = "certificate-store",
description = "Store and manage public OpenPGP certificates",
subcommands = {
Export.class,
Insert.class,
Import.class,
Get.class,

View File

@ -0,0 +1,40 @@
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package pgp.cert_d.cli.commands;
import org.bouncycastle.util.io.Streams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pgp.cert_d.cli.PGPCertDCli;
import pgp.certificate_store.Certificate;
import picocli.CommandLine;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
@CommandLine.Command(name = "export",
description = "Export all certificates in the store to Standard Output")
public class Export implements Runnable {
private static final Logger LOGGER = LoggerFactory.getLogger(Get.class);
@Override
public void run() {
Iterator<Certificate> certificates = PGPCertDCli.getCertificateDirectory()
.getCertificates();
while (certificates.hasNext()) {
try {
Certificate certificate = certificates.next();
InputStream inputStream = certificate.getInputStream();
Streams.pipeAll(inputStream, System.out);
inputStream.close();
} catch (IOException e) {
LOGGER.error("IO Error", e);
System.exit(-1);
}
}
}
}

View File

@ -20,7 +20,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
@CommandLine.Command(name = "import",
description = "Import certificates into the store from stdin")
description = "Import certificates into the store from Standard Input")
public class Import implements Runnable {
private static final Logger LOGGER = LoggerFactory.getLogger(Import.class);