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

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

import java.security.PublicKey;

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

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

    public final String publicKeyAlgorithm;
    public final PublicKey publicKey;

    public SshMsgUserAuthPkOk(String publicKeyAlgorithm, PublicKey publicKey) {
        assertNotNull(publicKeyAlgorithm);
        this.publicKeyAlgorithm = publicKeyAlgorithm;

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

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

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

    @Override
    public String toString() {
        return "SshMsgUserAuthPkOk {"
                + "publicKeyAlgorithm='" + this.publicKeyAlgorithm + '\''
                + ", publicKey=" + this.publicKey
                + '}';
    }

    public interface Handler
            extends Message.HandlerBase {

        void handle(SshMsgUserAuthPkOk message, MessageConnection connection);

    }
}
