package Y3;

import com.google.android.gms.security.ProviderInstaller;
import java.security.GeneralSecurityException;
import java.security.Provider;
import java.security.Security;
import java.util.ArrayList;
import java.util.Iterator;

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

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final u4.c f8837b;

    public /* synthetic */ n(u4.c cVar, int i6) {
        this.f8836a = i6;
        this.f8837b = cVar;
    }

    public final Object a(String str) throws GeneralSecurityException {
        switch (this.f8836a) {
            case 0:
                String[] strArr = {ProviderInstaller.PROVIDER_NAME, "AndroidOpenSSL"};
                ArrayList arrayList = new ArrayList();
                for (int i6 = 0; i6 < 2; i6++) {
                    Provider provider = Security.getProvider(strArr[i6]);
                    if (provider != null) {
                        arrayList.add(provider);
                    }
                }
                Iterator it = arrayList.iterator();
                Exception exc = null;
                while (true) {
                    boolean zHasNext = it.hasNext();
                    u4.c cVar = this.f8837b;
                    if (!zHasNext) {
                        return cVar.d(str, null);
                    }
                    try {
                        return cVar.d(str, (Provider) it.next());
                    } catch (Exception e6) {
                        if (exc == null) {
                            exc = e6;
                        }
                    }
                }
                break;
            case 1:
                return this.f8837b.d(str, null);
            default:
                String[] strArr2 = {ProviderInstaller.PROVIDER_NAME, "AndroidOpenSSL", "Conscrypt"};
                ArrayList arrayList2 = new ArrayList();
                for (int i7 = 0; i7 < 3; i7++) {
                    Provider provider2 = Security.getProvider(strArr2[i7]);
                    if (provider2 != null) {
                        arrayList2.add(provider2);
                    }
                }
                Iterator it2 = arrayList2.iterator();
                Exception exc2 = null;
                while (it2.hasNext()) {
                    try {
                        return this.f8837b.d(str, (Provider) it2.next());
                    } catch (Exception e7) {
                        if (exc2 == null) {
                            exc2 = e7;
                        }
                    }
                }
                throw new GeneralSecurityException("No good Provider found.", exc2);
        }
    }
}
