package F0;

import android.net.Uri;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import z0.y;

/* JADX INFO: loaded from: classes.dex */
public final class a implements z0.h {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final z0.h f2252q;

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

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

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public CipherInputStream f2255t;

    public a(z0.h hVar, byte[] bArr, byte[] bArr2) {
        this.f2252q = hVar;
        this.f2253r = bArr;
        this.f2254s = bArr2;
    }

    @Override // z0.h
    public final void close() {
        if (this.f2255t != null) {
            this.f2255t = null;
            this.f2252q.close();
        }
    }

    @Override // z0.h
    public final Uri e() {
        return this.f2252q.e();
    }

    @Override // z0.h
    public final long g(z0.k kVar) {
        try {
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
            try {
                cipher.init(2, new SecretKeySpec(this.f2253r, "AES"), new IvParameterSpec(this.f2254s));
                z0.j jVar = new z0.j(this.f2252q, kVar);
                this.f2255t = new CipherInputStream(jVar, cipher);
                jVar.a();
                return -1L;
            } catch (InvalidAlgorithmParameterException | InvalidKeyException e8) {
                throw new RuntimeException(e8);
            }
        } catch (NoSuchAlgorithmException | NoSuchPaddingException e9) {
            throw new RuntimeException(e9);
        }
    }

    @Override // z0.h
    public final void k(y yVar) {
        yVar.getClass();
        this.f2252q.k(yVar);
    }

    @Override // z0.h
    public final Map m() {
        return this.f2252q.m();
    }

    @Override // u0.InterfaceC1571g
    public final int p(byte[] bArr, int i, int i5) throws IOException {
        this.f2255t.getClass();
        int i8 = this.f2255t.read(bArr, i, i5);
        if (i8 < 0) {
            return -1;
        }
        return i8;
    }
}
