Skip to content

Commit

Permalink
Refactored to use more unmodifiable lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Hakky54 committed Nov 7, 2024
1 parent e5ba3cf commit 145b4c1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -34,7 +35,7 @@ enum PemType {
private final List<Class<?>> supportedTypes;

PemType(Class<?>... classes) {
this.supportedTypes = Arrays.asList(classes);
this.supportedTypes = toUnmodifiableList(classes);
}

static PemType from(Object object) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* <p>
* <strong>NOTE:</strong>
Expand Down Expand Up @@ -62,11 +63,11 @@ public HostnameVerifier getHostnameVerifier() {
}

public List<String> getCiphers() {
return Arrays.asList(sslParameters.getCipherSuites());
return toUnmodifiableList(sslParameters.getCipherSuites());
}

public List<String> getProtocols() {
return Arrays.asList(sslParameters.getProtocols());
return toUnmodifiableList(sslParameters.getProtocols());
}

public static class Builder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String> KEYCHAIN_LOOKUP_COMMANDS = Arrays.asList("list-keychains", "default-keychain");
private static final List<String> KEYCHAIN_LOOKUP_COMMANDS = toUnmodifiableList("list-keychains", "default-keychain");

private static final String EMPTY = "";
private static final String SPACE = " ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package nl.altindag.ssl.util.internal;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
Expand All @@ -32,4 +34,9 @@ public static boolean isEmpty(List<?> collection) {
return collection == null || collection.isEmpty();
}

@SafeVarargs
public static <T> List<T> toUnmodifiableList(T... values) {
return Collections.unmodifiableList(Arrays.asList(values));
}

}

0 comments on commit 145b4c1

Please sign in to comment.