package uq;

import ca.canadapost.core.data.model.CoreConstants;
import java.io.IOException;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;

/* loaded from: classes3.dex */
public final class t {

    /* renamed from: e, reason: collision with root package name */
    public static final a f37589e = new a(null);

    /* renamed from: a, reason: collision with root package name */
    private final g0 f37590a;

    /* renamed from: b, reason: collision with root package name */
    private final i f37591b;

    /* renamed from: c, reason: collision with root package name */
    private final List f37592c;

    /* renamed from: d, reason: collision with root package name */
    private final rm.o f37593d;

    /* loaded from: classes3.dex */
    public static final class a {

        /* renamed from: uq.t$a$a, reason: collision with other inner class name */
        /* loaded from: classes3.dex */
        static final class C0904a extends kotlin.jvm.internal.v implements dn.a {

            /* renamed from: p, reason: collision with root package name */
            final /* synthetic */ List f37594p;

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            C0904a(List list) {
                super(0);
                this.f37594p = list;
            }

            @Override // dn.a
            /* renamed from: a, reason: merged with bridge method [inline-methods] */
            public final List invoke() {
                return this.f37594p;
            }
        }

        private a() {
        }

        public /* synthetic */ a(kotlin.jvm.internal.k kVar) {
            this();
        }

        private final List b(Certificate[] certificateArr) {
            List k10;
            if (certificateArr != null) {
                return vq.p.k(Arrays.copyOf(certificateArr, certificateArr.length));
            }
            k10 = sm.u.k();
            return k10;
        }

        public final t a(SSLSession sSLSession) {
            List k10;
            kotlin.jvm.internal.t.g(sSLSession, "<this>");
            String cipherSuite = sSLSession.getCipherSuite();
            if (cipherSuite == null) {
                throw new IllegalStateException("cipherSuite == null".toString());
            }
            if (kotlin.jvm.internal.t.b(cipherSuite, "TLS_NULL_WITH_NULL_NULL") ? true : kotlin.jvm.internal.t.b(cipherSuite, "SSL_NULL_WITH_NULL_NULL")) {
                throw new IOException("cipherSuite == " + cipherSuite);
            }
            i b10 = i.f37469b.b(cipherSuite);
            String protocol = sSLSession.getProtocol();
            if (protocol == null) {
                throw new IllegalStateException("tlsVersion == null".toString());
            }
            if (kotlin.jvm.internal.t.b(CoreConstants.VERIFICATION_METHOD_NONE, protocol)) {
                throw new IOException("tlsVersion == NONE");
            }
            g0 a10 = g0.Companion.a(protocol);
            try {
                k10 = b(sSLSession.getPeerCertificates());
            } catch (SSLPeerUnverifiedException unused) {
                k10 = sm.u.k();
            }
            return new t(a10, b10, b(sSLSession.getLocalCertificates()), new C0904a(k10));
        }
    }

    /* loaded from: classes3.dex */
    static final class b extends kotlin.jvm.internal.v implements dn.a {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ dn.a f37595p;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        b(dn.a aVar) {
            super(0);
            this.f37595p = aVar;
        }

        @Override // dn.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final List invoke() {
            List k10;
            try {
                return (List) this.f37595p.invoke();
            } catch (SSLPeerUnverifiedException unused) {
                k10 = sm.u.k();
                return k10;
            }
        }
    }

    public t(g0 tlsVersion, i cipherSuite, List localCertificates, dn.a peerCertificatesFn) {
        rm.o a10;
        kotlin.jvm.internal.t.g(tlsVersion, "tlsVersion");
        kotlin.jvm.internal.t.g(cipherSuite, "cipherSuite");
        kotlin.jvm.internal.t.g(localCertificates, "localCertificates");
        kotlin.jvm.internal.t.g(peerCertificatesFn, "peerCertificatesFn");
        this.f37590a = tlsVersion;
        this.f37591b = cipherSuite;
        this.f37592c = localCertificates;
        a10 = rm.q.a(new b(peerCertificatesFn));
        this.f37593d = a10;
    }

    private final String b(Certificate certificate) {
        if (certificate instanceof X509Certificate) {
            return ((X509Certificate) certificate).getSubjectDN().toString();
        }
        String type = certificate.getType();
        kotlin.jvm.internal.t.f(type, "type");
        return type;
    }

    public final i a() {
        return this.f37591b;
    }

    public final List c() {
        return this.f37592c;
    }

    public final List d() {
        return (List) this.f37593d.getValue();
    }

    public final g0 e() {
        return this.f37590a;
    }

    public boolean equals(Object obj) {
        if (obj instanceof t) {
            t tVar = (t) obj;
            if (tVar.f37590a == this.f37590a && kotlin.jvm.internal.t.b(tVar.f37591b, this.f37591b) && kotlin.jvm.internal.t.b(tVar.d(), d()) && kotlin.jvm.internal.t.b(tVar.f37592c, this.f37592c)) {
                return true;
            }
        }
        return false;
    }

    public int hashCode() {
        return ((((((527 + this.f37590a.hashCode()) * 31) + this.f37591b.hashCode()) * 31) + d().hashCode()) * 31) + this.f37592c.hashCode();
    }

    public String toString() {
        int v10;
        int v11;
        List d10 = d();
        v10 = sm.v.v(d10, 10);
        ArrayList arrayList = new ArrayList(v10);
        Iterator it = d10.iterator();
        while (it.hasNext()) {
            arrayList.add(b((Certificate) it.next()));
        }
        String obj = arrayList.toString();
        StringBuilder sb2 = new StringBuilder();
        sb2.append("Handshake{tlsVersion=");
        sb2.append(this.f37590a);
        sb2.append(" cipherSuite=");
        sb2.append(this.f37591b);
        sb2.append(" peerCertificates=");
        sb2.append(obj);
        sb2.append(" localCertificates=");
        List list = this.f37592c;
        v11 = sm.v.v(list, 10);
        ArrayList arrayList2 = new ArrayList(v11);
        Iterator it2 = list.iterator();
        while (it2.hasNext()) {
            arrayList2.add(b((Certificate) it2.next()));
        }
        sb2.append(arrayList2);
        sb2.append('}');
        return sb2.toString();
    }
}
