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

import com.jscape.util.SuppressObfuscation;

import java.io.IOException;
import java.io.OutputStream;

/**
 * @author Alex Usun
 */
public interface Mac {

    Mac NULL = new Mac() {
        @Override
        public int digestLength() {
            return 0;
        }

        @Override
        public void apply(byte[] sequenceNumber, byte[] data, int offset, int length, OutputStream out) {
        }

        @Override
        public void assertMacValid(byte[] sequenceNumber, byte[] data, int offset, int length, byte[] mac) {
        }
    };

    int digestLength();

    void apply(byte[] sequenceNumber, byte[] data, int offset, int length, OutputStream out)
            throws OperationException;

    void assertMacValid(byte[] sequenceNumber, byte[] data, int offset, int length, byte[] mac)
            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);
        }
    }

    @SuppressObfuscation
    class InvalidMacException
            extends OperationException {

        public InvalidMacException() {
            super("Invalid MAC.");
        }
    }

}
