package meerkat.crypto;

import com.google.protobuf.Message;
import meerkat.protobuf.BulletinBoardApi.MessageID;

import java.security.MessageDigest;

/**
 * Created by talm on 11/9/15.
 */
public interface Digest {
    /**
     * Completes the hash computation by performing final operations such as padding.
     * (copied from {@link MessageDigest#digest()})
     * @return
     */
    public byte[] digest();

    /**
     * Completes the hash computation and returns a MessageID Protobuf as output
     * @return
     */
    public MessageID digestAsMessageID();

    /**
     * Updates the digest using the given raw data
     * @param data contains the raw data
     */
    public void update (byte[] data);

    /**
     * Updates the digest using the specified message (in serialized wire form)
     *
     * Each message is (automatically) prepended with its length as a 32-bit big-endian unsigned integer.
     * @param msg
     * @return
     */
    public void update(Message msg);

    /**
     * Resets the digest for further use.
     */
    public void reset();

    /**
     * Clone the current digest state
     * @return
     */
    public Digest clone() throws CloneNotSupportedException;

}
