Compare commits
4 Commits
f21802523a
...
76a5a91fe0
Author | SHA1 | Date |
---|---|---|
Paul Schaub | 76a5a91fe0 | |
Paul Schaub | d8a060d0df | |
Paul Schaub | 27ae686d52 | |
Paul Schaub | 52a31cb541 |
|
@ -42,11 +42,14 @@ public class PGPCertDCli {
|
|||
|
||||
static PGPainlessCertD certificateDirectory;
|
||||
|
||||
// https://www.cyberciti.biz/faq/linux-bash-exit-status-set-exit-statusin-bash/
|
||||
public static final int EXIT_CODE_NOT_A_STORE = 30;
|
||||
|
||||
private int executionStrategy(CommandLine.ParseResult parseResult) {
|
||||
try {
|
||||
initStore();
|
||||
} catch (NotAStoreException | SQLException e) {
|
||||
return -1;
|
||||
return EXIT_CODE_NOT_A_STORE;
|
||||
}
|
||||
return new CommandLine.RunLast().execute(parseResult);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import pgp.certificate_store.exception.BadNameException;
|
|||
import picocli.CommandLine;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
@CommandLine.Command(name = "get",
|
||||
resourceBundle = "msg_get")
|
||||
|
@ -26,6 +27,10 @@ public class Get implements Runnable {
|
|||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Get.class);
|
||||
|
||||
// https://www.cyberciti.biz/faq/linux-bash-exit-status-set-exit-statusin-bash/
|
||||
public static final int EXIT_CODE_NO_SUCH_ELEMENT = 2;
|
||||
public static final int EXIT_CODE_IO_ERROR = 5;
|
||||
|
||||
@CommandLine.Option(names = {"-a", "--armor"})
|
||||
boolean armor = false;
|
||||
|
||||
|
@ -33,16 +38,16 @@ public class Get implements Runnable {
|
|||
paramLabel = "IDENTIFIER",
|
||||
arity = "1"
|
||||
)
|
||||
String identifer;
|
||||
String identifier;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
KeyMaterial record;
|
||||
if (SpecialNames.lookupSpecialName(identifer) != null) {
|
||||
record = PGPCertDCli.getCertificateDirectory().getBySpecialName(identifer);
|
||||
if (SpecialNames.lookupSpecialName(identifier) != null) {
|
||||
record = PGPCertDCli.getCertificateDirectory().getBySpecialName(identifier);
|
||||
} else {
|
||||
record = PGPCertDCli.getCertificateDirectory().getByFingerprint(identifer.toLowerCase());
|
||||
record = PGPCertDCli.getCertificateDirectory().getByFingerprint(identifier.toLowerCase());
|
||||
}
|
||||
if (record == null) {
|
||||
return;
|
||||
|
@ -57,9 +62,12 @@ public class Get implements Runnable {
|
|||
Streams.pipeAll(record.getInputStream(), System.out);
|
||||
}
|
||||
|
||||
} catch (NoSuchElementException e) {
|
||||
LOGGER.debug("Certificate not found.", e);
|
||||
System.exit(EXIT_CODE_NO_SUCH_ELEMENT);
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("IO Error", e);
|
||||
System.exit(-1);
|
||||
System.exit(EXIT_CODE_IO_ERROR);
|
||||
} catch (BadDataException e) {
|
||||
LOGGER.error("Certificate file contains bad data.", e);
|
||||
System.exit(-1);
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package pgp.cert_d.cli;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class DummyTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
|
@ -27,11 +27,12 @@ import java.io.InputStream;
|
|||
import java.nio.charset.Charset;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class SetupTest {
|
||||
|
@ -53,7 +54,7 @@ public class SetupTest {
|
|||
@Test
|
||||
public void testSetupGeneratesTrustRoot()
|
||||
throws BadDataException, IOException {
|
||||
assertNull(store.getTrustRoot());
|
||||
assertThrows(NoSuchElementException.class, () -> store.getTrustRoot());
|
||||
|
||||
PGPCertDCli.main(new String[] {"setup"});
|
||||
KeyMaterial trustRoot = store.getTrustRoot();
|
||||
|
@ -68,7 +69,7 @@ public class SetupTest {
|
|||
@Test
|
||||
public void testSetupWithPassword()
|
||||
throws BadDataException, IOException, PGPException {
|
||||
assertNull(store.getTrustRoot());
|
||||
assertThrows(NoSuchElementException.class, () -> store.getTrustRoot());
|
||||
|
||||
PGPCertDCli.main(new String[] {"setup", "--with-password", "sw0rdf1sh"});
|
||||
KeyMaterial trustRoot = store.getTrustRoot();
|
||||
|
@ -87,7 +88,7 @@ public class SetupTest {
|
|||
public void testSetupImportFromStdin()
|
||||
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException,
|
||||
BadDataException, IOException {
|
||||
assertNull(store.getTrustRoot());
|
||||
assertThrows(NoSuchElementException.class, () -> store.getTrustRoot());
|
||||
|
||||
PGPSecretKeyRing trustRoot = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("trust-root");
|
||||
|
@ -108,7 +109,7 @@ public class SetupTest {
|
|||
@Test
|
||||
public void testSetupOverridesExistingTrustRoot()
|
||||
throws BadDataException, IOException {
|
||||
assertNull(store.getTrustRoot());
|
||||
assertThrows(NoSuchElementException.class, () -> store.getTrustRoot());
|
||||
|
||||
PGPCertDCli.main(new String[] {"setup"});
|
||||
KeyMaterial trustRoot = store.getTrustRoot();
|
||||
|
|
|
@ -7,7 +7,7 @@ package org.pgpainless.cert_d;
|
|||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
@ -20,6 +20,7 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -74,8 +75,8 @@ public class SharedPGPCertificateDirectoryTest {
|
|||
OpenPgpFingerprint fingerprint = OpenPgpFingerprint.of(cert);
|
||||
ByteArrayInputStream certIn = new ByteArrayInputStream(cert.getEncoded());
|
||||
|
||||
// standard case: get() is null
|
||||
assertNull(directory.getByFingerprint(fingerprint.toString().toLowerCase()));
|
||||
// standard case: no cert found
|
||||
assertThrows(NoSuchElementException.class, () -> directory.getByFingerprint(fingerprint.toString().toLowerCase()));
|
||||
|
||||
// insert and check returned certs fingerprint
|
||||
Certificate certificate = directory.insert(certIn, dummyMerge);
|
||||
|
@ -99,8 +100,8 @@ public class SharedPGPCertificateDirectoryTest {
|
|||
OpenPgpFingerprint fingerprint = OpenPgpFingerprint.of(trustRoot);
|
||||
ByteArrayInputStream certIn = new ByteArrayInputStream(trustRoot.getEncoded());
|
||||
|
||||
// standard case: get() is null
|
||||
assertNull(directory.getBySpecialName("trust-root"));
|
||||
// standard case: no cert found
|
||||
assertThrows(NoSuchElementException.class, () -> directory.getBySpecialName("trust-root"));
|
||||
|
||||
// insert and check returned certs fingerprint
|
||||
Certificate certificate = directory.insertWithSpecialName("trust-root", certIn, dummyMerge);
|
||||
|
|
|
@ -13,7 +13,7 @@ allprojects {
|
|||
junitVersion = '5.8.2'
|
||||
mockitoVersion = '4.5.1'
|
||||
pgpainlessVersion = '1.3.5'
|
||||
pgpCertDJavaVersion = '0.2.0'
|
||||
pgpCertDJavaVersion = '0.2.1'
|
||||
picocliVersion = '4.6.3'
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue