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;

/* renamed from: ᵼᵢ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C5283 implements InterfaceC2556 {

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public static final Set f19770;

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public static final byte[] f19771 = new byte[0];

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final C0863 f19772;

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final String f19773;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final AbstractC0596 f19774;

    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");
        f19770 = DesugarCollections.unmodifiableSet(hashSet);
    }

    public C5283(C4708 c4708, C0863 c0863) {
        if (!f19770.contains(c4708.m9901())) {
            C4069.m8934("Unsupported DEK key type: ", c4708.m9901(), ". Only Tink AEAD key types are supported.");
            throw null;
        }
        this.f19773 = c4708.m9901();
        C0846 c0846M9900 = C4708.m9900(c4708);
        c0846M9900.m2968(EnumC0894.f4061);
        this.f19774 = ˆᴵ.ᵨᵳʝ(((C4708) c0846M9900.m8459()).m952());
        this.f19772 = c0863;
    }

    @Override // defpackage.InterfaceC2556
    /* renamed from: ᵥᵯˎ */
    public final byte[] mo2411(byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
        ˉˇʨ r0 = C1562.f6218.m4535(this.f19774, null);
        byte[] bArrMo2411 = this.f19772.mo2411(((AbstractC2202) ((C3460) C2542.f9905.m6407(r0)).f12990).m5863(), f19771);
        if (bArrMo2411.length <= 4096) {
            byte[] bArrMo24112 = ((InterfaceC2556) ((C1885) C3011.f11597.f11598.get()).m5288(r0, InterfaceC2556.class)).mo2411(bArr, bArr2);
            return ByteBuffer.allocate(bArrMo2411.length + 4 + bArrMo24112.length).putInt(bArrMo2411.length).put(bArrMo2411).put(bArrMo24112).array();
        }
        C0910.m3048("length of encrypted DEK too large");
        return null;
    }

    @Override // defpackage.InterfaceC2556
    /* renamed from: ᵴᵳ */
    public final byte[] mo2412(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[] bArrMo2412 = this.f19772.mo2412(bArr3, f19771);
            String str = this.f19773;
            try {
                C5500 c5500 = AbstractC2202.f8641;
                return ((InterfaceC2556) ((C1885) C3011.f11597.f11598.get()).m5288(C2542.f9905.m6410(C3460.m7874(str, AbstractC2202.m5862(bArrMo2412, 0, bArrMo2412.length), EnumC3069.f11743, EnumC0894.f4061, null)), InterfaceC2556.class)).mo2412(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;
        }
    }
}
