mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-01-10 04:07:57 +01:00
Fix more code issues
This commit is contained in:
parent
e96d668ee2
commit
59f1a85887
7 changed files with 31 additions and 28 deletions
|
@ -16,7 +16,7 @@ import java.util.Set;
|
||||||
*/
|
*/
|
||||||
public class AlgorithmSuite {
|
public class AlgorithmSuite {
|
||||||
|
|
||||||
private static AlgorithmSuite defaultAlgorithmSuite = new AlgorithmSuite(
|
private static final AlgorithmSuite defaultAlgorithmSuite = new AlgorithmSuite(
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
SymmetricKeyAlgorithm.AES_256,
|
SymmetricKeyAlgorithm.AES_256,
|
||||||
SymmetricKeyAlgorithm.AES_192,
|
SymmetricKeyAlgorithm.AES_192,
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class DecryptionBuilder implements DecryptionBuilderInterface {
|
||||||
|
|
||||||
class DecryptWithImpl implements DecryptWith {
|
class DecryptWithImpl implements DecryptWith {
|
||||||
|
|
||||||
private BufferedInputStream inputStream;
|
private final BufferedInputStream inputStream;
|
||||||
|
|
||||||
DecryptWithImpl(InputStream inputStream) {
|
DecryptWithImpl(InputStream inputStream) {
|
||||||
this.inputStream = new BufferedInputStream(inputStream, BUFFER_SIZE);
|
this.inputStream = new BufferedInputStream(inputStream, BUFFER_SIZE);
|
||||||
|
|
|
@ -145,7 +145,7 @@ public final class EncryptionResult {
|
||||||
private CompressionAlgorithm compressionAlgorithm;
|
private CompressionAlgorithm compressionAlgorithm;
|
||||||
|
|
||||||
private final MultiMap<SubkeyIdentifier, PGPSignature> detachedSignatures = new MultiMap<>();
|
private final MultiMap<SubkeyIdentifier, PGPSignature> detachedSignatures = new MultiMap<>();
|
||||||
private Set<SubkeyIdentifier> recipients = new HashSet<>();
|
private final Set<SubkeyIdentifier> recipients = new HashSet<>();
|
||||||
private String fileName = "";
|
private String fileName = "";
|
||||||
private Date modificationDate = new Date(0L); // NOW
|
private Date modificationDate = new Date(0L); // NOW
|
||||||
private StreamEncoding encoding = StreamEncoding.BINARY;
|
private StreamEncoding encoding = StreamEncoding.BINARY;
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class KeyRingInfo {
|
||||||
private static final Pattern PATTERN_EMAIL = Pattern.compile("[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}");
|
private static final Pattern PATTERN_EMAIL = Pattern.compile("[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}");
|
||||||
|
|
||||||
private final PGPKeyRing keys;
|
private final PGPKeyRing keys;
|
||||||
private Signatures signatures;
|
private final Signatures signatures;
|
||||||
private final Date evaluationDate;
|
private final Date evaluationDate;
|
||||||
private final String primaryUserId;
|
private final String primaryUserId;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
import java.security.InvalidAlgorithmParameterException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||||
|
@ -41,7 +40,7 @@ import org.pgpainless.util.Passphrase;
|
||||||
|
|
||||||
public class MissingPassphraseForDecryptionTest {
|
public class MissingPassphraseForDecryptionTest {
|
||||||
|
|
||||||
private String passphrase = "dragon123";
|
private final String passphrase = "dragon123";
|
||||||
private PGPSecretKeyRing secretKeys;
|
private PGPSecretKeyRing secretKeys;
|
||||||
private byte[] message;
|
private byte[] message;
|
||||||
|
|
||||||
|
@ -63,7 +62,6 @@ public class MissingPassphraseForDecryptionTest {
|
||||||
@Test
|
@Test
|
||||||
public void invalidPostponedKeysStrategyTest() {
|
public void invalidPostponedKeysStrategyTest() {
|
||||||
SecretKeyPassphraseProvider callback = new SecretKeyPassphraseProvider() {
|
SecretKeyPassphraseProvider callback = new SecretKeyPassphraseProvider() {
|
||||||
@Nullable
|
|
||||||
@Override
|
@Override
|
||||||
public Passphrase getPassphraseFor(Long keyId) {
|
public Passphrase getPassphraseFor(Long keyId) {
|
||||||
fail("MUST NOT get called in if postponed key strategy is invalid.");
|
fail("MUST NOT get called in if postponed key strategy is invalid.");
|
||||||
|
@ -88,7 +86,6 @@ public class MissingPassphraseForDecryptionTest {
|
||||||
public void interactiveStrategy() throws PGPException, IOException {
|
public void interactiveStrategy() throws PGPException, IOException {
|
||||||
// interactive callback
|
// interactive callback
|
||||||
SecretKeyPassphraseProvider callback = new SecretKeyPassphraseProvider() {
|
SecretKeyPassphraseProvider callback = new SecretKeyPassphraseProvider() {
|
||||||
@Nullable
|
|
||||||
@Override
|
@Override
|
||||||
public Passphrase getPassphraseFor(Long keyId) {
|
public Passphrase getPassphraseFor(Long keyId) {
|
||||||
// is called in interactive mode
|
// is called in interactive mode
|
||||||
|
@ -121,7 +118,6 @@ public class MissingPassphraseForDecryptionTest {
|
||||||
List<PGPPublicKey> encryptionKeys = info.getEncryptionSubkeys(EncryptionPurpose.ANY);
|
List<PGPPublicKey> encryptionKeys = info.getEncryptionSubkeys(EncryptionPurpose.ANY);
|
||||||
|
|
||||||
SecretKeyPassphraseProvider callback = new SecretKeyPassphraseProvider() {
|
SecretKeyPassphraseProvider callback = new SecretKeyPassphraseProvider() {
|
||||||
@Nullable
|
|
||||||
@Override
|
@Override
|
||||||
public Passphrase getPassphraseFor(Long keyId) {
|
public Passphrase getPassphraseFor(Long keyId) {
|
||||||
fail("MUST NOT get called in non-interactive mode.");
|
fail("MUST NOT get called in non-interactive mode.");
|
||||||
|
|
|
@ -8,27 +8,15 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import java.security.Provider;
|
import java.security.Provider;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class ProviderFactoryTest {
|
public class ProviderFactoryTest {
|
||||||
|
|
||||||
@Test
|
private final ProviderFactory customProviderFactory = new ProviderFactory() {
|
||||||
public void providerFactoryDefaultIsBouncyCastleTest() {
|
|
||||||
assertEquals("BC", ProviderFactory.getProviderName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setCustomProviderTest() {
|
|
||||||
ProviderFactory.setFactory(customProviderFactory);
|
|
||||||
assertEquals("PL", ProviderFactory.getProviderName());
|
|
||||||
// Reset back to BouncyCastle
|
|
||||||
ProviderFactory.setFactory(new BouncyCastleProviderFactory());
|
|
||||||
}
|
|
||||||
|
|
||||||
private ProviderFactory customProviderFactory = new ProviderFactory() {
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
Provider provider = new Provider("PL", 1L, "PGPainlessTestProvider") {
|
final Provider provider = new Provider("PL", 1L, "PGPainlessTestProvider") {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -42,4 +30,21 @@ public class ProviderFactoryTest {
|
||||||
return provider.getName();
|
return provider.getName();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void providerFactoryDefaultIsBouncyCastleTest() {
|
||||||
|
assertEquals("BC", ProviderFactory.getProviderName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setCustomProviderTest() {
|
||||||
|
ProviderFactory.setFactory(customProviderFactory);
|
||||||
|
assertEquals("PL", ProviderFactory.getProviderName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void resetToDefault() {
|
||||||
|
// Reset back to BouncyCastle
|
||||||
|
ProviderFactory.setFactory(new BouncyCastleProviderFactory());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,11 +37,13 @@ public class DetachInbandSignatureAndMessageImpl implements DetachInbandSignatur
|
||||||
|
|
||||||
return new ReadyWithResult<Signatures>() {
|
return new ReadyWithResult<Signatures>() {
|
||||||
|
|
||||||
private ByteArrayOutputStream sigOut = new ByteArrayOutputStream();
|
private final ByteArrayOutputStream sigOut = new ByteArrayOutputStream();
|
||||||
@Override
|
|
||||||
public Signatures writeTo(OutputStream messageOutputStream) throws SOPGPException.NoSignature, IOException {
|
|
||||||
|
|
||||||
PGPSignatureList signatures = null;
|
@Override
|
||||||
|
public Signatures writeTo(OutputStream messageOutputStream)
|
||||||
|
throws SOPGPException.NoSignature, IOException {
|
||||||
|
|
||||||
|
PGPSignatureList signatures;
|
||||||
try {
|
try {
|
||||||
signatures = ClearsignedMessageUtil.detachSignaturesFromInbandClearsignedMessage(messageInputStream, messageOutputStream);
|
signatures = ClearsignedMessageUtil.detachSignaturesFromInbandClearsignedMessage(messageInputStream, messageOutputStream);
|
||||||
} catch (WrongConsumingMethodException e) {
|
} catch (WrongConsumingMethodException e) {
|
||||||
|
|
Loading…
Reference in a new issue