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

import com.jscape.util.SuppressObfuscation;

import java.util.List;

/**
 * A SSH encryption factory.
 *
 * @author Alex Usun
 */
public interface EncryptionFactory {

    /**
     * Returns supported encryption algorithms.
     *
     * @return supported encryption algorithms
     */
    List<String> encryptions();

    /**
     * Returns an encryption operation for client-server direction.
     *
     * @param name a SSH algorithm name
     * @param keyFactory a key factory
     * @param mode an encryption mode
     *
     * @return an cryption operation
     *
     * @throws OperationException if an error occurs
     */
    Encryption clientToServerEncryptionFor(String name, KeyFactory keyFactory, Mode mode)
            throws OperationException;

    /**
     * Returns an encryption operation for server-client direction.
     *
     * @param name a SSH algorithm name
     * @param keyFactory a key factory
     * @param mode an encryption mode
     *
     * @return an cryption operation
     *
     * @throws OperationException if an error occurs
     */
    Encryption serverToClientEncryptionFor(String name, KeyFactory keyFactory, Mode mode)
            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);
        }
    }

    /**
     * Algorithm mode.
     */
    enum Mode {

        ENCRYPTION,
        DECRYPTION

    }
}
