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

    public final String publicKeyAlgorithm;
    public final PublicKey publicKey;
    public final Signature signature;

    public SshMsgUserAuthRequestPublicKeySignature(String username,
                                                   String serviceName,
                                                   String publicKeyAlgorithm,
                                                   PublicKey publicKey,
                                                   Signature signature) {
        super(username, serviceName);

        assertNotNull(publicKeyAlgorithm);
        this.publicKeyAlgorithm = publicKeyAlgorithm;

        assertNotNull(publicKey);
        this.publicKey = publicKey;

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

    public interface Handler
            extends Message.HandlerBase {

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

    }
}
