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:
parent
1ce6632f18
commit
6251e01d57
21 changed files with 104 additions and 22 deletions
|
@ -17,7 +17,6 @@ package org.pgpainless;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import org.bouncycastle.openpgp.PGPKeyRing;
|
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.signature.cleartext_signatures.VerifyCleartextSignaturesImpl;
|
||||||
import org.pgpainless.util.ArmorUtils;
|
import org.pgpainless.util.ArmorUtils;
|
||||||
|
|
||||||
public class PGPainless {
|
public final class PGPainless {
|
||||||
|
|
||||||
|
private PGPainless() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a new OpenPGP key ring.
|
* Generate a new OpenPGP key ring.
|
||||||
|
|
|
@ -36,7 +36,11 @@ import org.pgpainless.signature.SignatureCreationDateComparator;
|
||||||
import org.pgpainless.signature.SignatureValidator;
|
import org.pgpainless.signature.SignatureValidator;
|
||||||
import org.pgpainless.util.CollectionUtils;
|
import org.pgpainless.util.CollectionUtils;
|
||||||
|
|
||||||
public class KeyRingValidator {
|
public final class KeyRingValidator {
|
||||||
|
|
||||||
|
private KeyRingValidator() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(KeyRingValidator.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(KeyRingValidator.class.getName());
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,11 @@ import org.pgpainless.exception.WrongPassphraseException;
|
||||||
import org.pgpainless.key.info.KeyInfo;
|
import org.pgpainless.key.info.KeyInfo;
|
||||||
import org.pgpainless.util.Passphrase;
|
import org.pgpainless.util.Passphrase;
|
||||||
|
|
||||||
public class UnlockSecretKey {
|
public final class UnlockSecretKey {
|
||||||
|
|
||||||
|
private UnlockSecretKey() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static PGPPrivateKey unlockSecretKey(PGPSecretKey secretKey, SecretKeyRingProtector protector)
|
public static PGPPrivateKey unlockSecretKey(PGPSecretKey secretKey, SecretKeyRingProtector protector)
|
||||||
throws WrongPassphraseException {
|
throws WrongPassphraseException {
|
||||||
|
|
|
@ -18,7 +18,11 @@ package org.pgpainless.key.util;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.regex.Pattern;
|
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}$");
|
private static final Pattern LONG_KEY_ID = Pattern.compile("^[0-9A-Fa-f]{16}$");
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,11 @@ import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
||||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||||
import org.pgpainless.key.protection.UnlockSecretKey;
|
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}.
|
* Return the primary {@link PGPSecretKey} from the provided {@link PGPSecretKeyRing}.
|
||||||
|
|
|
@ -26,7 +26,11 @@ import org.bouncycastle.openpgp.PGPSignature;
|
||||||
import org.pgpainless.algorithm.HashAlgorithm;
|
import org.pgpainless.algorithm.HashAlgorithm;
|
||||||
import org.pgpainless.algorithm.SignatureType;
|
import org.pgpainless.algorithm.SignatureType;
|
||||||
|
|
||||||
public class OpenPgpKeyAttributeUtil {
|
public final class OpenPgpKeyAttributeUtil {
|
||||||
|
|
||||||
|
private OpenPgpKeyAttributeUtil() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static List<HashAlgorithm> getPreferredHashAlgorithms(PGPPublicKey publicKey) {
|
public static List<HashAlgorithm> getPreferredHashAlgorithms(PGPPublicKey publicKey) {
|
||||||
List<HashAlgorithm> hashAlgorithms = new ArrayList<>();
|
List<HashAlgorithm> hashAlgorithms = new ArrayList<>();
|
||||||
|
|
|
@ -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
|
* 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.
|
* 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());
|
private static final Logger LOGGER = Logger.getLogger(SignatureChainValidator.class.getName());
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,11 @@ import org.pgpainless.util.CollectionUtils;
|
||||||
* [User Attribute [Signature ...] ...]
|
* [User Attribute [Signature ...] ...]
|
||||||
* [[Subkey [Binding-Signature-Revocation] Primary-Key-Binding-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.
|
* Pick the, at validation date most recent valid key revocation signature.
|
||||||
|
|
|
@ -52,7 +52,11 @@ import org.pgpainless.util.ArmorUtils;
|
||||||
/**
|
/**
|
||||||
* Utility methods related to signatures.
|
* Utility methods related to signatures.
|
||||||
*/
|
*/
|
||||||
public class SignatureUtils {
|
public final class SignatureUtils {
|
||||||
|
|
||||||
|
private SignatureUtils() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a signature generator for the provided signing key.
|
* Return a signature generator for the provided signing key.
|
||||||
|
|
|
@ -29,7 +29,11 @@ import org.pgpainless.algorithm.KeyFlag;
|
||||||
/**
|
/**
|
||||||
* Utility class that helps dealing with BCs SignatureSubpacketGenerator class.
|
* 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
|
* Return a list of {@link SignatureSubpacket SignatureSubpackets} from the subpacket generator, which correspond
|
||||||
|
|
|
@ -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),
|
* 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.
|
* 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.
|
* Return the issuer-fingerprint subpacket of the signature.
|
||||||
|
|
|
@ -39,7 +39,7 @@ import org.bouncycastle.util.io.Streams;
|
||||||
import org.pgpainless.algorithm.HashAlgorithm;
|
import org.pgpainless.algorithm.HashAlgorithm;
|
||||||
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
||||||
|
|
||||||
public class ArmorUtils {
|
public final class ArmorUtils {
|
||||||
|
|
||||||
// MessageIDs are 32 printable characters
|
// MessageIDs are 32 printable characters
|
||||||
private static final Pattern PATTERN_MESSAGE_ID = Pattern.compile("^\\S{32}$");
|
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_HASH = "Hash";
|
||||||
public static final String HEADER_CHARSET = "Charset";
|
public static final String HEADER_CHARSET = "Charset";
|
||||||
|
|
||||||
|
private ArmorUtils() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static String toAsciiArmoredString(PGPSecretKeyRing secretKeys) throws IOException {
|
public static String toAsciiArmoredString(PGPSecretKeyRing secretKeys) throws IOException {
|
||||||
MultiMap<String, String> header = keyToHeader(secretKeys);
|
MultiMap<String, String> header = keyToHeader(secretKeys);
|
||||||
return toAsciiArmoredString(secretKeys.getEncoded(), header);
|
return toAsciiArmoredString(secretKeys.getEncoded(), header);
|
||||||
|
|
|
@ -20,7 +20,11 @@ import java.io.InputStream;
|
||||||
|
|
||||||
import org.bouncycastle.bcpg.ArmoredInputStream;
|
import org.bouncycastle.bcpg.ArmoredInputStream;
|
||||||
|
|
||||||
public class ArmoredInputStreamFactory {
|
public final class ArmoredInputStreamFactory {
|
||||||
|
|
||||||
|
private ArmoredInputStreamFactory() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static ArmoredInputStream get(InputStream inputStream) throws IOException {
|
public static ArmoredInputStream get(InputStream inputStream) throws IOException {
|
||||||
if (inputStream instanceof CRCingArmoredInputStreamWrapper) {
|
if (inputStream instanceof CRCingArmoredInputStreamWrapper) {
|
||||||
|
|
|
@ -23,12 +23,16 @@ import org.bouncycastle.bcpg.ArmoredOutputStream;
|
||||||
* Factory to create configured {@link ArmoredOutputStream ArmoredOutputStreams}.
|
* Factory to create configured {@link ArmoredOutputStream ArmoredOutputStreams}.
|
||||||
* The configuration entails setting custom version and comment headers.
|
* The configuration entails setting custom version and comment headers.
|
||||||
*/
|
*/
|
||||||
public class ArmoredOutputStreamFactory {
|
public final class ArmoredOutputStreamFactory {
|
||||||
|
|
||||||
public static final String PGPAINLESS = "PGPainless";
|
public static final String PGPAINLESS = "PGPainless";
|
||||||
private static String VERSION = PGPAINLESS;
|
private static String VERSION = PGPAINLESS;
|
||||||
public static String[] COMMENT = new String[0];
|
public static String[] COMMENT = new String[0];
|
||||||
|
|
||||||
|
private ArmoredOutputStreamFactory() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrap an {@link OutputStream} inside a preconfigured {@link ArmoredOutputStream}.
|
* Wrap an {@link OutputStream} inside a preconfigured {@link ArmoredOutputStream}.
|
||||||
*
|
*
|
||||||
|
|
|
@ -19,7 +19,11 @@ import org.bouncycastle.asn1.ASN1ObjectIdentifier;
|
||||||
import org.bouncycastle.bcpg.ECPublicBCPGKey;
|
import org.bouncycastle.bcpg.ECPublicBCPGKey;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||||
|
|
||||||
public class BCUtil {
|
public final class BCUtil {
|
||||||
|
|
||||||
|
private BCUtil() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility method to get the bit strength of OpenPGP keys.
|
* Utility method to get the bit strength of OpenPGP keys.
|
||||||
|
|
|
@ -19,7 +19,11 @@ import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CollectionUtils {
|
public final class CollectionUtils {
|
||||||
|
|
||||||
|
private 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<>();
|
||||||
|
|
|
@ -20,8 +20,11 @@ import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.TimeZone;
|
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");
|
public static SimpleDateFormat UTC_PARSER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
|
||||||
static {
|
static {
|
||||||
UTC_PARSER.setTimeZone(TimeZone.getTimeZone("UTC"));
|
UTC_PARSER.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
|
|
@ -22,7 +22,11 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
import org.pgpainless.util.selection.keyring.PublicKeyRingSelectionStrategy;
|
import org.pgpainless.util.selection.keyring.PublicKeyRingSelectionStrategy;
|
||||||
import org.pgpainless.util.selection.keyring.SecretKeyRingSelectionStrategy;
|
import org.pgpainless.util.selection.keyring.SecretKeyRingSelectionStrategy;
|
||||||
|
|
||||||
public class ExactUserId {
|
public final class ExactUserId {
|
||||||
|
|
||||||
|
private ExactUserId() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static class PubRingSelectionStrategy extends PublicKeyRingSelectionStrategy<String> {
|
public static class PubRingSelectionStrategy extends PublicKeyRingSelectionStrategy<String> {
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,11 @@ import org.pgpainless.util.selection.keyring.PublicKeyRingSelectionStrategy;
|
||||||
import org.pgpainless.util.selection.keyring.SecretKeyRingSelectionStrategy;
|
import org.pgpainless.util.selection.keyring.SecretKeyRingSelectionStrategy;
|
||||||
import org.pgpainless.util.MultiMap;
|
import org.pgpainless.util.MultiMap;
|
||||||
|
|
||||||
public class Whitelist {
|
public final class Whitelist {
|
||||||
|
|
||||||
|
private Whitelist() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static class PubRingSelectionStrategy<O> extends PublicKeyRingSelectionStrategy<O> {
|
public static class PubRingSelectionStrategy<O> extends PublicKeyRingSelectionStrategy<O> {
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,11 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
import org.pgpainless.util.selection.keyring.PublicKeyRingSelectionStrategy;
|
import org.pgpainless.util.selection.keyring.PublicKeyRingSelectionStrategy;
|
||||||
import org.pgpainless.util.selection.keyring.SecretKeyRingSelectionStrategy;
|
import org.pgpainless.util.selection.keyring.SecretKeyRingSelectionStrategy;
|
||||||
|
|
||||||
public class Wildcard {
|
public final class Wildcard {
|
||||||
|
|
||||||
|
private Wildcard() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static class PubRingSelectionStrategy<O> extends PublicKeyRingSelectionStrategy<O> {
|
public static class PubRingSelectionStrategy<O> extends PublicKeyRingSelectionStrategy<O> {
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,11 @@ package org.pgpainless.util.selection.keyring.impl;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
|
|
||||||
public class XMPP {
|
public final class XMPP {
|
||||||
|
|
||||||
|
private XMPP() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static class PubRingSelectionStrategy extends ExactUserId.PubRingSelectionStrategy {
|
public static class PubRingSelectionStrategy extends ExactUserId.PubRingSelectionStrategy {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue