package fa;

import com.google.android.gms.measurement.internal.c2;
import java.nio.ByteBuffer;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import ma.j0;
import ma.p0;

/* JADX INFO: loaded from: classes2.dex */
public final class p implements da.a {

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

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

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

    public p(byte[] bArr, int i10, byte[] bArr2) {
        this.f26021a = i10;
        if (i10 != 2) {
            this.f26023c = new m(bArr, 0);
            this.f26022b = bArr2;
        } else {
            this.f26023c = new m(bArr, 1);
            this.f26022b = bArr2;
        }
    }

    @Override // da.a
    public final byte[] a(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        int i10 = this.f26021a;
        byte[] bArr3 = this.f26022b;
        Object obj = this.f26023c;
        switch (i10) {
            case 0:
                return bArr3.length == 0 ? ((da.a) obj).a(bArr, bArr2) : c2.f(bArr3, ((da.a) obj).a(bArr, bArr2));
            case 1:
                ByteBuffer byteBufferAllocate = ByteBuffer.allocate(bArr.length + 28);
                byte[] bArrA = j0.a(12);
                byteBufferAllocate.put(bArrA);
                ((m) obj).b(byteBufferAllocate, bArrA, bArr, bArr2);
                byte[] bArrArray = byteBufferAllocate.array();
                return bArr3.length == 0 ? bArrArray : c2.f(bArr3, bArrArray);
            default:
                ByteBuffer byteBufferAllocate2 = ByteBuffer.allocate(bArr.length + 40);
                byte[] bArrA2 = j0.a(24);
                byteBufferAllocate2.put(bArrA2);
                ((m) obj).b(byteBufferAllocate2, bArrA2, bArr, bArr2);
                byte[] bArrArray2 = byteBufferAllocate2.array();
                return bArr3.length == 0 ? bArrArray2 : c2.f(bArr3, bArrArray2);
        }
    }

    @Override // da.a
    public final byte[] b(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        int i10 = this.f26021a;
        byte[] bArr3 = this.f26022b;
        switch (i10) {
            case 0:
                int length = bArr3.length;
                Object obj = this.f26023c;
                if (length == 0) {
                    return ((da.a) obj).b(bArr, bArr2);
                }
                if (p0.b(bArr3, bArr)) {
                    return ((da.a) obj).b(Arrays.copyOfRange(bArr, 5, bArr.length), bArr2);
                }
                throw new GeneralSecurityException("wrong prefix");
            case 1:
                if (bArr3.length == 0) {
                    return c(bArr, bArr2);
                }
                if (p0.b(bArr3, bArr)) {
                    return c(Arrays.copyOfRange(bArr, bArr3.length, bArr.length), bArr2);
                }
                throw new GeneralSecurityException("Decryption failed (OutputPrefix mismatch).");
            default:
                if (bArr3.length == 0) {
                    return d(bArr, bArr2);
                }
                if (p0.b(bArr3, bArr)) {
                    return d(Arrays.copyOfRange(bArr, bArr3.length, bArr.length), bArr2);
                }
                throw new GeneralSecurityException("Decryption failed (OutputPrefix mismatch).");
        }
    }

    public final byte[] c(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        if (bArr.length < 28) {
            throw new GeneralSecurityException("ciphertext too short");
        }
        byte[] bArrCopyOf = Arrays.copyOf(bArr, 12);
        return ((m) this.f26023c).a(ByteBuffer.wrap(bArr, 12, bArr.length - 12), bArrCopyOf, bArr2);
    }

    public final byte[] d(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        if (bArr.length < 40) {
            throw new GeneralSecurityException("ciphertext too short");
        }
        byte[] bArrCopyOf = Arrays.copyOf(bArr, 24);
        return ((m) this.f26023c).a(ByteBuffer.wrap(bArr, 24, bArr.length - 24), bArrCopyOf, bArr2);
    }

    public p(da.a aVar, byte[] bArr) {
        this.f26021a = 0;
        this.f26023c = aVar;
        if (bArr.length != 0 && bArr.length != 5) {
            throw new IllegalArgumentException("identifier has an invalid length");
        }
        this.f26022b = bArr;
    }
}
