package net.minecraft.network.protocol.login;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.util.Crypt;
import net.minecraft.network.FriendlyByteBuf;
import java.security.PublicKey;
import net.minecraft.network.protocol.Packet;

public class ClientboundHelloPacket implements Packet<ClientLoginPacketListener> {
    private String serverId;
    private PublicKey publicKey;
    private byte[] nonce;
    
    public ClientboundHelloPacket() {
    }
    
    public ClientboundHelloPacket(final String string, final PublicKey publicKey, final byte[] arr) {
        this.serverId = string;
        this.publicKey = publicKey;
        this.nonce = arr;
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.serverId = kv.readUtf(20);
        this.publicKey = Crypt.byteToPublicKey(kv.readByteArray());
        this.nonce = kv.readByteArray();
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeUtf(this.serverId);
        kv.writeByteArray(this.publicKey.getEncoded());
        kv.writeByteArray(this.nonce);
    }
    
    @Override
    public void handle(final ClientLoginPacketListener rh) {
        rh.handleHello(this);
    }
    
    public String getServerId() {
        return this.serverId;
    }
    
    public PublicKey getPublicKey() {
        return this.publicKey;
    }
    
    public byte[] getNonce() {
        return this.nonce;
    }
}
