package meerkat.voting;

import com.google.protobuf.ByteString;
import com.google.protobuf.Message;
import meerkat.crypto.DigitalSignature;
import meerkat.protobuf.Crypto;
import meerkat.protobuf.Crypto.*;
import meerkat.protobuf.Crypto.Signature;

import java.io.IOException;
import java.io.InputStream;
import java.security.*;
import java.security.cert.CertificateException;

/**
 * Created by hai on 07/06/16.
 */
public class ToySignature implements DigitalSignature {

    private final ByteString signerID;
    private ByteString msgByteString;


    public ToySignature(String signerID) {
        this.signerID = ByteString.copyFromUtf8(signerID);
    }

    @Override
    public ByteString getSignerID() {
        return signerID;
    }

    @Override
    public SignatureVerificationKey getSignerPublicKey() {
        return null;
    }

    @Override
    public void updateContent(Message msg) throws SignatureException {
        msgByteString = msg.toByteString();
    }

    @Override
    public Signature sign() throws SignatureException {
        ByteString signature = ByteString.copyFromUtf8("Signature(")
                .concat(msgByteString)
                .concat(ByteString.copyFromUtf8(")"));
        return Signature.newBuilder()
                .setType(SignatureType.ECDSA)
                .setData(signature)
                .setSignerId(getSignerID())
                .build();
    }


    @Override
    public void loadVerificationCertificate(SignatureVerificationKey cert) throws CertificateException {
        throw new UnsupportedOperationException();
    }

    @Override
    public ByteString computeCertificateFingerprint(SignatureVerificationKey cert) throws CertificateException {
        return null;
    }

    @Override
    public void loadVerificationCertificates(InputStream certStream) throws CertificateException {
        throw new UnsupportedOperationException();
    }

    @Override
    public void clearVerificationCertificates() {
        throw new UnsupportedOperationException();
    }

    @Override
    public void updateContent(byte[] data) throws SignatureException {
        throw new UnsupportedOperationException();
    }

    @Override
    public void initVerify(Signature sig) throws CertificateException, InvalidKeyException {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean verify() {
        throw new UnsupportedOperationException();
    }

    @Override
    public KeyStore.Builder getPKCS12KeyStoreBuilder(InputStream keyStream, char[] password) throws IOException, CertificateException, KeyStoreException, NoSuchAlgorithmException {
        throw new UnsupportedOperationException();
    }

    @Override
    public void loadSigningCertificate(KeyStore.Builder keyStoreBuilder) throws IOException, CertificateException, UnrecoverableKeyException {
        throw new UnsupportedOperationException();
    }


    @Override
    public void clearSigningKey() {
        throw new UnsupportedOperationException();
    }
}
