package g2;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/* JADX INFO: compiled from: ASN1ObjectIdentifier.java */
/* JADX INFO: loaded from: classes.dex */
public class n extends s {

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private static final ConcurrentMap<a, n> f4723g = new ConcurrentHashMap();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private final String f4724e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private byte[] f4725f;

    /* JADX INFO: compiled from: ASN1ObjectIdentifier.java */
    private static class a {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private final int f4726a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        private final byte[] f4727b;

        a(byte[] bArr) {
            this.f4726a = i2.a.d(bArr);
            this.f4727b = bArr;
        }

        public boolean equals(Object obj) {
            if (obj instanceof a) {
                return i2.a.a(this.f4727b, ((a) obj).f4727b);
            }
            return false;
        }

        public int hashCode() {
            return this.f4726a;
        }
    }

    n(byte[] bArr) {
        StringBuffer stringBuffer = new StringBuffer();
        boolean z2 = true;
        long j3 = 0;
        BigInteger bigIntegerShiftLeft = null;
        for (int i3 = 0; i3 != bArr.length; i3++) {
            int i4 = bArr[i3] & 255;
            if (j3 <= 72057594037927808L) {
                long j4 = j3 + ((long) (i4 & 127));
                if ((i4 & 128) == 0) {
                    if (z2) {
                        if (j4 < 40) {
                            stringBuffer.append('0');
                        } else if (j4 < 80) {
                            stringBuffer.append('1');
                            j4 -= 40;
                        } else {
                            stringBuffer.append('2');
                            j4 -= 80;
                        }
                        z2 = false;
                    }
                    stringBuffer.append('.');
                    stringBuffer.append(j4);
                    j3 = 0;
                } else {
                    j3 = j4 << 7;
                }
            } else {
                BigInteger bigIntegerOr = (bigIntegerShiftLeft == null ? BigInteger.valueOf(j3) : bigIntegerShiftLeft).or(BigInteger.valueOf(i4 & 127));
                if ((i4 & 128) == 0) {
                    if (z2) {
                        stringBuffer.append('2');
                        bigIntegerOr = bigIntegerOr.subtract(BigInteger.valueOf(80L));
                        z2 = false;
                    }
                    stringBuffer.append('.');
                    stringBuffer.append(bigIntegerOr);
                    j3 = 0;
                    bigIntegerShiftLeft = null;
                } else {
                    bigIntegerShiftLeft = bigIntegerOr.shiftLeft(7);
                }
            }
        }
        this.f4724e = stringBuffer.toString().intern();
        this.f4725f = i2.a.c(bArr);
    }

    private void p(ByteArrayOutputStream byteArrayOutputStream) {
        x1 x1Var = new x1(this.f4724e);
        int i3 = Integer.parseInt(x1Var.b()) * 40;
        String strB = x1Var.b();
        if (strB.length() <= 18) {
            v(byteArrayOutputStream, ((long) i3) + Long.parseLong(strB));
        } else {
            w(byteArrayOutputStream, new BigInteger(strB).add(BigInteger.valueOf(i3)));
        }
        while (x1Var.a()) {
            String strB2 = x1Var.b();
            if (strB2.length() <= 18) {
                v(byteArrayOutputStream, Long.parseLong(strB2));
            } else {
                w(byteArrayOutputStream, new BigInteger(strB2));
            }
        }
    }

    static n q(byte[] bArr) {
        n nVar = f4723g.get(new a(bArr));
        return nVar == null ? new n(bArr) : nVar;
    }

    private synchronized byte[] r() {
        if (this.f4725f == null) {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            p(byteArrayOutputStream);
            this.f4725f = byteArrayOutputStream.toByteArray();
        }
        return this.f4725f;
    }

    /* JADX WARN: Code restructure failed: missing block: B:11:0x001f, code lost:
    
        if (r7.charAt(r0 + 1) != '0') goto L33;
     */
    /* JADX WARN: Code restructure failed: missing block: B:12:0x0021, code lost:
    
        return false;
     */
    /* JADX WARN: Code restructure failed: missing block: B:8:0x0015, code lost:
    
        if (r2 == 0) goto L26;
     */
    /* JADX WARN: Code restructure failed: missing block: B:9:0x0017, code lost:
    
        if (r2 <= 1) goto L32;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private static boolean t(java.lang.String r7, int r8) {
        /*
            int r0 = r7.length()
            r1 = 0
        L5:
            r2 = r1
        L6:
            int r0 = r0 + (-1)
            r3 = 48
            r4 = 1
            if (r0 < r8) goto L2c
            char r5 = r7.charAt(r0)
            r6 = 46
            if (r5 != r6) goto L22
            if (r2 == 0) goto L21
            if (r2 <= r4) goto L5
            int r2 = r0 + 1
            char r2 = r7.charAt(r2)
            if (r2 != r3) goto L5
        L21:
            return r1
        L22:
            if (r3 > r5) goto L2b
            r3 = 57
            if (r5 > r3) goto L2b
            int r2 = r2 + 1
            goto L6
        L2b:
            return r1
        L2c:
            if (r2 == 0) goto L39
            if (r2 <= r4) goto L38
            int r0 = r0 + r4
            char r7 = r7.charAt(r0)
            if (r7 != r3) goto L38
            goto L39
        L38:
            return r4
        L39:
            return r1
        */
        throw new UnsupportedOperationException("Method not decompiled: g2.n.t(java.lang.String, int):boolean");
    }

    private static boolean u(String str) {
        char cCharAt;
        if (str.length() < 3 || str.charAt(1) != '.' || (cCharAt = str.charAt(0)) < '0' || cCharAt > '2') {
            return false;
        }
        return t(str, 2);
    }

    private void v(ByteArrayOutputStream byteArrayOutputStream, long j3) {
        byte[] bArr = new byte[9];
        int i3 = 8;
        bArr[8] = (byte) (((int) j3) & 127);
        while (j3 >= 128) {
            j3 >>= 7;
            i3--;
            bArr[i3] = (byte) ((((int) j3) & 127) | 128);
        }
        byteArrayOutputStream.write(bArr, i3, 9 - i3);
    }

    private void w(ByteArrayOutputStream byteArrayOutputStream, BigInteger bigInteger) {
        int iBitLength = (bigInteger.bitLength() + 6) / 7;
        if (iBitLength == 0) {
            byteArrayOutputStream.write(0);
            return;
        }
        byte[] bArr = new byte[iBitLength];
        int i3 = iBitLength - 1;
        for (int i4 = i3; i4 >= 0; i4--) {
            bArr[i4] = (byte) ((bigInteger.intValue() & 127) | 128);
            bigInteger = bigInteger.shiftRight(7);
        }
        bArr[i3] = (byte) (bArr[i3] & 127);
        byteArrayOutputStream.write(bArr, 0, iBitLength);
    }

    @Override // g2.s
    boolean h(s sVar) {
        if (sVar == this) {
            return true;
        }
        if (sVar instanceof n) {
            return this.f4724e.equals(((n) sVar).f4724e);
        }
        return false;
    }

    @Override // g2.m
    public int hashCode() {
        return this.f4724e.hashCode();
    }

    @Override // g2.s
    void i(q qVar, boolean z2) throws IOException {
        qVar.n(z2, 6, r());
    }

    @Override // g2.s
    int j() throws IOException {
        int length = r().length;
        return y1.a(length) + 1 + length;
    }

    @Override // g2.s
    boolean m() {
        return false;
    }

    public String s() {
        return this.f4724e;
    }

    public String toString() {
        return s();
    }

    public n(String str) {
        Objects.requireNonNull(str, "'identifier' cannot be null");
        if (u(str)) {
            this.f4724e = str.intern();
            return;
        }
        throw new IllegalArgumentException("string " + str + " not an OID");
    }
}
