package com.google.android.play.core.b;

import android.util.Pair;
import com.bytedance.covode.number.Covode;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.FileChannel;
import java.security.DigestException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public final class bq {
    static {
        Covode.recordClassIndex(44267);
    }

    public static int LIZ(int i) {
        if (i == 513) {
            return 1;
        }
        if (i == 514) {
            return 2;
        }
        if (i == 769) {
            return 1;
        }
        switch (i) {
            case 257:
            case 259:
                return 1;
            case 258:
            case 260:
                return 2;
            default:
                String valueOf = String.valueOf(Long.toHexString((long) i));
                throw new IllegalArgumentException(valueOf.length() != 0 ? "Unknown signature algorithm: 0x".concat(valueOf) : new String("Unknown signature algorithm: 0x"));
        }
    }

    public static long LIZ(ByteBuffer byteBuffer, int i) {
        return ((long) byteBuffer.getInt(i)) & 4294967295L;
    }

    public static Pair<ByteBuffer, Long> LIZ(RandomAccessFile randomAccessFile) {
        if (randomAccessFile.length() < 22) {
            return null;
        }
        Pair<ByteBuffer, Long> LIZ = LIZ(randomAccessFile, 0);
        return LIZ != null ? LIZ : LIZ(randomAccessFile, 65535);
    }

    public static Pair<ByteBuffer, Long> LIZ(RandomAccessFile randomAccessFile, int i) {
        long length = randomAccessFile.length();
        if (length < 22) {
            return null;
        }
        ByteBuffer allocate = ByteBuffer.allocate(((int) Math.min((long) i, -22 + length)) + 22);
        allocate.order(ByteOrder.LITTLE_ENDIAN);
        long capacity = length - ((long) allocate.capacity());
        randomAccessFile.seek(capacity);
        randomAccessFile.readFully(allocate.array(), allocate.arrayOffset(), allocate.capacity());
        LIZ(allocate);
        int capacity2 = allocate.capacity();
        if (capacity2 >= 22) {
            int i2 = capacity2 - 22;
            int min = Math.min(i2, 65535);
            int i3 = 0;
            while (true) {
                if (i3 >= min) {
                    break;
                }
                int i4 = i2 - i3;
                if (allocate.getInt(i4) != 101010256 || ((char) allocate.getShort(i4 + 20)) != i3) {
                    i3++;
                } else if (i4 != -1) {
                    allocate.position(i4);
                    ByteBuffer slice = allocate.slice();
                    slice.order(ByteOrder.LITTLE_ENDIAN);
                    return Pair.create(slice, Long.valueOf(capacity + ((long) i4)));
                }
            }
        }
        return null;
    }

    public static String LIZ(String str, String str2) {
        int length = str.length();
        StringBuilder sb = new StringBuilder(length + 1 + String.valueOf(str2).length());
        sb.append(str);
        sb.append(":");
        sb.append(str2);
        return sb.toString();
    }

    public static String LIZ(String str, String str2, String str3) {
        int length = str.length();
        int length2 = String.valueOf(str2).length();
        StringBuilder sb = new StringBuilder(length + 2 + length2 + String.valueOf(str3).length());
        sb.append(str);
        sb.append(":");
        sb.append(str2);
        sb.append(":");
        sb.append(str3);
        return sb.toString();
    }

    public static void LIZ(int i, byte[] bArr) {
        bArr[1] = (byte) (i & 255);
        bArr[2] = (byte) ((i >>> 8) & 255);
        bArr[3] = (byte) ((i >>> 16) & 255);
        bArr[4] = (byte) (i >> 24);
    }

    public static void LIZ(ByteBuffer byteBuffer) {
        if (byteBuffer.order() != ByteOrder.LITTLE_ENDIAN) {
            throw new IllegalArgumentException("ByteBuffer byte order must be little endian");
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:58:0x012c, code lost:
        r0 = android.util.Pair.create(r8, r0);
        r9 = null;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static java.security.cert.X509Certificate[] LIZ(java.nio.ByteBuffer r22, java.util.Map<java.lang.Integer, byte[]> r23, java.security.cert.CertificateFactory r24) {
        /*
            r16 = 12354(0x3042, float:1.7312E-41)
            com.bytedance.frameworks.apm.trace.MethodCollector.i(r16)
            java.nio.ByteBuffer r7 = LIZIZ((java.nio.ByteBuffer) r22)
            java.nio.ByteBuffer r15 = LIZIZ((java.nio.ByteBuffer) r22)
            byte[] r6 = LIZJ((java.nio.ByteBuffer) r22)
            java.util.ArrayList r5 = new java.util.ArrayList
            r5.<init>()
            r10 = -1
            r4 = -1
            r8 = 0
            r1 = 0
        L_0x001a:
            boolean r0 = r15.hasRemaining()
            r3 = 8
            r13 = 769(0x301, float:1.078E-42)
            r12 = 514(0x202, float:7.2E-43)
            r11 = 513(0x201, float:7.19E-43)
            r2 = 1
            if (r0 == 0) goto L_0x0089
            int r8 = r8 + 1
            java.nio.ByteBuffer r14 = LIZIZ((java.nio.ByteBuffer) r15)     // Catch:{ IOException -> 0x006a, BufferUnderflowException -> 0x006c }
            int r0 = r14.remaining()     // Catch:{ IOException -> 0x006a, BufferUnderflowException -> 0x006c }
            if (r0 < r3) goto L_0x005f
            int r9 = r14.getInt()     // Catch:{ IOException -> 0x006a, BufferUnderflowException -> 0x006c }
            java.lang.Integer r0 = java.lang.Integer.valueOf(r9)     // Catch:{ IOException -> 0x006a, BufferUnderflowException -> 0x006c }
            r5.add(r0)     // Catch:{ IOException -> 0x006a, BufferUnderflowException -> 0x006c }
            if (r9 == r11) goto L_0x004a
            if (r9 == r12) goto L_0x004a
            if (r9 == r13) goto L_0x004a
            switch(r9) {
                case 257: goto L_0x004a;
                case 258: goto L_0x004a;
                case 259: goto L_0x004a;
                case 260: goto L_0x004a;
                default: goto L_0x0049;
            }     // Catch:{ IOException -> 0x006a, BufferUnderflowException -> 0x006c }
        L_0x0049:
            goto L_0x001a
        L_0x004a:
            if (r4 == r10) goto L_0x0059
            int r3 = LIZ((int) r9)     // Catch:{ IOException -> 0x006a, BufferUnderflowException -> 0x006c }
            int r0 = LIZ((int) r4)     // Catch:{ IOException -> 0x006a, BufferUnderflowException -> 0x006c }
            if (r3 == r2) goto L_0x001a
            if (r0 == r2) goto L_0x0059
            goto L_0x001a
        L_0x0059:
            byte[] r1 = LIZJ((java.nio.ByteBuffer) r14)     // Catch:{ IOException -> 0x006a, BufferUnderflowException -> 0x006c }
            r4 = r9
            goto L_0x001a
        L_0x005f:
            java.lang.SecurityException r1 = new java.lang.SecurityException     // Catch:{ IOException -> 0x006a, BufferUnderflowException -> 0x006c }
            java.lang.String r0 = "Signature record too short"
            r1.<init>(r0)     // Catch:{ IOException -> 0x006a, BufferUnderflowException -> 0x006c }
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r16)     // Catch:{ IOException -> 0x006a, BufferUnderflowException -> 0x006c }
            throw r1     // Catch:{ IOException -> 0x006a, BufferUnderflowException -> 0x006c }
        L_0x006a:
            r3 = move-exception
            goto L_0x006d
        L_0x006c:
            r3 = move-exception
        L_0x006d:
            java.lang.SecurityException r2 = new java.lang.SecurityException
            java.lang.StringBuilder r1 = new java.lang.StringBuilder
            r0 = 45
            r1.<init>(r0)
            java.lang.String r0 = "Failed to parse signature record #"
            r1.append(r0)
            r1.append(r8)
            java.lang.String r0 = r1.toString()
            r2.<init>(r0, r3)
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r16)
            throw r2
        L_0x0089:
            if (r4 != r10) goto L_0x00a1
            java.lang.SecurityException r1 = new java.lang.SecurityException
            if (r8 != 0) goto L_0x0098
            java.lang.String r0 = "No signatures found"
            r1.<init>(r0)
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r16)
            throw r1
        L_0x0098:
            java.lang.String r0 = "No supported signatures found"
            r1.<init>(r0)
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r16)
            throw r1
        L_0x00a1:
            java.lang.String r8 = "Unknown signature algorithm: 0x"
            if (r4 == r11) goto L_0x00d1
            if (r4 == r12) goto L_0x00d1
            if (r4 == r13) goto L_0x00ce
            switch(r4) {
                case 257: goto L_0x00d4;
                case 258: goto L_0x00d4;
                case 259: goto L_0x00d4;
                case 260: goto L_0x00d4;
                default: goto L_0x00ac;
            }
        L_0x00ac:
            java.lang.IllegalArgumentException r2 = new java.lang.IllegalArgumentException
            long r0 = (long) r4
            java.lang.String r0 = java.lang.Long.toHexString(r0)
            java.lang.String r1 = java.lang.String.valueOf(r0)
            int r0 = r1.length()
            if (r0 == 0) goto L_0x00c8
            java.lang.String r0 = r8.concat(r1)
        L_0x00c1:
            r2.<init>(r0)
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r16)
            throw r2
        L_0x00c8:
            java.lang.String r0 = new java.lang.String
            r0.<init>(r8)
            goto L_0x00c1
        L_0x00ce:
            java.lang.String r10 = "DSA"
            goto L_0x00d6
        L_0x00d1:
            java.lang.String r10 = "EC"
            goto L_0x00d6
        L_0x00d4:
            java.lang.String r10 = "RSA"
        L_0x00d6:
            if (r4 == r11) goto L_0x0139
            if (r4 == r12) goto L_0x0135
            if (r4 == r13) goto L_0x0132
            switch(r4) {
                case 257: goto L_0x0101;
                case 258: goto L_0x0119;
                case 259: goto L_0x0115;
                case 260: goto L_0x013d;
                default: goto L_0x00df;
            }
        L_0x00df:
            java.lang.IllegalArgumentException r2 = new java.lang.IllegalArgumentException
            long r0 = (long) r4
            java.lang.String r0 = java.lang.Long.toHexString(r0)
            java.lang.String r1 = java.lang.String.valueOf(r0)
            int r0 = r1.length()
            if (r0 == 0) goto L_0x00fb
            java.lang.String r0 = r8.concat(r1)
        L_0x00f4:
            r2.<init>(r0)
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r16)
            throw r2
        L_0x00fb:
            java.lang.String r0 = new java.lang.String
            r0.<init>(r8)
            goto L_0x00f4
        L_0x0101:
            java.security.spec.PSSParameterSpec r0 = new java.security.spec.PSSParameterSpec
            java.security.spec.MGF1ParameterSpec r20 = java.security.spec.MGF1ParameterSpec.SHA256
            r21 = 32
            r22 = 1
            java.lang.String r18 = "SHA-256"
            java.lang.String r19 = "MGF1"
            r17 = r0
            r17.<init>(r18, r19, r20, r21, r22)
            java.lang.String r8 = "SHA256withRSA/PSS"
            goto L_0x012c
        L_0x0115:
            r9 = 0
            java.lang.String r0 = "SHA256withRSA"
            goto L_0x0140
        L_0x0119:
            java.security.spec.PSSParameterSpec r0 = new java.security.spec.PSSParameterSpec
            java.security.spec.MGF1ParameterSpec r20 = java.security.spec.MGF1ParameterSpec.SHA512
            r21 = 64
            r22 = 1
            java.lang.String r18 = "SHA-512"
            java.lang.String r19 = "MGF1"
            r17 = r0
            r17.<init>(r18, r19, r20, r21, r22)
            java.lang.String r8 = "SHA512withRSA/PSS"
        L_0x012c:
            android.util.Pair r0 = android.util.Pair.create(r8, r0)
            r9 = 0
            goto L_0x0144
        L_0x0132:
            java.lang.String r0 = "SHA256withDSA"
            goto L_0x013f
        L_0x0135:
            r9 = 0
            java.lang.String r0 = "SHA512withECDSA"
            goto L_0x0140
        L_0x0139:
            r9 = 0
            java.lang.String r0 = "SHA256withECDSA"
            goto L_0x0140
        L_0x013d:
            java.lang.String r0 = "SHA512withRSA"
        L_0x013f:
            r9 = 0
        L_0x0140:
            android.util.Pair r0 = android.util.Pair.create(r0, r9)
        L_0x0144:
            java.lang.Object r8 = r0.first
            java.lang.String r8 = (java.lang.String) r8
            java.lang.Object r11 = r0.second
            java.security.spec.AlgorithmParameterSpec r11 = (java.security.spec.AlgorithmParameterSpec) r11
            java.security.KeyFactory r10 = java.security.KeyFactory.getInstance(r10)     // Catch:{ NoSuchAlgorithmException -> 0x02a6, InvalidKeySpecException -> 0x02a4, InvalidKeyException -> 0x02a2, InvalidAlgorithmParameterException -> 0x02a0, SignatureException -> 0x02a8 }
            java.security.spec.X509EncodedKeySpec r0 = new java.security.spec.X509EncodedKeySpec     // Catch:{ NoSuchAlgorithmException -> 0x02a6, InvalidKeySpecException -> 0x02a4, InvalidKeyException -> 0x02a2, InvalidAlgorithmParameterException -> 0x02a0, SignatureException -> 0x02a8 }
            r0.<init>(r6)     // Catch:{ NoSuchAlgorithmException -> 0x02a6, InvalidKeySpecException -> 0x02a4, InvalidKeyException -> 0x02a2, InvalidAlgorithmParameterException -> 0x02a0, SignatureException -> 0x02a8 }
            java.security.PublicKey r10 = r10.generatePublic(r0)     // Catch:{ NoSuchAlgorithmException -> 0x02a6, InvalidKeySpecException -> 0x02a4, InvalidKeyException -> 0x02a2, InvalidAlgorithmParameterException -> 0x02a0, SignatureException -> 0x02a8 }
            java.security.Signature r0 = java.security.Signature.getInstance(r8)     // Catch:{ NoSuchAlgorithmException -> 0x02a6, InvalidKeySpecException -> 0x02a4, InvalidKeyException -> 0x02a2, InvalidAlgorithmParameterException -> 0x02a0, SignatureException -> 0x02a8 }
            r0.initVerify(r10)     // Catch:{ NoSuchAlgorithmException -> 0x02a6, InvalidKeySpecException -> 0x02a4, InvalidKeyException -> 0x02a2, InvalidAlgorithmParameterException -> 0x02a0, SignatureException -> 0x02a8 }
            if (r11 == 0) goto L_0x0165
            r0.setParameter(r11)     // Catch:{ NoSuchAlgorithmException -> 0x02a6, InvalidKeySpecException -> 0x02a4, InvalidKeyException -> 0x02a2, InvalidAlgorithmParameterException -> 0x02a0, SignatureException -> 0x02a8 }
        L_0x0165:
            r0.update(r7)     // Catch:{ NoSuchAlgorithmException -> 0x02a6, InvalidKeySpecException -> 0x02a4, InvalidKeyException -> 0x02a2, InvalidAlgorithmParameterException -> 0x02a0, SignatureException -> 0x02a8 }
            boolean r0 = r0.verify(r1)     // Catch:{ NoSuchAlgorithmException -> 0x02a6, InvalidKeySpecException -> 0x02a4, InvalidKeyException -> 0x02a2, InvalidAlgorithmParameterException -> 0x02a0, SignatureException -> 0x02a8 }
            if (r0 == 0) goto L_0x028d
            r7.clear()
            java.nio.ByteBuffer r12 = LIZIZ((java.nio.ByteBuffer) r7)
            java.util.ArrayList r11 = new java.util.ArrayList
            r11.<init>()
            r8 = 0
        L_0x017b:
            boolean r0 = r12.hasRemaining()
            if (r0 == 0) goto L_0x01c8
            int r8 = r8 + r2
            java.nio.ByteBuffer r10 = LIZIZ((java.nio.ByteBuffer) r12)     // Catch:{ IOException -> 0x01a9, BufferUnderflowException -> 0x01ab }
            int r0 = r10.remaining()     // Catch:{ IOException -> 0x01a9, BufferUnderflowException -> 0x01ab }
            if (r0 < r3) goto L_0x019e
            int r1 = r10.getInt()     // Catch:{ IOException -> 0x01a9, BufferUnderflowException -> 0x01ab }
            java.lang.Integer r0 = java.lang.Integer.valueOf(r1)     // Catch:{ IOException -> 0x01a9, BufferUnderflowException -> 0x01ab }
            r11.add(r0)     // Catch:{ IOException -> 0x01a9, BufferUnderflowException -> 0x01ab }
            if (r1 != r4) goto L_0x017b
            byte[] r9 = LIZJ((java.nio.ByteBuffer) r10)     // Catch:{ IOException -> 0x01a9, BufferUnderflowException -> 0x01ab }
            goto L_0x017b
        L_0x019e:
            java.io.IOException r1 = new java.io.IOException     // Catch:{ IOException -> 0x01a9, BufferUnderflowException -> 0x01ab }
            java.lang.String r0 = "Record too short"
            r1.<init>(r0)     // Catch:{ IOException -> 0x01a9, BufferUnderflowException -> 0x01ab }
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r16)     // Catch:{ IOException -> 0x01a9, BufferUnderflowException -> 0x01ab }
            throw r1     // Catch:{ IOException -> 0x01a9, BufferUnderflowException -> 0x01ab }
        L_0x01a9:
            r3 = move-exception
            goto L_0x01ac
        L_0x01ab:
            r3 = move-exception
        L_0x01ac:
            java.io.IOException r2 = new java.io.IOException
            java.lang.StringBuilder r1 = new java.lang.StringBuilder
            r0 = 42
            r1.<init>(r0)
            java.lang.String r0 = "Failed to parse digest record #"
            r1.append(r0)
            r1.append(r8)
            java.lang.String r0 = r1.toString()
            r2.<init>(r0, r3)
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r16)
            throw r2
        L_0x01c8:
            boolean r0 = r5.equals(r11)
            if (r0 == 0) goto L_0x0282
            int r1 = LIZ((int) r4)
            java.lang.Integer r0 = java.lang.Integer.valueOf(r1)
            r3 = r23
            java.lang.Object r0 = r3.put(r0, r9)
            byte[] r0 = (byte[]) r0
            if (r0 == 0) goto L_0x01e6
            boolean r0 = java.security.MessageDigest.isEqual(r0, r9)
            if (r0 == 0) goto L_0x026f
        L_0x01e6:
            java.nio.ByteBuffer r7 = LIZIZ((java.nio.ByteBuffer) r7)
            java.util.ArrayList r4 = new java.util.ArrayList
            r4.<init>()
            r5 = 0
        L_0x01f0:
            boolean r0 = r7.hasRemaining()
            if (r0 == 0) goto L_0x022e
            int r5 = r5 + r2
            byte[] r3 = LIZJ((java.nio.ByteBuffer) r7)
            java.io.ByteArrayInputStream r0 = new java.io.ByteArrayInputStream     // Catch:{ CertificateException -> 0x0211 }
            r0.<init>(r3)     // Catch:{ CertificateException -> 0x0211 }
            r1 = r24
            java.security.cert.Certificate r1 = r1.generateCertificate(r0)     // Catch:{ CertificateException -> 0x0211 }
            java.security.cert.X509Certificate r1 = (java.security.cert.X509Certificate) r1     // Catch:{ CertificateException -> 0x0211 }
            com.google.android.play.core.b.bo r0 = new com.google.android.play.core.b.bo
            r0.<init>(r1, r3)
            r4.add(r0)
            goto L_0x01f0
        L_0x0211:
            r3 = move-exception
            java.lang.SecurityException r2 = new java.lang.SecurityException
            java.lang.StringBuilder r1 = new java.lang.StringBuilder
            r0 = 41
            r1.<init>(r0)
            java.lang.String r0 = "Failed to decode certificate #"
            r1.append(r0)
            r1.append(r5)
            java.lang.String r0 = r1.toString()
            r2.<init>(r0, r3)
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r16)
            throw r2
        L_0x022e:
            boolean r0 = r4.isEmpty()
            if (r0 != 0) goto L_0x0264
            r0 = 0
            java.lang.Object r0 = r4.get(r0)
            java.security.cert.X509Certificate r0 = (java.security.cert.X509Certificate) r0
            java.security.PublicKey r0 = r0.getPublicKey()
            byte[] r0 = r0.getEncoded()
            boolean r0 = java.util.Arrays.equals(r6, r0)
            if (r0 == 0) goto L_0x0259
            int r0 = r4.size()
            java.security.cert.X509Certificate[] r0 = new java.security.cert.X509Certificate[r0]
            java.lang.Object[] r0 = r4.toArray(r0)
            java.security.cert.X509Certificate[] r0 = (java.security.cert.X509Certificate[]) r0
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r16)
            return r0
        L_0x0259:
            java.lang.SecurityException r1 = new java.lang.SecurityException
            java.lang.String r0 = "Public key mismatch between certificate and signature record"
            r1.<init>(r0)
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r16)
            throw r1
        L_0x0264:
            java.lang.SecurityException r1 = new java.lang.SecurityException
            java.lang.String r0 = "No certificates listed"
            r1.<init>(r0)
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r16)
            throw r1
        L_0x026f:
            java.lang.SecurityException r2 = new java.lang.SecurityException
            java.lang.String r1 = LIZIZ((int) r1)
            java.lang.String r0 = " contents digest does not match the digest specified by a preceding signer"
            java.lang.String r0 = r1.concat(r0)
            r2.<init>(r0)
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r16)
            throw r2
        L_0x0282:
            java.lang.SecurityException r1 = new java.lang.SecurityException
            java.lang.String r0 = "Signature algorithms don't match between digests and signatures records"
            r1.<init>(r0)
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r16)
            throw r1
        L_0x028d:
            java.lang.SecurityException r2 = new java.lang.SecurityException
            java.lang.String r1 = java.lang.String.valueOf(r8)
            java.lang.String r0 = " signature did not verify"
            java.lang.String r0 = r1.concat(r0)
            r2.<init>(r0)
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r16)
            throw r2
        L_0x02a0:
            r3 = move-exception
            goto L_0x02a9
        L_0x02a2:
            r3 = move-exception
            goto L_0x02a9
        L_0x02a4:
            r3 = move-exception
            goto L_0x02a9
        L_0x02a6:
            r3 = move-exception
            goto L_0x02a9
        L_0x02a8:
            r3 = move-exception
        L_0x02a9:
            java.lang.SecurityException r2 = new java.lang.SecurityException
            java.lang.String r0 = java.lang.String.valueOf(r8)
            int r0 = r0.length()
            java.lang.StringBuilder r1 = new java.lang.StringBuilder
            int r0 = r0 + 27
            r1.<init>(r0)
            java.lang.String r0 = "Failed to verify "
            r1.append(r0)
            r1.append(r8)
            java.lang.String r0 = " signature"
            r1.append(r0)
            java.lang.String r0 = r1.toString()
            r2.<init>(r0, r3)
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r16)
            throw r2
        */
        throw new UnsupportedOperationException("Method not decompiled: com.google.android.play.core.b.bq.LIZ(java.nio.ByteBuffer, java.util.Map, java.security.cert.CertificateFactory):java.security.cert.X509Certificate[]");
    }

    public static byte[][] LIZ(int[] iArr, av[] avVarArr) {
        long j;
        int i;
        int length;
        long j2 = 0;
        long j3 = 0;
        int i2 = 0;
        while (true) {
            j = 1048576;
            if (i2 >= 3) {
                break;
            }
            j3 += (avVarArr[i2].LIZ() + 1048575) / 1048576;
            i2++;
        }
        if (j3 < 2097151) {
            int i3 = (int) j3;
            int[] iArr2 = iArr;
            byte[][] bArr = new byte[iArr2.length][];
            int i4 = 0;
            while (true) {
                length = iArr2.length;
                if (i4 >= length) {
                    break;
                }
                byte[] bArr2 = new byte[((LIZJ(iArr2[i4]) * i3) + 5)];
                bArr2[0] = 90;
                LIZ(i3, bArr2);
                bArr[i4] = bArr2;
                i4++;
            }
            byte[] bArr3 = new byte[5];
            bArr3[0] = -91;
            MessageDigest[] messageDigestArr = new MessageDigest[length];
            int i5 = 0;
            while (i5 < iArr2.length) {
                String LIZIZ = LIZIZ(iArr2[i5]);
                try {
                    messageDigestArr[i5] = MessageDigest.getInstance(LIZIZ);
                    i5++;
                } catch (NoSuchAlgorithmException e) {
                    throw new RuntimeException(LIZIZ.concat(" digest not supported"), e);
                }
            }
            int i6 = 0;
            int i7 = 0;
            int i8 = 0;
            for (i = 3; i6 < i; i = 3) {
                av avVar = avVarArr[i6];
                long LIZ = avVar.LIZ();
                long j4 = 0;
                while (LIZ > j2) {
                    int min = (int) Math.min(LIZ, j);
                    LIZ(min, bArr3);
                    for (int i9 = 0; i9 < length; i9++) {
                        messageDigestArr[i9].update(bArr3);
                    }
                    avVar = avVar;
                    try {
                        avVar.LIZ(messageDigestArr, j4, min);
                        int i10 = 0;
                        while (i10 < iArr2.length) {
                            int i11 = iArr2[i10];
                            byte[] bArr4 = bArr[i10];
                            int LIZJ = LIZJ(i11);
                            MessageDigest messageDigest = messageDigestArr[i10];
                            int digest = messageDigest.digest(bArr4, (i7 * LIZJ) + 5, LIZJ);
                            if (digest == LIZJ) {
                                i10++;
                            } else {
                                String algorithm = messageDigest.getAlgorithm();
                                StringBuilder sb = new StringBuilder(String.valueOf(algorithm).length() + 46);
                                sb.append("Unexpected output size of ");
                                sb.append(algorithm);
                                sb.append(" digest: ");
                                sb.append(digest);
                                throw new RuntimeException(sb.toString());
                            }
                        }
                        long j5 = (long) min;
                        j4 += j5;
                        LIZ -= j5;
                        i7++;
                        j2 = 0;
                        j = 1048576;
                    } catch (IOException e2) {
                        StringBuilder sb2 = new StringBuilder(59);
                        sb2.append("Failed to digest chunk #");
                        sb2.append(i7);
                        sb2.append(" of section #");
                        sb2.append(i8);
                        throw new DigestException(sb2.toString(), e2);
                    }
                }
                i8++;
                i6++;
                j2 = 0;
                j = 1048576;
            }
            byte[][] bArr5 = new byte[iArr2.length][];
            int i12 = 0;
            while (i12 < iArr2.length) {
                int i13 = iArr2[i12];
                byte[] bArr6 = bArr[i12];
                String LIZIZ2 = LIZIZ(i13);
                try {
                    bArr5[i12] = MessageDigest.getInstance(LIZIZ2).digest(bArr6);
                    i12++;
                } catch (NoSuchAlgorithmException e3) {
                    throw new RuntimeException(LIZIZ2.concat(" digest not supported"), e3);
                }
            }
            return bArr5;
        }
        StringBuilder sb3 = new StringBuilder(37);
        sb3.append("Too many chunks: ");
        sb3.append(j3);
        throw new DigestException(sb3.toString());
    }

    public static String LIZIZ(int i) {
        if (i == 1) {
            return "SHA-256";
        }
        if (i == 2) {
            return "SHA-512";
        }
        StringBuilder sb = new StringBuilder(44);
        sb.append("Unknown content digest algorthm: ");
        sb.append(i);
        throw new IllegalArgumentException(sb.toString());
    }

    public static ByteBuffer LIZIZ(ByteBuffer byteBuffer) {
        if (byteBuffer.remaining() >= 4) {
            int i = byteBuffer.getInt();
            if (i < 0) {
                throw new IllegalArgumentException("Negative length");
            } else if (i <= byteBuffer.remaining()) {
                return LIZIZ(byteBuffer, i);
            } else {
                int remaining = byteBuffer.remaining();
                StringBuilder sb = new StringBuilder(101);
                sb.append("Length-prefixed field longer than remaining buffer. Field length: ");
                sb.append(i);
                sb.append(", remaining: ");
                sb.append(remaining);
                throw new IOException(sb.toString());
            }
        } else {
            int remaining2 = byteBuffer.remaining();
            StringBuilder sb2 = new StringBuilder(93);
            sb2.append("Remaining buffer too short to contain length of length-prefixed field. Remaining: ");
            sb2.append(remaining2);
            throw new IOException(sb2.toString());
        }
    }

    public static ByteBuffer LIZIZ(ByteBuffer byteBuffer, int i) {
        if (i >= 0) {
            int limit = byteBuffer.limit();
            int position = byteBuffer.position();
            int i2 = i + position;
            if (i2 < position || i2 > limit) {
                throw new BufferUnderflowException();
            }
            byteBuffer.limit(i2);
            try {
                ByteBuffer slice = byteBuffer.slice();
                slice.order(byteBuffer.order());
                byteBuffer.position(i2);
                return slice;
            } finally {
                byteBuffer.limit(limit);
            }
        } else {
            StringBuilder sb = new StringBuilder(17);
            sb.append("size: ");
            sb.append(i);
            throw new IllegalArgumentException(sb.toString());
        }
    }

    public static int LIZJ(int i) {
        if (i == 1) {
            return 32;
        }
        if (i == 2) {
            return 64;
        }
        StringBuilder sb = new StringBuilder(44);
        sb.append("Unknown content digest algorthm: ");
        sb.append(i);
        throw new IllegalArgumentException(sb.toString());
    }

    public static byte[] LIZJ(ByteBuffer byteBuffer) {
        int i = byteBuffer.getInt();
        if (i < 0) {
            throw new IOException("Negative length");
        } else if (i <= byteBuffer.remaining()) {
            byte[] bArr = new byte[i];
            byteBuffer.get(bArr);
            return bArr;
        } else {
            int remaining = byteBuffer.remaining();
            StringBuilder sb = new StringBuilder(90);
            sb.append("Underflow while reading length-prefixed value. Length: ");
            sb.append(i);
            sb.append(", available: ");
            sb.append(remaining);
            throw new IOException(sb.toString());
        }
    }

    public static X509Certificate[][] LIZ(String str) {
        ByteBuffer byteBuffer;
        int limit;
        int position;
        RandomAccessFile randomAccessFile = new RandomAccessFile(str, "r");
        try {
            Pair<ByteBuffer, Long> LIZ = LIZ(randomAccessFile);
            if (LIZ != null) {
                ByteBuffer byteBuffer2 = (ByteBuffer) LIZ.first;
                long longValue = ((Long) LIZ.second).longValue();
                long j = -20 + longValue;
                if (j >= 0) {
                    randomAccessFile.seek(j);
                    if (randomAccessFile.readInt() == 1347094023) {
                        throw new bn("ZIP64 APK not supported");
                    }
                }
                LIZ(byteBuffer2);
                long LIZ2 = LIZ(byteBuffer2, byteBuffer2.position() + 16);
                if (LIZ2 < longValue) {
                    LIZ(byteBuffer2);
                    if (LIZ(byteBuffer2, byteBuffer2.position() + 12) + LIZ2 != longValue) {
                        throw new bn("ZIP Central Directory is not immediately followed by End of Central Directory");
                    } else if (LIZ2 >= 32) {
                        ByteBuffer allocate = ByteBuffer.allocate(24);
                        allocate.order(ByteOrder.LITTLE_ENDIAN);
                        randomAccessFile.seek(LIZ2 - ((long) allocate.capacity()));
                        randomAccessFile.readFully(allocate.array(), allocate.arrayOffset(), allocate.capacity());
                        int i = 8;
                        if (allocate.getLong(8) == 2334950737559900225L && allocate.getLong(16) == 3617552046287187010L) {
                            int i2 = 0;
                            long j2 = allocate.getLong(0);
                            if (j2 < ((long) allocate.capacity()) || j2 > 2147483639) {
                                StringBuilder sb = new StringBuilder(57);
                                sb.append("APK Signing Block size out of range: ");
                                sb.append(j2);
                                throw new bn(sb.toString());
                            }
                            int i3 = (int) (8 + j2);
                            long j3 = LIZ2 - ((long) i3);
                            if (j3 >= 0) {
                                ByteBuffer allocate2 = ByteBuffer.allocate(i3);
                                allocate2.order(ByteOrder.LITTLE_ENDIAN);
                                randomAccessFile.seek(j3);
                                randomAccessFile.readFully(allocate2.array(), allocate2.arrayOffset(), allocate2.capacity());
                                long j4 = allocate2.getLong(0);
                                if (j4 == j2) {
                                    Pair create = Pair.create(allocate2, Long.valueOf(j3));
                                    byteBuffer = (ByteBuffer) create.first;
                                    long longValue2 = ((Long) create.second).longValue();
                                    if (byteBuffer.order() == ByteOrder.LITTLE_ENDIAN) {
                                        int capacity = byteBuffer.capacity() - 24;
                                        if (capacity >= 8) {
                                            int capacity2 = byteBuffer.capacity();
                                            if (capacity <= byteBuffer.capacity()) {
                                                limit = byteBuffer.limit();
                                                position = byteBuffer.position();
                                                byteBuffer.position(0);
                                                byteBuffer.limit(capacity);
                                                byteBuffer.position(8);
                                                ByteBuffer slice = byteBuffer.slice();
                                                slice.order(byteBuffer.order());
                                                byteBuffer.position(0);
                                                byteBuffer.limit(limit);
                                                byteBuffer.position(position);
                                                while (slice.hasRemaining()) {
                                                    i2++;
                                                    if (slice.remaining() >= i) {
                                                        long j5 = slice.getLong();
                                                        if (j5 < 4 || j5 > 2147483647L) {
                                                            StringBuilder sb2 = new StringBuilder(76);
                                                            sb2.append("APK Signing Block entry #");
                                                            sb2.append(i2);
                                                            sb2.append(" size out of range: ");
                                                            sb2.append(j5);
                                                            throw new bn(sb2.toString());
                                                        }
                                                        int i4 = (int) j5;
                                                        int position2 = slice.position() + i4;
                                                        if (i4 > slice.remaining()) {
                                                            int remaining = slice.remaining();
                                                            StringBuilder sb3 = new StringBuilder(91);
                                                            sb3.append("APK Signing Block entry #");
                                                            sb3.append(i2);
                                                            sb3.append(" size out of range: ");
                                                            sb3.append(i4);
                                                            sb3.append(", available: ");
                                                            sb3.append(remaining);
                                                            throw new bn(sb3.toString());
                                                        } else if (slice.getInt() == 1896449818) {
                                                            X509Certificate[][] LIZ3 = LIZ(randomAccessFile.getChannel(), new bm(LIZIZ(slice, i4 - 4), longValue2, LIZ2, longValue, byteBuffer2));
                                                            randomAccessFile.close();
                                                            try {
                                                                randomAccessFile.close();
                                                            } catch (IOException unused) {
                                                            }
                                                            return LIZ3;
                                                        } else {
                                                            slice.position(position2);
                                                            i = 8;
                                                        }
                                                    } else {
                                                        StringBuilder sb4 = new StringBuilder(70);
                                                        sb4.append("Insufficient data to read size of APK Signing Block entry #");
                                                        sb4.append(i2);
                                                        throw new bn(sb4.toString());
                                                    }
                                                }
                                                throw new bn("No APK Signature Scheme v2 block in APK Signing Block");
                                            }
                                            StringBuilder sb5 = new StringBuilder(41);
                                            sb5.append("end > capacity: ");
                                            sb5.append(capacity);
                                            sb5.append(" > ");
                                            sb5.append(capacity2);
                                            throw new IllegalArgumentException(sb5.toString());
                                        }
                                        StringBuilder sb6 = new StringBuilder(38);
                                        sb6.append("end < start: ");
                                        sb6.append(capacity);
                                        sb6.append(" < ");
                                        sb6.append(8);
                                        throw new IllegalArgumentException(sb6.toString());
                                    }
                                    throw new IllegalArgumentException("ByteBuffer byte order must be little endian");
                                }
                                StringBuilder sb7 = new StringBuilder(103);
                                sb7.append("APK Signing Block sizes in header and footer do not match: ");
                                sb7.append(j4);
                                sb7.append(" vs ");
                                sb7.append(j2);
                                throw new bn(sb7.toString());
                            }
                            StringBuilder sb8 = new StringBuilder(59);
                            sb8.append("APK Signing Block offset out of range: ");
                            sb8.append(j3);
                            throw new bn(sb8.toString());
                        }
                        throw new bn("No APK Signing Block before ZIP Central Directory");
                    } else {
                        StringBuilder sb9 = new StringBuilder(87);
                        sb9.append("APK too small for APK Signing Block. ZIP Central Directory offset: ");
                        sb9.append(LIZ2);
                        throw new bn(sb9.toString());
                    }
                } else {
                    StringBuilder sb10 = new StringBuilder(122);
                    sb10.append("ZIP Central Directory offset out of range: ");
                    sb10.append(LIZ2);
                    sb10.append(". ZIP End of Central Directory offset: ");
                    sb10.append(longValue);
                    throw new bn(sb10.toString());
                }
            } else {
                long length = randomAccessFile.length();
                StringBuilder sb11 = new StringBuilder(102);
                sb11.append("Not an APK file: ZIP End of Central Directory record not found in file with ");
                sb11.append(length);
                sb11.append(" bytes");
                throw new bn(sb11.toString());
            }
        } catch (Throwable th) {
            try {
                randomAccessFile.close();
            } catch (IOException unused2) {
            }
            throw th;
        }
    }

    public static X509Certificate[][] LIZ(FileChannel fileChannel, bm bmVar) {
        HashMap hashMap = new HashMap();
        ArrayList arrayList = new ArrayList();
        try {
            CertificateFactory instance = CertificateFactory.getInstance("X.509");
            try {
                ByteBuffer LIZIZ = LIZIZ(bmVar.LIZ);
                int i = 0;
                while (LIZIZ.hasRemaining()) {
                    i++;
                    try {
                        arrayList.add(LIZ(LIZIZ(LIZIZ), (Map<Integer, byte[]>) hashMap, instance));
                    } catch (IOException | SecurityException | BufferUnderflowException e) {
                        StringBuilder sb = new StringBuilder(48);
                        sb.append("Failed to parse/verify signer #");
                        sb.append(i);
                        sb.append(" block");
                        throw new SecurityException(sb.toString(), e);
                    }
                }
                if (i <= 0) {
                    throw new SecurityException("No signers found");
                } else if (!hashMap.isEmpty()) {
                    LIZ(hashMap, fileChannel, bmVar.LIZIZ, bmVar.LIZJ, bmVar.LIZLLL, bmVar.LJ);
                    return (X509Certificate[][]) arrayList.toArray(new X509Certificate[arrayList.size()][]);
                } else {
                    throw new SecurityException("No content digests found");
                }
            } catch (IOException e2) {
                throw new SecurityException("Failed to read list of signers", e2);
            }
        } catch (CertificateException e3) {
            throw new RuntimeException("Failed to obtain X.509 CertificateFactory", e3);
        }
    }

    public static void LIZ(Map<Integer, byte[]> map, FileChannel fileChannel, long j, long j2, long j3, ByteBuffer byteBuffer) {
        Map<Integer, byte[]> map2 = map;
        long j4 = j3;
        if (!map2.isEmpty()) {
            long j5 = j;
            FileChannel fileChannel2 = fileChannel;
            bl blVar = new bl(fileChannel2, 0, j5);
            long j6 = j2;
            bl blVar2 = new bl(fileChannel2, j6, j4 - j6);
            ByteBuffer duplicate = byteBuffer.duplicate();
            duplicate.order(ByteOrder.LITTLE_ENDIAN);
            LIZ(duplicate);
            int position = duplicate.position() + 16;
            if (j5 < 0 || j5 > 4294967295L) {
                StringBuilder sb = new StringBuilder(47);
                sb.append("uint32 value of out range: ");
                sb.append(j5);
                throw new IllegalArgumentException(sb.toString());
            }
            duplicate.putInt(duplicate.position() + position, (int) j5);
            v vVar = new v(duplicate);
            int size = map2.size();
            int[] iArr = new int[size];
            int i = 0;
            int i2 = 0;
            for (Integer intValue : map2.keySet()) {
                iArr[i2] = intValue.intValue();
                i2++;
            }
            try {
                byte[][] LIZ = LIZ(iArr, new av[]{blVar, blVar2, vVar});
                while (i < size) {
                    int i3 = iArr[i];
                    if (MessageDigest.isEqual(map2.get(Integer.valueOf(i3)), LIZ[i])) {
                        i++;
                    } else {
                        throw new SecurityException(LIZIZ(i3).concat(" digest of contents did not verify"));
                    }
                }
            } catch (DigestException e) {
                throw new SecurityException("Failed to compute digest(s) of contents", e);
            }
        } else {
            throw new SecurityException("No digests provided");
        }
    }
}
