package defpackage;

import j$.util.DesugarCollections;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.security.GeneralSecurityException;
import java.util.HashSet;
import java.util.Set;

/* JADX INFO: renamed from: ˈᵣ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C1096 implements InterfaceC5579 {

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public static final Set f4666;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public static final byte[] f4667 = new byte[0];

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final AbstractC1378 f4668;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final C4658 f4669;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final String f4670;

    static {
        HashSet hashSet = new HashSet();
        hashSet.add("type.googleapis.com/google.crypto.tink.AesGcmKey");
        hashSet.add("type.googleapis.com/google.crypto.tink.ChaCha20Poly1305Key");
        hashSet.add("type.googleapis.com/google.crypto.tink.XChaCha20Poly1305Key");
        hashSet.add("type.googleapis.com/google.crypto.tink.AesCtrHmacAeadKey");
        hashSet.add("type.googleapis.com/google.crypto.tink.AesGcmSivKey");
        hashSet.add("type.googleapis.com/google.crypto.tink.AesEaxKey");
        f4666 = DesugarCollections.unmodifiableSet(hashSet);
    }

    public C1096(C4763 c4763, C4658 c4658) {
        if (!f4666.contains(c4763.m9952())) {
            C3226.m7372("Unsupported DEK key type: ", c4763.m9952(), ". Only Tink AEAD key types are supported.");
            throw null;
        }
        this.f4670 = c4763.m9952();
        C1444 c1444M9946 = C4763.m9946(c4763);
        c1444M9946.m4159(EnumC5109.f19249);
        this.f4668 = ᵶᵦ.ˏːˆ(((C4763) c1444M9946.m5863()).m896());
        this.f4669 = c4658;
    }

    @Override // defpackage.InterfaceC5579
    /* JADX INFO: renamed from: ʽˈˋ */
    public final byte[] mo1207(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        try {
            ByteBuffer byteBufferWrap = ByteBuffer.wrap(bArr);
            int i = byteBufferWrap.getInt();
            if (i <= 0 || i > 4096 || i > bArr.length - 4) {
                throw new GeneralSecurityException("length of encrypted DEK too large");
            }
            byte[] bArr3 = new byte[i];
            byteBufferWrap.get(bArr3, 0, i);
            byte[] bArr4 = new byte[byteBufferWrap.remaining()];
            byteBufferWrap.get(bArr4, 0, byteBufferWrap.remaining());
            byte[] bArrMo1207 = this.f4669.mo1207(bArr3, f4667);
            String str = this.f4670;
            try {
                C1236 c1236 = AbstractC4613.f17546;
                return ((InterfaceC5579) ((C0135) C2154.f8571.f8572.get()).m1249(C5495.f20773.m11131(C2781.m6742(str, AbstractC4613.m9729(bArrMo1207, 0, bArrMo1207.length), EnumC1913.f7601, EnumC5109.f19249, null)), InterfaceC5579.class)).mo1207(bArr4, bArr2);
            } catch (NegativeArraySizeException e) {
                e = e;
                throw new GeneralSecurityException("invalid ciphertext", e);
            } catch (BufferUnderflowException e2) {
                e = e2;
                throw new GeneralSecurityException("invalid ciphertext", e);
            }
        } catch (IndexOutOfBoundsException | NegativeArraySizeException | BufferUnderflowException e3) {
            e = e3;
        }
    }

    @Override // defpackage.InterfaceC5579
    /* JADX INFO: renamed from: ᵲᵶᵳˈ */
    public final byte[] mo1208(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        ᵺᵘ r0 = C4290.f16355.m9268(this.f4668, null);
        byte[] bArrMo1208 = this.f4669.mo1208(((AbstractC4613) ((C2781) C5495.f20773.m11132(r0)).f10706).m9730(), f4667);
        if (bArrMo1208.length <= 4096) {
            byte[] bArrMo12082 = ((InterfaceC5579) ((C0135) C2154.f8571.f8572.get()).m1249(r0, InterfaceC5579.class)).mo1208(bArr, bArr2);
            return ByteBuffer.allocate(bArrMo1208.length + 4 + bArrMo12082.length).putInt(bArrMo1208.length).put(bArrMo1208).put(bArrMo12082).array();
        }
        C1685.m4558("length of encrypted DEK too large");
        return null;
    }
}
