From 6251e01d5766d301baf11b4d71be71dc72cf02c9 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sun, 15 Aug 2021 15:24:19 +0200 Subject: [PATCH] Make classes final where sensible --- .../src/main/java/org/pgpainless/PGPainless.java | 7 +++++-- .../src/main/java/org/pgpainless/key/KeyRingValidator.java | 6 +++++- .../org/pgpainless/key/protection/UnlockSecretKey.java | 6 +++++- .../src/main/java/org/pgpainless/key/util/KeyIdUtil.java | 6 +++++- .../main/java/org/pgpainless/key/util/KeyRingUtils.java | 6 +++++- .../org/pgpainless/key/util/OpenPgpKeyAttributeUtil.java | 6 +++++- .../org/pgpainless/signature/SignatureChainValidator.java | 6 +++++- .../java/org/pgpainless/signature/SignaturePicker.java | 6 +++++- .../main/java/org/pgpainless/signature/SignatureUtils.java | 6 +++++- .../subpackets/SignatureSubpacketGeneratorUtil.java | 6 +++++- .../signature/subpackets/SignatureSubpacketsUtil.java | 6 +++++- .../src/main/java/org/pgpainless/util/ArmorUtils.java | 6 +++++- .../org/pgpainless/util/ArmoredInputStreamFactory.java | 6 +++++- .../org/pgpainless/util/ArmoredOutputStreamFactory.java | 6 +++++- .../src/main/java/org/pgpainless/util/BCUtil.java | 6 +++++- .../src/main/java/org/pgpainless/util/CollectionUtils.java | 6 +++++- .../src/main/java/org/pgpainless/util/DateUtil.java | 5 ++++- .../util/selection/keyring/impl/ExactUserId.java | 6 +++++- .../pgpainless/util/selection/keyring/impl/Whitelist.java | 6 +++++- .../pgpainless/util/selection/keyring/impl/Wildcard.java | 6 +++++- .../org/pgpainless/util/selection/keyring/impl/XMPP.java | 6 +++++- 21 files changed, 104 insertions(+), 22 deletions(-) diff --git a/pgpainless-core/src/main/java/org/pgpainless/PGPainless.java b/pgpainless-core/src/main/java/org/pgpainless/PGPainless.java index 5c841c7b..ace68e81 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/PGPainless.java +++ b/pgpainless-core/src/main/java/org/pgpainless/PGPainless.java @@ -17,7 +17,6 @@ package org.pgpainless; import java.io.IOException; import java.util.Date; - import javax.annotation.Nonnull; import org.bouncycastle.openpgp.PGPKeyRing; @@ -38,7 +37,11 @@ import org.pgpainless.signature.cleartext_signatures.VerifyCleartextSignatures; import org.pgpainless.signature.cleartext_signatures.VerifyCleartextSignaturesImpl; import org.pgpainless.util.ArmorUtils; -public class PGPainless { +public final class PGPainless { + + private PGPainless() { + + } /** * Generate a new OpenPGP key ring. diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/KeyRingValidator.java b/pgpainless-core/src/main/java/org/pgpainless/key/KeyRingValidator.java index fa0984f6..cc5d0997 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/KeyRingValidator.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/KeyRingValidator.java @@ -36,7 +36,11 @@ import org.pgpainless.signature.SignatureCreationDateComparator; import org.pgpainless.signature.SignatureValidator; import org.pgpainless.util.CollectionUtils; -public class KeyRingValidator { +public final class KeyRingValidator { + + private KeyRingValidator() { + + } private static final Logger LOGGER = Logger.getLogger(KeyRingValidator.class.getName()); diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/protection/UnlockSecretKey.java b/pgpainless-core/src/main/java/org/pgpainless/key/protection/UnlockSecretKey.java index 421183de..8e45b0c8 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/protection/UnlockSecretKey.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/protection/UnlockSecretKey.java @@ -23,7 +23,11 @@ import org.pgpainless.exception.WrongPassphraseException; import org.pgpainless.key.info.KeyInfo; import org.pgpainless.util.Passphrase; -public class UnlockSecretKey { +public final class UnlockSecretKey { + + private UnlockSecretKey() { + + } public static PGPPrivateKey unlockSecretKey(PGPSecretKey secretKey, SecretKeyRingProtector protector) throws WrongPassphraseException { diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/util/KeyIdUtil.java b/pgpainless-core/src/main/java/org/pgpainless/key/util/KeyIdUtil.java index 650bf7b0..40decde7 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/util/KeyIdUtil.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/util/KeyIdUtil.java @@ -18,7 +18,11 @@ package org.pgpainless.key.util; import java.math.BigInteger; import java.util.regex.Pattern; -public class KeyIdUtil { +public final class KeyIdUtil { + + private KeyIdUtil() { + + } private static final Pattern LONG_KEY_ID = Pattern.compile("^[0-9A-Fa-f]{16}$"); diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/util/KeyRingUtils.java b/pgpainless-core/src/main/java/org/pgpainless/key/util/KeyRingUtils.java index c7872589..db3e4898 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/util/KeyRingUtils.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/util/KeyRingUtils.java @@ -35,7 +35,11 @@ import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.UnlockSecretKey; -public class KeyRingUtils { +public final class KeyRingUtils { + + private KeyRingUtils() { + + } /** * Return the primary {@link PGPSecretKey} from the provided {@link PGPSecretKeyRing}. diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/util/OpenPgpKeyAttributeUtil.java b/pgpainless-core/src/main/java/org/pgpainless/key/util/OpenPgpKeyAttributeUtil.java index 573c163d..0cd4fb21 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/util/OpenPgpKeyAttributeUtil.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/util/OpenPgpKeyAttributeUtil.java @@ -26,7 +26,11 @@ import org.bouncycastle.openpgp.PGPSignature; import org.pgpainless.algorithm.HashAlgorithm; import org.pgpainless.algorithm.SignatureType; -public class OpenPgpKeyAttributeUtil { +public final class OpenPgpKeyAttributeUtil { + + private OpenPgpKeyAttributeUtil() { + + } public static List getPreferredHashAlgorithms(PGPPublicKey publicKey) { List hashAlgorithms = new ArrayList<>(); diff --git a/pgpainless-core/src/main/java/org/pgpainless/signature/SignatureChainValidator.java b/pgpainless-core/src/main/java/org/pgpainless/signature/SignatureChainValidator.java index e6a3a060..927726ce 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/signature/SignatureChainValidator.java +++ b/pgpainless-core/src/main/java/org/pgpainless/signature/SignatureChainValidator.java @@ -42,7 +42,11 @@ import org.pgpainless.signature.subpackets.SignatureSubpacketsUtil; * Its responsibilities are checking if a signing key was eligible to create a certain signature * and if the signature is valid at the time of validation. */ -public class SignatureChainValidator { +public final class SignatureChainValidator { + + private SignatureChainValidator() { + + } private static final Logger LOGGER = Logger.getLogger(SignatureChainValidator.class.getName()); diff --git a/pgpainless-core/src/main/java/org/pgpainless/signature/SignaturePicker.java b/pgpainless-core/src/main/java/org/pgpainless/signature/SignaturePicker.java index dc9b99af..6f73d9b0 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/signature/SignaturePicker.java +++ b/pgpainless-core/src/main/java/org/pgpainless/signature/SignaturePicker.java @@ -41,7 +41,11 @@ import org.pgpainless.util.CollectionUtils; * [User Attribute [Signature ...] ...] * [[Subkey [Binding-Signature-Revocation] Primary-Key-Binding-Signature] ...] */ -public class SignaturePicker { +public final class SignaturePicker { + + private SignaturePicker() { + + } /** * Pick the, at validation date most recent valid key revocation signature. diff --git a/pgpainless-core/src/main/java/org/pgpainless/signature/SignatureUtils.java b/pgpainless-core/src/main/java/org/pgpainless/signature/SignatureUtils.java index f3337af3..6ac18175 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/signature/SignatureUtils.java +++ b/pgpainless-core/src/main/java/org/pgpainless/signature/SignatureUtils.java @@ -52,7 +52,11 @@ import org.pgpainless.util.ArmorUtils; /** * Utility methods related to signatures. */ -public class SignatureUtils { +public final class SignatureUtils { + + private SignatureUtils() { + + } /** * Return a signature generator for the provided signing key. diff --git a/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketGeneratorUtil.java b/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketGeneratorUtil.java index a2a07ffe..66aa4b50 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketGeneratorUtil.java +++ b/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketGeneratorUtil.java @@ -29,7 +29,11 @@ import org.pgpainless.algorithm.KeyFlag; /** * Utility class that helps dealing with BCs SignatureSubpacketGenerator class. */ -public class SignatureSubpacketGeneratorUtil { +public final class SignatureSubpacketGeneratorUtil { + + private SignatureSubpacketGeneratorUtil() { + + } /** * Return a list of {@link SignatureSubpacket SignatureSubpackets} from the subpacket generator, which correspond diff --git a/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketsUtil.java b/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketsUtil.java index 846635fd..1fb68f20 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketsUtil.java +++ b/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketsUtil.java @@ -62,7 +62,11 @@ import org.pgpainless.signature.SignatureUtils; * Since rfc4880 is not always clear about where a signature subpacket can be located (hashed/unhashed area), * this class makes some educated guesses as to where the subpacket may be found when necessary. */ -public class SignatureSubpacketsUtil { +public final class SignatureSubpacketsUtil { + + private SignatureSubpacketsUtil() { + + } /** * Return the issuer-fingerprint subpacket of the signature. diff --git a/pgpainless-core/src/main/java/org/pgpainless/util/ArmorUtils.java b/pgpainless-core/src/main/java/org/pgpainless/util/ArmorUtils.java index 3f9aa703..18b33574 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/util/ArmorUtils.java +++ b/pgpainless-core/src/main/java/org/pgpainless/util/ArmorUtils.java @@ -39,7 +39,7 @@ import org.bouncycastle.util.io.Streams; import org.pgpainless.algorithm.HashAlgorithm; import org.pgpainless.key.OpenPgpV4Fingerprint; -public class ArmorUtils { +public final class ArmorUtils { // MessageIDs are 32 printable characters private static final Pattern PATTERN_MESSAGE_ID = Pattern.compile("^\\S{32}$"); @@ -50,6 +50,10 @@ public class ArmorUtils { public static final String HEADER_HASH = "Hash"; public static final String HEADER_CHARSET = "Charset"; + private ArmorUtils() { + + } + public static String toAsciiArmoredString(PGPSecretKeyRing secretKeys) throws IOException { MultiMap header = keyToHeader(secretKeys); return toAsciiArmoredString(secretKeys.getEncoded(), header); diff --git a/pgpainless-core/src/main/java/org/pgpainless/util/ArmoredInputStreamFactory.java b/pgpainless-core/src/main/java/org/pgpainless/util/ArmoredInputStreamFactory.java index 6228a885..7ab5f867 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/util/ArmoredInputStreamFactory.java +++ b/pgpainless-core/src/main/java/org/pgpainless/util/ArmoredInputStreamFactory.java @@ -20,7 +20,11 @@ import java.io.InputStream; import org.bouncycastle.bcpg.ArmoredInputStream; -public class ArmoredInputStreamFactory { +public final class ArmoredInputStreamFactory { + + private ArmoredInputStreamFactory() { + + } public static ArmoredInputStream get(InputStream inputStream) throws IOException { if (inputStream instanceof CRCingArmoredInputStreamWrapper) { diff --git a/pgpainless-core/src/main/java/org/pgpainless/util/ArmoredOutputStreamFactory.java b/pgpainless-core/src/main/java/org/pgpainless/util/ArmoredOutputStreamFactory.java index 22e68431..1c54306c 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/util/ArmoredOutputStreamFactory.java +++ b/pgpainless-core/src/main/java/org/pgpainless/util/ArmoredOutputStreamFactory.java @@ -23,12 +23,16 @@ import org.bouncycastle.bcpg.ArmoredOutputStream; * Factory to create configured {@link ArmoredOutputStream ArmoredOutputStreams}. * The configuration entails setting custom version and comment headers. */ -public class ArmoredOutputStreamFactory { +public final class ArmoredOutputStreamFactory { public static final String PGPAINLESS = "PGPainless"; private static String VERSION = PGPAINLESS; public static String[] COMMENT = new String[0]; + private ArmoredOutputStreamFactory() { + + } + /** * Wrap an {@link OutputStream} inside a preconfigured {@link ArmoredOutputStream}. * diff --git a/pgpainless-core/src/main/java/org/pgpainless/util/BCUtil.java b/pgpainless-core/src/main/java/org/pgpainless/util/BCUtil.java index b43236ff..8800b755 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/util/BCUtil.java +++ b/pgpainless-core/src/main/java/org/pgpainless/util/BCUtil.java @@ -19,7 +19,11 @@ import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.bcpg.ECPublicBCPGKey; import org.bouncycastle.openpgp.PGPPublicKey; -public class BCUtil { +public final class BCUtil { + + private BCUtil() { + + } /** * Utility method to get the bit strength of OpenPGP keys. diff --git a/pgpainless-core/src/main/java/org/pgpainless/util/CollectionUtils.java b/pgpainless-core/src/main/java/org/pgpainless/util/CollectionUtils.java index bf687229..6ad81991 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/util/CollectionUtils.java +++ b/pgpainless-core/src/main/java/org/pgpainless/util/CollectionUtils.java @@ -19,7 +19,11 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -public class CollectionUtils { +public final class CollectionUtils { + + private CollectionUtils() { + + } public static List iteratorToList(Iterator iterator) { List items = new ArrayList<>(); diff --git a/pgpainless-core/src/main/java/org/pgpainless/util/DateUtil.java b/pgpainless-core/src/main/java/org/pgpainless/util/DateUtil.java index 1b04f476..cfc6cc3a 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/util/DateUtil.java +++ b/pgpainless-core/src/main/java/org/pgpainless/util/DateUtil.java @@ -20,8 +20,11 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; -public class DateUtil { +public final class DateUtil { + private DateUtil() { + + } public static SimpleDateFormat UTC_PARSER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); static { UTC_PARSER.setTimeZone(TimeZone.getTimeZone("UTC")); diff --git a/pgpainless-core/src/main/java/org/pgpainless/util/selection/keyring/impl/ExactUserId.java b/pgpainless-core/src/main/java/org/pgpainless/util/selection/keyring/impl/ExactUserId.java index 4501328d..4edc7cb5 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/util/selection/keyring/impl/ExactUserId.java +++ b/pgpainless-core/src/main/java/org/pgpainless/util/selection/keyring/impl/ExactUserId.java @@ -22,7 +22,11 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.pgpainless.util.selection.keyring.PublicKeyRingSelectionStrategy; import org.pgpainless.util.selection.keyring.SecretKeyRingSelectionStrategy; -public class ExactUserId { +public final class ExactUserId { + + private ExactUserId() { + + } public static class PubRingSelectionStrategy extends PublicKeyRingSelectionStrategy { diff --git a/pgpainless-core/src/main/java/org/pgpainless/util/selection/keyring/impl/Whitelist.java b/pgpainless-core/src/main/java/org/pgpainless/util/selection/keyring/impl/Whitelist.java index 1663706a..2d8a6ed9 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/util/selection/keyring/impl/Whitelist.java +++ b/pgpainless-core/src/main/java/org/pgpainless/util/selection/keyring/impl/Whitelist.java @@ -24,7 +24,11 @@ import org.pgpainless.util.selection.keyring.PublicKeyRingSelectionStrategy; import org.pgpainless.util.selection.keyring.SecretKeyRingSelectionStrategy; import org.pgpainless.util.MultiMap; -public class Whitelist { +public final class Whitelist { + + private Whitelist() { + + } public static class PubRingSelectionStrategy extends PublicKeyRingSelectionStrategy { diff --git a/pgpainless-core/src/main/java/org/pgpainless/util/selection/keyring/impl/Wildcard.java b/pgpainless-core/src/main/java/org/pgpainless/util/selection/keyring/impl/Wildcard.java index 7337639c..23562afe 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/util/selection/keyring/impl/Wildcard.java +++ b/pgpainless-core/src/main/java/org/pgpainless/util/selection/keyring/impl/Wildcard.java @@ -20,7 +20,11 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.pgpainless.util.selection.keyring.PublicKeyRingSelectionStrategy; import org.pgpainless.util.selection.keyring.SecretKeyRingSelectionStrategy; -public class Wildcard { +public final class Wildcard { + + private Wildcard() { + + } public static class PubRingSelectionStrategy extends PublicKeyRingSelectionStrategy { diff --git a/pgpainless-core/src/main/java/org/pgpainless/util/selection/keyring/impl/XMPP.java b/pgpainless-core/src/main/java/org/pgpainless/util/selection/keyring/impl/XMPP.java index 31b46102..aafb0ad9 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/util/selection/keyring/impl/XMPP.java +++ b/pgpainless-core/src/main/java/org/pgpainless/util/selection/keyring/impl/XMPP.java @@ -18,7 +18,11 @@ package org.pgpainless.util.selection.keyring.impl; import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing; -public class XMPP { +public final class XMPP { + + private XMPP() { + + } public static class PubRingSelectionStrategy extends ExactUserId.PubRingSelectionStrategy {