package meerkat.crypto;

import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Message;

import java.io.IOException;
import java.util.Random;

import static meerkat.protobuf.Crypto.*;

/**
 * Created by talm on 11/2/15.
 */
public interface Encryption {
    /**
     * Encrypt the serialized form of a message plaintext.
     * @param plaintext
     * @param rnd
     * @return
     */
    RerandomizableEncryptedMessage encrypt(Message plaintext, EncryptionRandomness rnd) throws IOException; // TODO: type of exception; throws


    /**
     * Rerandomize a ciphertext using the supplied randomness.
     * @param msg
     * @param rnd
     * @return
     * @throws InvalidProtocolBufferException
     */
    RerandomizableEncryptedMessage rerandomize(RerandomizableEncryptedMessage msg, EncryptionRandomness rnd) throws InvalidProtocolBufferException;

    /**
     * Generate randomness compatible with {@link #encrypt(Message, EncryptionRandomness) and
     * {@link #rerandomize(RerandomizableEncryptedMessage, EncryptionRandomness)}}.
     * @param rand
     * @return
     */
    EncryptionRandomness generateRandomness(Random rand);
}
