package U3;

import java.security.GeneralSecurityException;
import java.security.Provider;
import java.security.Security;
import java.util.ArrayList;
import n4.u0;

/* JADX INFO: loaded from: classes.dex */
public final class h {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f6711a;

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

    public /* synthetic */ h(j jVar, int i) {
        this.f6711a = i;
        this.f6712b = jVar;
    }

    public final Object a(String str) throws GeneralSecurityException {
        switch (this.f6711a) {
            case u0.f15495q /* 0 */:
                String[] strArr = {"GmsCore_OpenSSL", "AndroidOpenSSL"};
                ArrayList arrayList = new ArrayList();
                int i = 0;
                for (int i5 = 0; i5 < 2; i5++) {
                    Provider provider = Security.getProvider(strArr[i5]);
                    if (provider != null) {
                        arrayList.add(provider);
                    }
                }
                int size = arrayList.size();
                Exception exc = null;
                while (true) {
                    j jVar = this.f6712b;
                    if (i >= size) {
                        return jVar.g(str, null);
                    }
                    Object obj = arrayList.get(i);
                    i++;
                    try {
                        return jVar.g(str, (Provider) obj);
                    } catch (Exception e8) {
                        if (exc == null) {
                            exc = e8;
                        }
                    }
                }
                break;
            case 1:
                return this.f6712b.g(str, null);
            default:
                String[] strArr2 = {"GmsCore_OpenSSL", "AndroidOpenSSL", "Conscrypt"};
                ArrayList arrayList2 = new ArrayList();
                int i8 = 0;
                for (int i9 = 0; i9 < 3; i9++) {
                    Provider provider2 = Security.getProvider(strArr2[i9]);
                    if (provider2 != null) {
                        arrayList2.add(provider2);
                    }
                }
                int size2 = arrayList2.size();
                Exception exc2 = null;
                while (i8 < size2) {
                    Object obj2 = arrayList2.get(i8);
                    i8++;
                    try {
                        return this.f6712b.g(str, (Provider) obj2);
                    } catch (Exception e9) {
                        if (exc2 == null) {
                            exc2 = e9;
                        }
                    }
                }
                throw new GeneralSecurityException("No good Provider found.", exc2);
        }
    }
}
