package F;

import I2.C0317a;
import J0.j1;
import android.content.Context;
import android.security.keystore.KeyGenParameterSpec;
import android.view.MotionEvent;
import androidx.compose.runtime.collection.MutableVector;
import androidx.media3.exoplayer.analytics.AnalyticsListener;
import java.net.ProtocolException;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.ProviderException;
import java.util.ArrayList;
import java.util.Arrays;
import javax.crypto.KeyGenerator;
import n.C2571F;
import s2.AbstractC2908c;

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

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int f1279b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public Object f1280c;

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

    public /* synthetic */ f0(int i6) {
        this.f1278a = i6;
    }

    public static f0 i(String str) throws ProtocolException {
        int i6;
        String strSubstring;
        boolean zStartsWith = str.startsWith("HTTP/1.");
        o4.m mVar = o4.m.HTTP_1_0;
        if (zStartsWith) {
            i6 = 9;
            if (str.length() < 9 || str.charAt(8) != ' ') {
                throw new ProtocolException("Unexpected status line: ".concat(str));
            }
            int iCharAt = str.charAt(7) - '0';
            if (iCharAt != 0) {
                if (iCharAt != 1) {
                    throw new ProtocolException("Unexpected status line: ".concat(str));
                }
                mVar = o4.m.HTTP_1_1;
            }
        } else {
            if (!str.startsWith("ICY ")) {
                throw new ProtocolException("Unexpected status line: ".concat(str));
            }
            i6 = 4;
        }
        int i7 = i6 + 3;
        if (str.length() < i7) {
            throw new ProtocolException("Unexpected status line: ".concat(str));
        }
        try {
            int i8 = Integer.parseInt(str.substring(i6, i7));
            if (str.length() <= i7) {
                strSubstring = "";
            } else {
                if (str.charAt(i7) != ' ') {
                    throw new ProtocolException("Unexpected status line: ".concat(str));
                }
                strSubstring = str.substring(i6 + 4);
            }
            return new f0(mVar, i8, strSubstring);
        } catch (NumberFormatException unused) {
            throw new ProtocolException("Unexpected status line: ".concat(str));
        }
    }

    public void a(int i6, r rVar) {
        if (i6 < 0) {
            A.b.a("size should be >=0");
        }
        if (i6 == 0) {
            return;
        }
        C0154h c0154h = new C0154h(this.f1279b, i6, rVar);
        this.f1279b += i6;
        ((MutableVector) this.f1280c).add(c0154h);
    }

    public C0317a b() {
        int i6 = this.f1279b;
        if (i6 == 0 && ((KeyGenParameterSpec) this.f1281d) == null) {
            throw new IllegalArgumentException("build() called before setKeyGenParameterSpec or setKeyScheme.");
        }
        if (i6 == 1) {
            this.f1281d = new KeyGenParameterSpec.Builder((String) this.f1280c, 3).setBlockModes("GCM").setEncryptionPaddings("NoPadding").setKeySize(256).build();
        }
        KeyGenParameterSpec keyGenParameterSpec = (KeyGenParameterSpec) this.f1281d;
        if (keyGenParameterSpec == null) {
            throw new NullPointerException("KeyGenParameterSpec was null after build() check");
        }
        Object obj = AbstractC2908c.f24197a;
        if (keyGenParameterSpec.getKeySize() != 256) {
            throw new IllegalArgumentException("invalid key size, want 256 bits got " + keyGenParameterSpec.getKeySize() + " bits");
        }
        if (!Arrays.equals(keyGenParameterSpec.getBlockModes(), new String[]{"GCM"})) {
            throw new IllegalArgumentException("invalid block mode, want GCM got " + Arrays.toString(keyGenParameterSpec.getBlockModes()));
        }
        if (keyGenParameterSpec.getPurposes() != 3) {
            throw new IllegalArgumentException("invalid purposes mode, want PURPOSE_ENCRYPT | PURPOSE_DECRYPT got " + keyGenParameterSpec.getPurposes());
        }
        if (!Arrays.equals(keyGenParameterSpec.getEncryptionPaddings(), new String[]{"NoPadding"})) {
            throw new IllegalArgumentException("invalid padding mode, want NoPadding got " + Arrays.toString(keyGenParameterSpec.getEncryptionPaddings()));
        }
        if (keyGenParameterSpec.isUserAuthenticationRequired() && keyGenParameterSpec.getUserAuthenticationValidityDurationSeconds() < 1) {
            throw new IllegalArgumentException("per-operation authentication is not supported (UserAuthenticationValidityDurationSeconds must be >0)");
        }
        synchronized (AbstractC2908c.f24197a) {
            String keystoreAlias = keyGenParameterSpec.getKeystoreAlias();
            KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
            keyStore.load(null);
            if (!keyStore.containsAlias(keystoreAlias)) {
                try {
                    KeyGenerator keyGenerator = KeyGenerator.getInstance("AES", "AndroidKeyStore");
                    keyGenerator.init(keyGenParameterSpec);
                    keyGenerator.generateKey();
                } catch (ProviderException e6) {
                    throw new GeneralSecurityException(e6.getMessage(), e6);
                }
            }
        }
        return new C0317a(keyGenParameterSpec.getKeystoreAlias(), (KeyGenParameterSpec) this.f1281d);
    }

    public C0154h c(int i6) {
        if (i6 < 0 || i6 >= this.f1279b) {
            StringBuilder sbR = com.google.android.recaptcha.internal.a.r(i6, "Index ", ", size ");
            sbR.append(this.f1279b);
            A.b.e(sbR.toString());
        }
        C0154h c0154h = (C0154h) this.f1281d;
        if (c0154h != null) {
            int i7 = c0154h.f1285a;
            if (i6 < c0154h.f1286b + i7 && i7 <= i6) {
                return c0154h;
            }
        }
        MutableVector mutableVector = (MutableVector) this.f1280c;
        C0154h c0154h2 = (C0154h) mutableVector.content[AbstractC0158l.h(i6, mutableVector)];
        this.f1281d = c0154h2;
        return c0154h2;
    }

    public int d(Object obj) {
        C2571F c2571f = (C2571F) this.f1280c;
        int iA = c2571f.a(obj);
        if (iA >= 0) {
            return c2571f.f21372c[iA];
        }
        return -1;
    }

    public Object e(int i6) {
        int i7 = i6 - this.f1279b;
        if (i7 < 0) {
            return null;
        }
        Object[] objArr = (Object[]) this.f1281d;
        if (i7 < objArr.length) {
            return objArr[i7];
        }
        return null;
    }

    public String f() {
        StringBuilder sb = new StringBuilder("$");
        int i6 = this.f1279b + 1;
        for (int i7 = 0; i7 < i6; i7++) {
            Object obj = ((Object[]) this.f1280c)[i7];
            if (obj instanceof i5.g) {
                i5.g gVar = (i5.g) obj;
                if (!kotlin.jvm.internal.o.c(gVar.e(), i5.k.f19101k)) {
                    int i8 = ((int[]) this.f1281d)[i7];
                    if (i8 >= 0) {
                        sb.append(".");
                        sb.append(gVar.g(i8));
                    }
                } else if (((int[]) this.f1281d)[i7] != -1) {
                    sb.append("[");
                    sb.append(((int[]) this.f1281d)[i7]);
                    sb.append("]");
                }
            } else if (obj != m5.m.f21255a) {
                sb.append("['");
                sb.append(obj);
                sb.append("']");
            }
        }
        String string = sb.toString();
        kotlin.jvm.internal.o.g(string, "toString(...)");
        return string;
    }

    public void g(int i6, int i7, int i8, int i9, int i10, int i11, boolean z6, boolean z7, boolean z8, int i12) {
        long[] jArr = (long[]) this.f1280c;
        int i13 = this.f1279b;
        int i14 = i13 + 3;
        this.f1279b = i14;
        int length = jArr.length;
        if (length <= i14) {
            int iMax = Math.max(length * 2, i14);
            long[] jArrCopyOf = Arrays.copyOf(jArr, iMax);
            kotlin.jvm.internal.o.g(jArrCopyOf, "copyOf(...)");
            this.f1280c = jArrCopyOf;
            long[] jArrCopyOf2 = Arrays.copyOf((long[]) this.f1281d, iMax);
            kotlin.jvm.internal.o.g(jArrCopyOf2, "copyOf(...)");
            this.f1281d = jArrCopyOf2;
        }
        long[] jArr2 = (long[]) this.f1280c;
        jArr2[i13] = (((long) i7) << 32) | (((long) i8) & 4294967295L);
        jArr2[i13 + 1] = (((long) i9) << 32) | (((long) i10) & 4294967295L);
        int i15 = i11 & 33554431;
        jArr2[i13 + 2] = ((z8 ? 1L : 0L) << 63) | ((z7 ? 1L : 0L) << 62) | ((z6 ? 1L : 0L) << 61) | (((long) 1) << 60) | (((long) Math.min(0, AnalyticsListener.EVENT_DRM_KEYS_LOADED)) << 50) | (((long) i15) << 25) | ((long) (i6 & 33554431));
        if (i11 < 0) {
            return;
        }
        for (int i16 = i12 != -1 ? i12 : i13 - 3; i16 >= 0; i16 -= 3) {
            int i17 = i16 + 2;
            long j4 = jArr2[i17];
            if ((((int) j4) & 33554431) == i15) {
                jArr2[i17] = (j4 & R0.a.f6002a) | (((long) Math.min((i13 - i16) / 3, AnalyticsListener.EVENT_DRM_KEYS_LOADED)) << 50);
                return;
            }
        }
    }

    public void j(int i6, boolean z6) {
        int i7 = i6 & 33554431;
        long[] jArr = (long[]) this.f1280c;
        int i8 = this.f1279b;
        for (int i9 = 0; i9 < jArr.length - 2 && i9 < i8; i9 += 3) {
            int i10 = i9 + 2;
            long j4 = jArr[i10];
            if ((((int) j4) & 33554431) == i7) {
                long j6 = z6 ? 1L : 0L;
                jArr[i10] = (j6 * Long.MIN_VALUE) | (8070450532247928831L & j4) | (1152921504606846976L * j6);
                return;
            }
        }
    }

    public void k(int i6, int i7, long j4) {
        int i8;
        char c6;
        char c7;
        long[] jArr = (long[]) this.f1280c;
        long[] jArr2 = (long[]) this.f1281d;
        jArr2[0] = j4;
        int i9 = 1;
        while (i9 > 0) {
            i9--;
            long j6 = jArr2[i9];
            int i10 = 33554431;
            int i11 = ((int) j6) & 33554431;
            char c8 = 25;
            int i12 = ((int) (j6 >> 25)) & 33554431;
            char c9 = '2';
            int i13 = ((int) (j6 >> 50)) & AnalyticsListener.EVENT_DRM_KEYS_LOADED;
            int i14 = i13 == 1023 ? this.f1279b : (i13 * 3) + i12;
            if (i12 < 0) {
                return;
            }
            while (i12 < jArr.length - 2 && i12 < i14) {
                int i15 = i12 + 2;
                long j7 = jArr[i15];
                if ((((int) (j7 >> c8)) & i10) == i11) {
                    long j8 = jArr[i12];
                    int i16 = i12 + 1;
                    i8 = i10;
                    c6 = c8;
                    long j9 = jArr[i16];
                    c7 = c9;
                    jArr[i12] = (((long) (((int) j8) + i7)) & 4294967295L) | (((long) (((int) (j8 >> 32)) + i6)) << 32);
                    jArr[i16] = (((long) (((int) j9) + i7)) & 4294967295L) | (((long) (((int) (j9 >> 32)) + i6)) << 32);
                    jArr[i15] = (((j7 >> 63) & 1) << 60) | j7;
                    if ((((int) (j7 >> c7)) & AnalyticsListener.EVENT_DRM_KEYS_LOADED) > 0) {
                        jArr2[i9] = (R0.a.f6003b & j7) | (((long) ((i12 + 3) & i8)) << c6);
                        i9++;
                    }
                } else {
                    i8 = i10;
                    c6 = c8;
                    c7 = c9;
                }
                i12 += 3;
                i10 = i8;
                c8 = c6;
                c9 = c7;
            }
        }
    }

    public void l(int i6, J4.g gVar) {
        int i7 = i6 & 33554431;
        long[] jArr = (long[]) this.f1280c;
        int i8 = this.f1279b;
        for (int i9 = 0; i9 < jArr.length - 2 && i9 < i8; i9 += 3) {
            if ((((int) jArr[i9 + 2]) & 33554431) == i7) {
                long j4 = jArr[i9];
                long j6 = jArr[i9 + 1];
                gVar.invoke(Integer.valueOf((int) (j4 >> 32)), Integer.valueOf((int) j4), Integer.valueOf((int) (j6 >> 32)), Integer.valueOf((int) j6));
                return;
            }
        }
    }

    public String toString() {
        switch (this.f1278a) {
            case 4:
                return f();
            case 5:
                StringBuilder sb = new StringBuilder();
                sb.append(((o4.m) this.f1280c) == o4.m.HTTP_1_0 ? "HTTP/1.0" : "HTTP/1.1");
                sb.append(' ');
                sb.append(this.f1279b);
                String str = (String) this.f1281d;
                if (str != null) {
                    sb.append(' ');
                    sb.append(str);
                }
                return sb.toString();
            case 6:
                StringBuilder sb2 = new StringBuilder();
                sb2.append((String) this.f1280c);
                sb2.append("://");
                int i6 = -1;
                if (((String) this.f1281d).indexOf(58) != -1) {
                    sb2.append('[');
                    sb2.append((String) this.f1281d);
                    sb2.append(']');
                } else {
                    sb2.append((String) this.f1281d);
                }
                int i7 = this.f1279b;
                if (i7 == -1) {
                    String str2 = (String) this.f1280c;
                    i7 = str2.equals("http") ? 80 : str2.equals("https") ? 443 : -1;
                }
                String str3 = (String) this.f1280c;
                if (str3.equals("http")) {
                    i6 = 80;
                } else if (str3.equals("https")) {
                    i6 = 443;
                }
                if (i7 != i6) {
                    sb2.append(':');
                    sb2.append(i7);
                }
                return sb2.toString();
            default:
                return super.toString();
        }
    }

    public f0(o4.m mVar, int i6, String str) {
        this.f1278a = 5;
        this.f1280c = mVar;
        this.f1279b = i6;
        this.f1281d = str;
    }

    public f0(ArrayList arrayList, int i6, MotionEvent motionEvent) {
        this.f1278a = 8;
        this.f1280c = arrayList;
        this.f1279b = i6;
        this.f1281d = motionEvent;
        if (arrayList.isEmpty()) {
            throw new IllegalArgumentException("changes cannot be empty");
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:30:0x00d1  */
    /* JADX WARN: Removed duplicated region for block: B:33:0x00e5 A[LOOP:1: B:27:0x00c3->B:33:0x00e5, LOOP_END] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public f0(P4.g gVar, AbstractC0158l abstractC0158l) {
        Object c0152f;
        this.f1278a = 1;
        f0 f0VarN = abstractC0158l.n();
        int i6 = gVar.f5676a;
        if (i6 < 0) {
            A.b.c("negative nearestRange.first");
        }
        int iMin = Math.min(gVar.f5677b, f0VarN.f1279b - 1);
        if (iMin < i6) {
            C2571F c2571f = n.T.f21375a;
            kotlin.jvm.internal.o.f(c2571f, "null cannot be cast to non-null type androidx.collection.ObjectIntMap<K of androidx.collection.ObjectIntMapKt.emptyObjectIntMap>");
            this.f1280c = c2571f;
            this.f1281d = new Object[0];
            this.f1279b = 0;
            return;
        }
        int i7 = (iMin - i6) + 1;
        this.f1281d = new Object[i7];
        this.f1279b = i6;
        C2571F c2571f2 = new C2571F(i7);
        if (i6 < 0 || i6 >= f0VarN.f1279b) {
            StringBuilder sbR = com.google.android.recaptcha.internal.a.r(i6, "Index ", ", size ");
            sbR.append(f0VarN.f1279b);
            A.b.e(sbR.toString());
        }
        if (iMin < 0 || iMin >= f0VarN.f1279b) {
            StringBuilder sbR2 = com.google.android.recaptcha.internal.a.r(iMin, "Index ", ", size ");
            sbR2.append(f0VarN.f1279b);
            A.b.e(sbR2.toString());
        }
        if (iMin < i6) {
            A.b.a("toIndex (" + iMin + ") should be not smaller than fromIndex (" + i6 + ')');
        }
        MutableVector mutableVector = (MutableVector) f0VarN.f1280c;
        int iH = AbstractC0158l.h(i6, mutableVector);
        int i8 = ((C0154h) mutableVector.content[iH]).f1285a;
        while (i8 <= iMin) {
            C0154h c0154h = (C0154h) mutableVector.content[iH];
            J4.c key = c0154h.f1287c.getKey();
            int i9 = c0154h.f1285a;
            int iMax = Math.max(i6, i9);
            int iMin2 = Math.min(iMin, (c0154h.f1286b + i9) - 1);
            if (iMax <= iMin2) {
                while (true) {
                    if (key != null) {
                        c0152f = key.invoke(Integer.valueOf(iMax - i9));
                        if (c0152f == null) {
                        }
                        c2571f2.g(iMax, c0152f);
                        ((Object[]) this.f1281d)[iMax - this.f1279b] = c0152f;
                        if (iMax == iMin2) {
                            break;
                        }
                    } else {
                        c0152f = new C0152f(iMax);
                        c2571f2.g(iMax, c0152f);
                        ((Object[]) this.f1281d)[iMax - this.f1279b] = c0152f;
                        iMax = iMax == iMin2 ? iMax + 1 : iMax;
                    }
                }
            }
            i8 += c0154h.f1286b;
            iH++;
        }
        this.f1280c = c2571f2;
    }

    public f0() {
        this.f1278a = 0;
        this.f1280c = new MutableVector(new C0154h[16], 0);
    }

    public f0(Context context) {
        this.f1278a = 7;
        context.getApplicationContext();
        this.f1280c = "_androidx_security_master_key_";
    }

    public f0(j1 j1Var) {
        this.f1278a = 3;
        this.f1280c = j1Var;
    }
}
