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 SshMsgUserAuthRequestPublicKey
        extends SshMsgUserAuthRequest<SshMsgUserAuthRequestPublicKey.Handler> {

    public final String publicKeyAlgorithm;
    public final PublicKey publicKey;

    public SshMsgUserAuthRequestPublicKey(String username, String serviceName, String publicKeyAlgorithm, PublicKey publicKey) {
        super(username, serviceName);

        assertNotNull(publicKeyAlgorithm);
        this.publicKeyAlgorithm = publicKeyAlgorithm;

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

    @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 "SshMsgUserAuthRequestPublicKey {"
                + "username='" + this.username + '\''
                + ", serviceName='" + this.serviceName + '\''
                + ", publicKeyAlgorithm='" + this.publicKeyAlgorithm + '\''
                + ", publicKey=" + this.publicKey
                + '}';
    }

    public interface Handler
            extends Message.HandlerBase {

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

    }
}
