Fix get command to also be able to get by special name

This commit is contained in:
Paul Schaub 2022-08-09 18:40:28 +02:00
parent c7cdf4c353
commit 8b853267ff
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -4,17 +4,18 @@
package pgp.cert_d.cli.commands; package pgp.cert_d.cli.commands;
import java.io.IOException;
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;
import pgp.cert_d.BadDataException; import pgp.cert_d.BadDataException;
import pgp.cert_d.BadNameException; import pgp.cert_d.BadNameException;
import pgp.cert_d.SpecialNames;
import pgp.cert_d.cli.PGPCertDCli; import pgp.cert_d.cli.PGPCertDCli;
import pgp.certificate.Certificate; import pgp.certificate.KeyMaterial;
import picocli.CommandLine; import picocli.CommandLine;
import java.io.IOException;
@CommandLine.Command(name = "get", @CommandLine.Command(name = "get",
resourceBundle = "msg_get") resourceBundle = "msg_get")
public class Get implements Runnable { public class Get implements Runnable {
@ -30,12 +31,16 @@ public class Get implements Runnable {
@Override @Override
public void run() { public void run() {
try { try {
Certificate certificate = PGPCertDCli.getCertificateDirectory() KeyMaterial record;
.getByFingerprint(identifer); if (SpecialNames.lookupSpecialName(identifer) != null) {
if (certificate == null) { record = PGPCertDCli.getCertificateDirectory().getBySpecialName(identifer);
} else {
record = PGPCertDCli.getCertificateDirectory().getByFingerprint(identifer);
}
if (record == null) {
return; return;
} }
Streams.pipeAll(certificate.getInputStream(), System.out); Streams.pipeAll(record.getInputStream(), System.out);
} catch (IOException e) { } catch (IOException e) {
LOGGER.error("IO Error", e); LOGGER.error("IO Error", e);
System.exit(-1); System.exit(-1);