// Path: src/main/java/org/cryptomator/cryptolib/api/Cryptor.java
// public interface Cryptor extends Destroyable, AutoCloseable {
// 
// 	FileContentCryptor fileContentCryptor();
// 
// 	FileHeaderCryptor fileHeaderCryptor();
// 
// 	FileNameCryptor fileNameCryptor();
// 
// 	@Override
// 	void destroy();
// 
// 	/**
// 	 * Calls {@link #destroy()}.
// 	 */
// 	@Override
// 	default void close() {
// 		destroy();
// 	}
// 
// }
// 
// Path: src/main/java/org/cryptomator/cryptolib/api/FileHeader.java
// public interface FileHeader {
// 
// 	/**
// 	 * Returns the value of a currently unused 64 bit field in the file header.
// 	 * <p>
// 	 * Formerly used for storing the plaintext file size.
// 	 *
// 	 * @return 64 bit integer for future use.
// 	 * @deprecated Don't rely on this method. It may be redefined any time.
// 	 */
// 	@Deprecated
// 	long getReserved();
// 
// 	/**
// 	 * Sets the 64 bit field in the file header.
// 	 * <p>
// 	 * Formerly used for storing the plaintext file size.
// 	 *
// 	 * @param reserved 64 bit integer for future use
// 	 * @deprecated Don't rely on this method. It may be redefined any time.
// 	 */
// 	@Deprecated
// 	void setReserved(long reserved);
// 
// }


import org.cryptomator.cryptolib.api.Cryptor;
import org.cryptomator.cryptolib.api.FileHeader;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
package org.cryptomator.cryptolib.common;



public class EncryptingReadableByteChannel implements ReadableByteChannel {

	private final ReadableByteChannel delegate;
	private final Cryptor cryptor;
	private final FileHeader header;

	private ByteBuffer ciphertextBuffer;
	private long chunk = 0;
	private boolean reachedEof;

	/**
	 * Creates an EncryptingReadableByteChannel that encrypts a whole cleartext file beginning at its first byte.
	 *
	 * @param src          A cleartext channel positioned at its begin
	 * @param cryptor      The cryptor to use
	 */
// Path: src/main/java/org/cryptomator/cryptolib/api/Cryptor.java
// public interface Cryptor extends Destroyable, AutoCloseable {
// 
// 	FileContentCryptor fileContentCryptor();
// 
// 	FileHeaderCryptor fileHeaderCryptor();
// 
// 	FileNameCryptor fileNameCryptor();
// 
// 	@Override
// 	void destroy();
// 
// 	/**
// 	 * Calls {@link #destroy()}.
// 	 */
// 	@Override
// 	default void close() {
// 		destroy();
// 	}
// 
// }
// 
// Path: src/main/java/org/cryptomator/cryptolib/api/FileHeader.java
// public interface FileHeader {
// 
// 	/**
// 	 * Returns the value of a currently unused 64 bit field in the file header.
// 	 * <p>
// 	 * Formerly used for storing the plaintext file size.
// 	 *
// 	 * @return 64 bit integer for future use.
// 	 * @deprecated Don't rely on this method. It may be redefined any time.
// 	 */
// 	@Deprecated
// 	long getReserved();
// 
// 	/**
// 	 * Sets the 64 bit field in the file header.
// 	 * <p>
// 	 * Formerly used for storing the plaintext file size.
// 	 *
// 	 * @param reserved 64 bit integer for future use
// 	 * @deprecated Don't rely on this method. It may be redefined any time.
// 	 */
// 	@Deprecated
// 	void setReserved(long reserved);
// 
// }


// Path: src/main/java/org/cryptomator/cryptolib/common/EncryptingReadableByteChannel.java
import org.cryptomator.cryptolib.api.Cryptor;
import org.cryptomator.cryptolib.api.FileHeader;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;

package org.cryptomator.cryptolib.common;



public class EncryptingReadableByteChannel implements ReadableByteChannel {

	private final ReadableByteChannel delegate;
	private final Cryptor cryptor;
	private final FileHeader header;

	private ByteBuffer ciphertextBuffer;
	private long chunk = 0;
	private boolean reachedEof;

	/**
	 * Creates an EncryptingReadableByteChannel that encrypts a whole cleartext file beginning at its first byte.
	 *
	 * @param src          A cleartext channel positioned at its begin
	 * @param cryptor      The cryptor to use
	 */
	public EncryptingReadableByteChannel(ReadableByteChannel src, Cryptor cryptor) {