package u2;

import i2.C0628e;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import java.util.Iterator;
import t2.InterfaceC1024a;

/* JADX INFO: renamed from: u2.c, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1067c implements InterfaceC1024a {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final B2.a f10312a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final C0628e f10313b;

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

    public C1067c(B2.a aVar) {
        this.f10312a = aVar;
        boolean zIsEmpty = ((D2.a) aVar.f134l).f440a.isEmpty();
        C0628e c0628e = A2.q.f54a;
        if (zIsEmpty) {
            this.f10313b = c0628e;
            this.f10314c = c0628e;
            return;
        }
        A2.g gVar = (A2.g) A2.h.f33b.f35a.get();
        gVar = gVar == null ? A2.h.f34c : gVar;
        A2.q.a(aVar);
        gVar.getClass();
        this.f10313b = c0628e;
        this.f10314c = c0628e;
    }

    @Override // t2.InterfaceC1024a
    public final byte[] a(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        C0628e c0628e = this.f10313b;
        B2.a aVar = this.f10312a;
        try {
            byte[] bArr3 = ((t2.k) aVar.f136n).f9990c;
            byte[] bArrE = android.support.v4.media.session.b.e(bArr3 == null ? null : Arrays.copyOf(bArr3, bArr3.length), ((InterfaceC1024a) ((t2.k) aVar.f136n).f9989b).a(bArr, bArr2));
            int i = ((t2.k) aVar.f136n).f9993f;
            int length = bArr.length;
            c0628e.getClass();
            return bArrE;
        } catch (GeneralSecurityException e2) {
            c0628e.getClass();
            throw e2;
        }
    }

    @Override // t2.InterfaceC1024a
    public final byte[] b(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        int length = bArr.length;
        B2.a aVar = this.f10312a;
        C0628e c0628e = this.f10314c;
        if (length > 5) {
            byte[] bArrCopyOf = Arrays.copyOf(bArr, 5);
            byte[] bArrCopyOfRange = Arrays.copyOfRange(bArr, 5, bArr.length);
            Iterator it = aVar.y(bArrCopyOf).iterator();
            while (it.hasNext()) {
                try {
                    byte[] bArrB = ((InterfaceC1024a) ((t2.k) it.next()).f9989b).b(bArrCopyOfRange, bArr2);
                    c0628e.getClass();
                    return bArrB;
                } catch (GeneralSecurityException e2) {
                    C1068d.f10315a.info("ciphertext prefix matches a key, but cannot decrypt: " + e2);
                }
            }
        }
        Iterator it2 = aVar.y(t2.b.f9976a).iterator();
        while (it2.hasNext()) {
            try {
                byte[] bArrB2 = ((InterfaceC1024a) ((t2.k) it2.next()).f9989b).b(bArr, bArr2);
                c0628e.getClass();
                return bArrB2;
            } catch (GeneralSecurityException unused) {
            }
        }
        c0628e.getClass();
        throw new GeneralSecurityException("decryption failed");
    }
}
