1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-23 03:17:58 +01:00

Make classes final where sensible

This commit is contained in:
Paul Schaub 2021-08-15 15:24:19 +02:00
parent 1ce6632f18
commit 6251e01d57
21 changed files with 104 additions and 22 deletions

View file

@ -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.

View file

@ -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());

View file

@ -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 {

View file

@ -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}$");

View file

@ -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}.

View file

@ -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<HashAlgorithm> getPreferredHashAlgorithms(PGPPublicKey publicKey) {
List<HashAlgorithm> hashAlgorithms = new ArrayList<>();

View file

@ -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());

View file

@ -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.

View file

@ -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.

View file

@ -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

View file

@ -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.

View file

@ -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<String, String> header = keyToHeader(secretKeys);
return toAsciiArmoredString(secretKeys.getEncoded(), header);

View file

@ -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) {

View file

@ -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}.
*

View file

@ -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.

View file

@ -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 <I> List<I> iteratorToList(Iterator<I> iterator) {
List<I> items = new ArrayList<>();

View file

@ -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"));

View file

@ -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<String> {

View file

@ -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<O> extends PublicKeyRingSelectionStrategy<O> {

View file

@ -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<O> extends PublicKeyRingSelectionStrategy<O> {

View file

@ -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 {