/*
 * @(#)Signer.java
 *
 * Copyright (c) 2002-2003 JSCAPE
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JSCAPE. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 * the terms of the license agreement you entered into with JSCAPE.
 */

package com.jscape.crypto;

/**
 * Represents a data signer/verifier.
 *
 * @author Alex Usun
 */
public interface Signer {

    /**
     * Signs the specified data.
     *
     * @param data a data to sign
     *
     * @return a data signature
     *
     * @throws com.jscape.crypto.Signer.OperationException
     *          if an operation error occurs
     */
    byte[] sign(byte[] data)
            throws OperationException;

    /**
     * Verifies data signature.
     *
     * @param data      a data to verify
     * @param signature a data signature
     *
     * @return <code>true</code> if signature is valid; <code>false</code> otherwise
     *
     * @throws com.jscape.crypto.Signer.OperationException
     *          if an operation error occurs
     */
    boolean verify(byte[] data, byte[] signature)
            throws OperationException;


    class OperationException
            extends RuntimeException {

        /**
         * {@inheritDoc}
         */
        public OperationException() {
        }

        /**
         * {@inheritDoc}
         */
        public OperationException(String message) {
            super(message);
        }

        /**
         * {@inheritDoc}
         */
        public OperationException(String message, Throwable cause) {
            super(message, cause);
        }

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