mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-01-09 03:37: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
pgpainless-core/src
main/java/org/pgpainless
algorithm
decryption_verification
encryption_signing
key/info
test/java/org/pgpainless
pgpainless-sop/src/main/java/org/pgpainless/sop
|
@ -16,7 +16,7 @@ import java.util.Set;
|
|||
*/
|
||||
public class AlgorithmSuite {
|
||||
|
||||
private static AlgorithmSuite defaultAlgorithmSuite = new AlgorithmSuite(
|
||||
private static final AlgorithmSuite defaultAlgorithmSuite = new AlgorithmSuite(
|
||||
Arrays.asList(
|
||||
SymmetricKeyAlgorithm.AES_256,
|
||||
SymmetricKeyAlgorithm.AES_192,
|
||||
|
|
|
@ -24,7 +24,7 @@ public class DecryptionBuilder implements DecryptionBuilderInterface {
|
|||
|
||||
class DecryptWithImpl implements DecryptWith {
|
||||
|
||||
private BufferedInputStream inputStream;
|
||||
private final BufferedInputStream inputStream;
|
||||
|
||||
DecryptWithImpl(InputStream inputStream) {
|
||||
this.inputStream = new BufferedInputStream(inputStream, BUFFER_SIZE);
|
||||
|
|
|
@ -145,7 +145,7 @@ public final class EncryptionResult {
|
|||
private CompressionAlgorithm compressionAlgorithm;
|
||||
|
||||
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 Date modificationDate = new Date(0L); // NOW
|
||||
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 final PGPKeyRing keys;
|
||||
private Signatures signatures;
|
||||
private final Signatures signatures;
|
||||
private final Date evaluationDate;
|
||||
private final String primaryUserId;
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ import java.nio.charset.StandardCharsets;
|
|||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
|
@ -41,7 +40,7 @@ import org.pgpainless.util.Passphrase;
|
|||
|
||||
public class MissingPassphraseForDecryptionTest {
|
||||
|
||||
private String passphrase = "dragon123";
|
||||
private final String passphrase = "dragon123";
|
||||
private PGPSecretKeyRing secretKeys;
|
||||
private byte[] message;
|
||||
|
||||
|
@ -63,7 +62,6 @@ public class MissingPassphraseForDecryptionTest {
|
|||
@Test
|
||||
public void invalidPostponedKeysStrategyTest() {
|
||||
SecretKeyPassphraseProvider callback = new SecretKeyPassphraseProvider() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Passphrase getPassphraseFor(Long keyId) {
|
||||
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 {
|
||||
// interactive callback
|
||||
SecretKeyPassphraseProvider callback = new SecretKeyPassphraseProvider() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Passphrase getPassphraseFor(Long keyId) {
|
||||
// is called in interactive mode
|
||||
|
@ -121,7 +118,6 @@ public class MissingPassphraseForDecryptionTest {
|
|||
List<PGPPublicKey> encryptionKeys = info.getEncryptionSubkeys(EncryptionPurpose.ANY);
|
||||
|
||||
SecretKeyPassphraseProvider callback = new SecretKeyPassphraseProvider() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Passphrase getPassphraseFor(Long keyId) {
|
||||
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 org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ProviderFactoryTest {
|
||||
|
||||
@Test
|
||||
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() {
|
||||
private final ProviderFactory customProviderFactory = new ProviderFactory() {
|
||||
|
||||
@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();
|
||||
}
|
||||
};
|
||||
|
||||
@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>() {
|
||||
|
||||
private ByteArrayOutputStream sigOut = new ByteArrayOutputStream();
|
||||
@Override
|
||||
public Signatures writeTo(OutputStream messageOutputStream) throws SOPGPException.NoSignature, IOException {
|
||||
private final ByteArrayOutputStream sigOut = new ByteArrayOutputStream();
|
||||
|
||||
PGPSignatureList signatures = null;
|
||||
@Override
|
||||
public Signatures writeTo(OutputStream messageOutputStream)
|
||||
throws SOPGPException.NoSignature, IOException {
|
||||
|
||||
PGPSignatureList signatures;
|
||||
try {
|
||||
signatures = ClearsignedMessageUtil.detachSignaturesFromInbandClearsignedMessage(messageInputStream, messageOutputStream);
|
||||
} catch (WrongConsumingMethodException e) {
|
||||
|
|
Loading…
Reference in a new issue