package okhttp3;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import javax.net.ssl.SSLSocket;
import kotlin.jvm.internal.o;
import okhttp3.TlsVersion;
import okhttp3.internal.Util;
import q.AbstractC2761L;
import x4.AbstractC3251q;
import z4.C3296a;

/* JADX INFO: loaded from: classes3.dex */
public final class ConnectionSpec {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final ConnectionSpec f21976e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final ConnectionSpec f21977f;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final boolean f21978a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final boolean f21979b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final String[] f21980c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final String[] f21981d;

    public static final class Builder {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public boolean f21982a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public String[] f21983b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public String[] f21984c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        public boolean f21985d;

        public Builder(boolean z6) {
            this.f21982a = z6;
        }

        public final ConnectionSpec a() {
            return new ConnectionSpec(this.f21982a, this.f21985d, this.f21983b, this.f21984c);
        }

        public final void b(String... cipherSuites) {
            o.h(cipherSuites, "cipherSuites");
            if (!this.f21982a) {
                throw new IllegalArgumentException("no cipher suites for cleartext connections");
            }
            if (cipherSuites.length == 0) {
                throw new IllegalArgumentException("At least one cipher suite is required");
            }
            this.f21983b = (String[]) cipherSuites.clone();
        }

        public final void c(CipherSuite... cipherSuites) {
            o.h(cipherSuites, "cipherSuites");
            if (!this.f21982a) {
                throw new IllegalArgumentException("no cipher suites for cleartext connections");
            }
            ArrayList arrayList = new ArrayList(cipherSuites.length);
            for (CipherSuite cipherSuite : cipherSuites) {
                arrayList.add(cipherSuite.f21974a);
            }
            String[] strArr = (String[]) arrayList.toArray(new String[0]);
            b((String[]) Arrays.copyOf(strArr, strArr.length));
        }

        public final void d(String... tlsVersions) {
            o.h(tlsVersions, "tlsVersions");
            if (!this.f21982a) {
                throw new IllegalArgumentException("no TLS versions for cleartext connections");
            }
            if (tlsVersions.length == 0) {
                throw new IllegalArgumentException("At least one TLS version is required");
            }
            this.f21984c = (String[]) tlsVersions.clone();
        }

        public final void e(TlsVersion... tlsVersionArr) {
            if (!this.f21982a) {
                throw new IllegalArgumentException("no TLS versions for cleartext connections");
            }
            ArrayList arrayList = new ArrayList(tlsVersionArr.length);
            for (TlsVersion tlsVersion : tlsVersionArr) {
                arrayList.add(tlsVersion.f22178a);
            }
            String[] strArr = (String[]) arrayList.toArray(new String[0]);
            d((String[]) Arrays.copyOf(strArr, strArr.length));
        }
    }

    public static final class Companion {
        public /* synthetic */ Companion(int i6) {
            this();
        }

        private Companion() {
        }
    }

    static {
        new Companion(0);
        CipherSuite cipherSuite = CipherSuite.f21971r;
        CipherSuite cipherSuite2 = CipherSuite.f21972s;
        CipherSuite cipherSuite3 = CipherSuite.f21973t;
        CipherSuite cipherSuite4 = CipherSuite.l;
        CipherSuite cipherSuite5 = CipherSuite.f21967n;
        CipherSuite cipherSuite6 = CipherSuite.f21966m;
        CipherSuite cipherSuite7 = CipherSuite.f21968o;
        CipherSuite cipherSuite8 = CipherSuite.f21970q;
        CipherSuite cipherSuite9 = CipherSuite.f21969p;
        CipherSuite[] cipherSuiteArr = {cipherSuite, cipherSuite2, cipherSuite3, cipherSuite4, cipherSuite5, cipherSuite6, cipherSuite7, cipherSuite8, cipherSuite9};
        CipherSuite[] cipherSuiteArr2 = {cipherSuite, cipherSuite2, cipherSuite3, cipherSuite4, cipherSuite5, cipherSuite6, cipherSuite7, cipherSuite8, cipherSuite9, CipherSuite.f21964j, CipherSuite.f21965k, CipherSuite.f21962h, CipherSuite.f21963i, CipherSuite.f21960f, CipherSuite.f21961g, CipherSuite.f21959e};
        Builder builder = new Builder(true);
        builder.c((CipherSuite[]) Arrays.copyOf(cipherSuiteArr, 9));
        TlsVersion tlsVersion = TlsVersion.TLS_1_3;
        TlsVersion tlsVersion2 = TlsVersion.TLS_1_2;
        builder.e(tlsVersion, tlsVersion2);
        if (!builder.f21982a) {
            throw new IllegalArgumentException("no TLS extensions for cleartext connections");
        }
        builder.f21985d = true;
        builder.a();
        Builder builder2 = new Builder(true);
        builder2.c((CipherSuite[]) Arrays.copyOf(cipherSuiteArr2, 16));
        builder2.e(tlsVersion, tlsVersion2);
        if (!builder2.f21982a) {
            throw new IllegalArgumentException("no TLS extensions for cleartext connections");
        }
        builder2.f21985d = true;
        f21976e = builder2.a();
        Builder builder3 = new Builder(true);
        builder3.c((CipherSuite[]) Arrays.copyOf(cipherSuiteArr2, 16));
        builder3.e(tlsVersion, tlsVersion2, TlsVersion.TLS_1_1, TlsVersion.TLS_1_0);
        if (!builder3.f21982a) {
            throw new IllegalArgumentException("no TLS extensions for cleartext connections");
        }
        builder3.f21985d = true;
        builder3.a();
        f21977f = new Builder(false).a();
    }

    public ConnectionSpec(boolean z6, boolean z7, String[] strArr, String[] strArr2) {
        this.f21978a = z6;
        this.f21979b = z7;
        this.f21980c = strArr;
        this.f21981d = strArr2;
    }

    public final List a() {
        String[] strArr = this.f21980c;
        if (strArr == null) {
            return null;
        }
        ArrayList arrayList = new ArrayList(strArr.length);
        for (String str : strArr) {
            arrayList.add(CipherSuite.f21956b.b(str));
        }
        return AbstractC3251q.C0(arrayList);
    }

    public final boolean b(SSLSocket sSLSocket) {
        if (!this.f21978a) {
            return false;
        }
        String[] strArr = this.f21981d;
        if (strArr != null && !Util.i(strArr, sSLSocket.getEnabledProtocols(), C3296a.f26322b)) {
            return false;
        }
        String[] strArr2 = this.f21980c;
        if (strArr2 == null) {
            return true;
        }
        String[] enabledCipherSuites = sSLSocket.getEnabledCipherSuites();
        CipherSuite.f21956b.getClass();
        return Util.i(strArr2, enabledCipherSuites, CipherSuite.f21957c);
    }

    public final List c() {
        String[] strArr = this.f21981d;
        if (strArr == null) {
            return null;
        }
        ArrayList arrayList = new ArrayList(strArr.length);
        for (String str : strArr) {
            TlsVersion.f22171b.getClass();
            arrayList.add(TlsVersion.Companion.a(str));
        }
        return AbstractC3251q.C0(arrayList);
    }

    public final boolean equals(Object obj) {
        if (!(obj instanceof ConnectionSpec)) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        ConnectionSpec connectionSpec = (ConnectionSpec) obj;
        boolean z6 = connectionSpec.f21978a;
        boolean z7 = this.f21978a;
        if (z7 != z6) {
            return false;
        }
        if (z7) {
            return Arrays.equals(this.f21980c, connectionSpec.f21980c) && Arrays.equals(this.f21981d, connectionSpec.f21981d) && this.f21979b == connectionSpec.f21979b;
        }
        return true;
    }

    public final int hashCode() {
        if (!this.f21978a) {
            return 17;
        }
        String[] strArr = this.f21980c;
        int iHashCode = (527 + (strArr != null ? Arrays.hashCode(strArr) : 0)) * 31;
        String[] strArr2 = this.f21981d;
        return ((iHashCode + (strArr2 != null ? Arrays.hashCode(strArr2) : 0)) * 31) + (!this.f21979b ? 1 : 0);
    }

    public final String toString() {
        if (!this.f21978a) {
            return "ConnectionSpec()";
        }
        StringBuilder sb = new StringBuilder("ConnectionSpec(cipherSuites=");
        sb.append(Objects.toString(a(), "[all enabled]"));
        sb.append(", tlsVersions=");
        sb.append(Objects.toString(c(), "[all enabled]"));
        sb.append(", supportsTlsExtensions=");
        return AbstractC2761L.h(sb, this.f21979b, ')');
    }
}
