package com.jscape.inet.ssh.protocol.v2.marshaling.algorithms;

import com.jscape.util.SuppressObfuscation;

import java.io.IOException;

/**
 * A SSH encryption operation.
 *
 * @author Alex Usun
 */
public interface Encryption {

    Encryption NULL = new Encryption() {
        @Override
        public int blockLength() {
            return 8;
        }

        @Override
        public void apply(byte[] data, int offset, int length, byte[] buffer, int bufferOffset) {
            System.arraycopy(data, offset, buffer, bufferOffset, length);
        }
    };

    int blockLength();

    void apply(byte[] data, int offset, int length, byte[] buffer, int bufferOffset)
            throws OperationException;

    @SuppressObfuscation
    class OperationException
            extends IOException {

        public OperationException() {
        }

        public OperationException(String message) {
            super(message);
        }

        public OperationException(String message, Throwable cause) {
            super(message, cause);
        }

        public OperationException(Throwable cause) {
            super(cause.getMessage() != null ? cause.getMessage() : cause.toString(), cause);
        }
    }

}
