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

import com.jscape.util.SuppressObfuscation;

import java.util.List;

/**
 * A SSH MAC factory.
 *
 * @author Alex Usun
 */
public interface MacFactory {

    /**
     * Returns supported MAC algorithms.
     *
     * @return supported MAC algorithms
     */
    List<String> macs();

    /**
     * Returns a MAC operation for client-server direction.
     *
     * @param name a SSH algorithm name
     * @param keyFactory a key factory
     *
     * @return a MAC operation
     *
     * @throws OperationException if an error occurs
     */
    Mac clientToServerMacFor(String name, KeyFactory keyFactory)
            throws OperationException;

    /**
     * Returns a MAC operation for server-client direction.
     *
     * @param name a SSH algorithm name
     * @param keyFactory a key factory
     *
     * @return a MAC operation
     *
     * @throws OperationException if an error occurs
     */
    Mac serverToClientMacFor(String name, KeyFactory keyFactory)
            throws OperationException;

    /**
     * Represents an operation error.
     */
    @SuppressObfuscation
    class OperationException
            extends Exception {

        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);
        }
    }
}
