package okio;

/* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
/* JADX INFO: loaded from: E:\ios\vf_dex\classes3.dex */
@kotlin.Metadata(d1 = {"\u0000F\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0010\b\n\u0002\b\u0005\n\u0002\u0010\u000b\n\u0002\b\u0005\u0018\u00002\u00020\u0001J\u000f\u0010\u0003\u001a\u00020\u0002H\u0002¢\u0006\u0004\b\u0003\u0010\u0004J\u000f\u0010\u0005\u001a\u00020\u0002H\u0002¢\u0006\u0004\b\u0005\u0010\u0004J\u000f\u0010\u0006\u001a\u00020\u0002H\u0002¢\u0006\u0004\b\u0006\u0010\u0004J\u001f\u0010\u000b\u001a\u00020\t2\u0006\u0010\b\u001a\u00020\u00072\u0006\u0010\n\u001a\u00020\tH\u0016¢\u0006\u0004\b\u000b\u0010\fJ\u000f\u0010\u000e\u001a\u00020\rH\u0016¢\u0006\u0004\b\u000e\u0010\u000fJ\u000f\u0010\u0010\u001a\u00020\u0002H\u0016¢\u0006\u0004\b\u0010\u0010\u0004R\u0014\u0010\u0013\u001a\u00020\u00118\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0006\u0010\u0012R\u0017\u0010\u0019\u001a\u00020\u00148\u0006¢\u0006\f\n\u0004\b\u0015\u0010\u0016\u001a\u0004\b\u0017\u0010\u0018R\u0014\u0010\u001d\u001a\u00020\u001a8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u001b\u0010\u001cR\u0014\u0010\u001f\u001a\u00020\u00078\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0003\u0010\u001eR\u0016\u0010\"\u001a\u00020 8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b\u0005\u0010!R\u0016\u0010$\u001a\u00020 8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b#\u0010!¨\u0006%"}, d2 = {"Lokio/CipherSource;", "Lokio/Source;", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "d", "()V", "e", "a", "Lokio/Buffer;", "sink", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "byteCount", "read", "(Lokio/Buffer;J)J", "Lokio/Timeout;", "timeout", "()Lokio/Timeout;", "close", "Lokio/BufferedSource;", "Lokio/BufferedSource;", "source", "Ljavax/crypto/Cipher;", "b", "Ljavax/crypto/Cipher;", "getCipher", "()Ljavax/crypto/Cipher;", "cipher", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "c", "I", "blockSize", "Lokio/Buffer;", "buffer", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "Z", "final", "f", "closed", "okio"}, k = 1, mv = {1, 9, 0}, xi = 48)
@kotlin.jvm.internal.SourceDebugExtension
public final class CipherSource implements okio.Source {

    /* JADX INFO: renamed from: a, reason: from kotlin metadata */
    private final okio.BufferedSource source;

    /* JADX INFO: renamed from: b, reason: from kotlin metadata */
    private final javax.crypto.Cipher cipher;

    /* JADX INFO: renamed from: c, reason: from kotlin metadata */
    private final int blockSize;

    /* JADX INFO: renamed from: d, reason: from kotlin metadata */
    private final okio.Buffer buffer;

    /* JADX INFO: renamed from: e, reason: from kotlin metadata */
    private boolean final;

    /* JADX INFO: renamed from: f, reason: from kotlin metadata */
    private boolean closed;

    private final void a() throws javax.crypto.BadPaddingException, javax.crypto.IllegalBlockSizeException, javax.crypto.ShortBufferException {
        int outputSize = this.cipher.getOutputSize(0);
        if (outputSize == 0) {
            return;
        }
        okio.Segment segmentZ0 = this.buffer.z0(outputSize);
        int iDoFinal = this.cipher.doFinal(segmentZ0.data, segmentZ0.pos);
        segmentZ0.limit += iDoFinal;
        okio.Buffer buffer = this.buffer;
        buffer.n0(buffer.getSize() + ((long) iDoFinal));
        if (segmentZ0.pos == segmentZ0.limit) {
            this.buffer.head = segmentZ0.b();
            okio.SegmentPool.b(segmentZ0);
        }
    }

    private final void d() throws javax.crypto.BadPaddingException, javax.crypto.IllegalBlockSizeException, javax.crypto.ShortBufferException {
        while (this.buffer.getSize() == 0 && !this.final) {
            if (this.source.m2()) {
                this.final = true;
                a();
                return;
            }
            e();
        }
    }

    private final void e() throws javax.crypto.BadPaddingException, javax.crypto.IllegalBlockSizeException, javax.crypto.ShortBufferException {
        okio.Segment segment = this.source.g().head;
        kotlin.jvm.internal.Intrinsics.i(segment);
        int i = segment.limit - segment.pos;
        int outputSize = this.cipher.getOutputSize(i);
        int i2 = i;
        while (outputSize > 8192) {
            int i5 = this.blockSize;
            if (i2 <= i5) {
                this.final = true;
                okio.Buffer buffer = this.buffer;
                byte[] bArrDoFinal = this.cipher.doFinal(this.source.x0());
                kotlin.jvm.internal.Intrinsics.k(bArrDoFinal, "doFinal(...)");
                buffer.write(bArrDoFinal);
                return;
            }
            i2 -= i5;
            outputSize = this.cipher.getOutputSize(i2);
        }
        okio.Segment segmentZ0 = this.buffer.z0(outputSize);
        int iUpdate = this.cipher.update(segment.data, segment.pos, i2, segmentZ0.data, segmentZ0.pos);
        this.source.skip(i2);
        segmentZ0.limit += iUpdate;
        okio.Buffer buffer2 = this.buffer;
        buffer2.n0(buffer2.getSize() + ((long) iUpdate));
        if (segmentZ0.pos == segmentZ0.limit) {
            this.buffer.head = segmentZ0.b();
            okio.SegmentPool.b(segmentZ0);
        }
    }

    @Override // okio.Source, java.io.Closeable, java.lang.AutoCloseable
    public void close() {
        this.closed = true;
        this.source.close();
    }

    @Override // okio.Source
    public long read(okio.Buffer sink, long byteCount) throws javax.crypto.BadPaddingException, javax.crypto.IllegalBlockSizeException, javax.crypto.ShortBufferException {
        kotlin.jvm.internal.Intrinsics.l(sink, "sink");
        if (byteCount < 0) {
            throw new java.lang.IllegalArgumentException(("byteCount < 0: " + byteCount).toString());
        }
        if (this.closed) {
            throw new java.lang.IllegalStateException("closed");
        }
        if (byteCount == 0) {
            return 0L;
        }
        d();
        return this.buffer.read(sink, byteCount);
    }

    @Override // okio.Source
    /* JADX INFO: renamed from: timeout */
    public okio.Timeout getTimeout() {
        return this.source.getTimeout();
    }
}
