1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-23 12:52:07 +01:00

Small code style fixes and optimizations

This commit is contained in:
Paul Schaub 2021-06-10 12:42:48 +02:00
parent 845779d40b
commit 9b9064beae
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
8 changed files with 13 additions and 21 deletions

View file

@ -179,12 +179,12 @@ public class SignatureVerifyingInputStream extends FilterInputStream {
} }
@Override @Override
public int read(byte[] b) throws IOException { public int read(@Nonnull byte[] b) throws IOException {
return read(b, 0, b.length); return read(b, 0, b.length);
} }
@Override @Override
public int read(byte[] b, int off, int len) throws IOException { public int read(@Nonnull byte[] b, int off, int len) throws IOException {
int read = super.read(b, off, len); int read = super.read(b, off, len);
final boolean endOfStream = read == -1; final boolean endOfStream = read == -1;

View file

@ -342,10 +342,7 @@ public class SecretKeyRingEditor implements SecretKeyRingEditorInterface {
} }
boolean found = false; boolean found = false;
Iterator<PGPSecretKey> iterator = secretKeyRing.iterator(); for (PGPSecretKey secretKey : secretKeyRing) {
while (iterator.hasNext()) {
PGPSecretKey secretKey = iterator.next();
// Skip over unaffected subkeys // Skip over unaffected subkeys
if (secretKey.getKeyID() != fingerprint.getKeyId()) { if (secretKey.getKeyID() != fingerprint.getKeyId()) {
secretKeyList.add(secretKey); secretKeyList.add(secretKey);

View file

@ -16,6 +16,8 @@
package org.pgpainless.key.util; package org.pgpainless.key.util;
import javax.annotation.Nonnull;
public final class UserId implements CharSequence { public final class UserId implements CharSequence {
public static final class Builder { public static final class Builder {
private String name; private String name;
@ -127,7 +129,7 @@ public final class UserId implements CharSequence {
} }
@Override @Override
public String toString() { public @Nonnull String toString() {
return asString(false); return asString(false);
} }

View file

@ -24,8 +24,8 @@ public class CollectionUtils {
public static <I> List<I> iteratorToList(Iterator<I> iterator) { public static <I> List<I> iteratorToList(Iterator<I> iterator) {
List<I> items = new ArrayList<>(); List<I> items = new ArrayList<>();
while (iterator.hasNext()) { while (iterator.hasNext()) {
Object o = iterator.next(); I item = iterator.next();
items.add((I) o); items.add(item);
} }
return items; return items;
} }

View file

@ -40,10 +40,6 @@ public class PGPPublicKeyRingTest {
* It does not. * It does not.
* *
* see also https://security.stackexchange.com/questions/92635/is-it-possible-to-assign-different-uids-to-subkeys-for-the-purpose-of-having-mul * see also https://security.stackexchange.com/questions/92635/is-it-possible-to-assign-different-uids-to-subkeys-for-the-purpose-of-having-mul
*
* @throws InvalidAlgorithmParameterException
* @throws NoSuchAlgorithmException
* @throws PGPException
*/ */
@Test @Test
public void subkeysDoNotHaveUserIDsTest() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException { public void subkeysDoNotHaveUserIDsTest() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
@ -54,10 +50,8 @@ public class PGPPublicKeyRingTest {
Iterator<String> userIds = subkey.getUserIDs(); Iterator<String> userIds = subkey.getUserIDs();
if (primaryKey == subkey) { if (primaryKey == subkey) {
assertEquals("primary@user.id", userIds.next()); assertEquals("primary@user.id", userIds.next());
assertFalse(userIds.hasNext());
} else {
assertFalse(userIds.hasNext());
} }
assertFalse(userIds.hasNext());
} }
} }

View file

@ -126,9 +126,9 @@ public class ModificationDetectionTests {
/** /**
* Messages containing a missing MDC shall fail to decrypt. * Messages containing a missing MDC shall fail to decrypt.
* @param implementationFactory * @param implementationFactory implementation factory
* @throws IOException * @throws IOException in case of an io-error
* @throws PGPException * @throws PGPException in case of a pgp error
*/ */
@ParameterizedTest @ParameterizedTest
@MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")

View file

@ -39,8 +39,6 @@ public class RecursionDepthTest {
* Test that decryption is aborted when maximum recursion depth of nested packets is exceeded. * Test that decryption is aborted when maximum recursion depth of nested packets is exceeded.
* *
* @see <a href="https://tests.sequoia-pgp.org/#Maximum_recursion_depth">Sequoia-PGP Test Suite</a> * @see <a href="https://tests.sequoia-pgp.org/#Maximum_recursion_depth">Sequoia-PGP Test Suite</a>
* @throws IOException
* @throws PGPException
*/ */
@ParameterizedTest @ParameterizedTest
@MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")

View file

@ -38,6 +38,7 @@ public class ProviderFactoryTest {
private ProviderFactory customProviderFactory = new ProviderFactory() { private ProviderFactory customProviderFactory = new ProviderFactory() {
@SuppressWarnings("deprecation")
Provider provider = new Provider("PL", 1L, "PGPainlessTestProvider") { Provider provider = new Provider("PL", 1L, "PGPainlessTestProvider") {
}; };