From 145b4c161ced40d315f4c7c1dc902e28bb2433c0 Mon Sep 17 00:00:00 2001 From: Hakky54 Date: Thu, 7 Nov 2024 18:56:55 +0100 Subject: [PATCH] Refactored to use more unmodifiable lists --- .../src/main/java/nl/altindag/ssl/pem/util/PemType.java | 5 +++-- .../java/nl/altindag/ssl/model/internal/SSLMaterial.java | 7 ++++--- .../java/nl/altindag/ssl/util/MacCertificateUtils.java | 4 ++-- .../nl/altindag/ssl/util/internal/CollectionUtils.java | 7 +++++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/sslcontext-kickstart-for-pem/src/main/java/nl/altindag/ssl/pem/util/PemType.java b/sslcontext-kickstart-for-pem/src/main/java/nl/altindag/ssl/pem/util/PemType.java index a94fa3e0..62584a22 100644 --- a/sslcontext-kickstart-for-pem/src/main/java/nl/altindag/ssl/pem/util/PemType.java +++ b/sslcontext-kickstart-for-pem/src/main/java/nl/altindag/ssl/pem/util/PemType.java @@ -23,9 +23,10 @@ import org.bouncycastle.openssl.X509TrustedCertificateBlock; import org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfo; -import java.util.Arrays; import java.util.List; +import static nl.altindag.ssl.util.internal.CollectionUtils.toUnmodifiableList; + enum PemType { CERTIFICATE(X509CertificateHolder.class, X509TrustedCertificateBlock.class), @@ -34,7 +35,7 @@ enum PemType { private final List> supportedTypes; PemType(Class... classes) { - this.supportedTypes = Arrays.asList(classes); + this.supportedTypes = toUnmodifiableList(classes); } static PemType from(Object object) { diff --git a/sslcontext-kickstart/src/main/java/nl/altindag/ssl/model/internal/SSLMaterial.java b/sslcontext-kickstart/src/main/java/nl/altindag/ssl/model/internal/SSLMaterial.java index 9fd99b32..a3141733 100644 --- a/sslcontext-kickstart/src/main/java/nl/altindag/ssl/model/internal/SSLMaterial.java +++ b/sslcontext-kickstart/src/main/java/nl/altindag/ssl/model/internal/SSLMaterial.java @@ -20,9 +20,10 @@ import javax.net.ssl.SSLParameters; import javax.net.ssl.X509ExtendedKeyManager; import javax.net.ssl.X509ExtendedTrustManager; -import java.util.Arrays; import java.util.List; +import static nl.altindag.ssl.util.internal.CollectionUtils.toUnmodifiableList; + /** *

* NOTE: @@ -62,11 +63,11 @@ public HostnameVerifier getHostnameVerifier() { } public List getCiphers() { - return Arrays.asList(sslParameters.getCipherSuites()); + return toUnmodifiableList(sslParameters.getCipherSuites()); } public List getProtocols() { - return Arrays.asList(sslParameters.getProtocols()); + return toUnmodifiableList(sslParameters.getProtocols()); } public static class Builder { diff --git a/sslcontext-kickstart/src/main/java/nl/altindag/ssl/util/MacCertificateUtils.java b/sslcontext-kickstart/src/main/java/nl/altindag/ssl/util/MacCertificateUtils.java index faeda014..e7e9279c 100644 --- a/sslcontext-kickstart/src/main/java/nl/altindag/ssl/util/MacCertificateUtils.java +++ b/sslcontext-kickstart/src/main/java/nl/altindag/ssl/util/MacCertificateUtils.java @@ -21,13 +21,13 @@ import java.io.IOException; import java.security.cert.Certificate; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; import static nl.altindag.ssl.util.OperatingSystem.MAC; +import static nl.altindag.ssl.util.internal.CollectionUtils.toUnmodifiableList; /** * @author Hakan Altindag @@ -36,7 +36,7 @@ final class MacCertificateUtils { private static final String SECURITY_EXECUTABLE = "security"; private static final String SYSTEM_ROOT_KEYCHAIN_FILE = "/System/Library/Keychains/SystemRootCertificates.keychain"; - private static final List KEYCHAIN_LOOKUP_COMMANDS = Arrays.asList("list-keychains", "default-keychain"); + private static final List KEYCHAIN_LOOKUP_COMMANDS = toUnmodifiableList("list-keychains", "default-keychain"); private static final String EMPTY = ""; private static final String SPACE = " "; diff --git a/sslcontext-kickstart/src/main/java/nl/altindag/ssl/util/internal/CollectionUtils.java b/sslcontext-kickstart/src/main/java/nl/altindag/ssl/util/internal/CollectionUtils.java index 7b6550e3..79c326e6 100644 --- a/sslcontext-kickstart/src/main/java/nl/altindag/ssl/util/internal/CollectionUtils.java +++ b/sslcontext-kickstart/src/main/java/nl/altindag/ssl/util/internal/CollectionUtils.java @@ -15,6 +15,8 @@ */ package nl.altindag.ssl.util.internal; +import java.util.Arrays; +import java.util.Collections; import java.util.List; /** @@ -32,4 +34,9 @@ public static boolean isEmpty(List collection) { return collection == null || collection.isEmpty(); } + @SafeVarargs + public static List toUnmodifiableList(T... values) { + return Collections.unmodifiableList(Arrays.asList(values)); + } + }