package com.jscape.inet.ssh.protocol.v2.messages;

import com.jscape.inet.ssh.protocol.messages.Message;
import com.jscape.util.HexFormat;
import com.jscape.util.net.connection.MessageConnection;

import java.math.BigInteger;
import java.security.PublicKey;

import static com.jscape.util.Parameters.assertNotNull;

/**
 * @author Alex Usun
 */
public class SshMsgKexDhGexReply
        extends Message<SshMsgKexDhGexReply.Handler> {

    public final PublicKey hostKey;
    public final BigInteger f;
    public final Signature signature;
    public byte[] hostKeyBlob;

    public SshMsgKexDhGexReply(PublicKey hostKey, BigInteger f, Signature signature) {
        assertNotNull(hostKey);
        this.hostKey = hostKey;

        assertNotNull(f);
        this.f = f;

        assertNotNull(signature);
        this.signature = signature;
    }

    @Override
    public Class handlerClass() {
        return Handler.class;
    }

    @Override
    public void accept(Handler handler, MessageConnection<Message> connection) {
        handler.handle(this, connection);
    }

    @Override
    public String toString() {
        return "SshMsgKexDhGexReply {"
               + "hostKey=" + this.hostKey
               + ", f=" + this.f
               + ", signature=" + this.signature
               + ", hostKeyBlob=" + HexFormat.formatData(this.hostKeyBlob)
               + '}';
    }

    public interface Handler
            extends Message.HandlerBase {

        void handle(SshMsgKexDhGexReply message, MessageConnection<Message> connection);

    }
}
