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
1 changed files with 12 additions and 7 deletions

View File

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