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 mg) throws IOException {
        this.serverId = mg.readUtf(20);
        this.publicKey = Crypt.byteToPublicKey(mg.readByteArray());
        this.nonce = mg.readByteArray();
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeUtf(this.serverId);
        mg.writeByteArray(this.publicKey.getEncoded());
        mg.writeByteArray(this.nonce);
    }
    
    @Override
    public void handle(final ClientLoginPacketListener sw) {
        sw.handleHello(this);
    }
    
    public String getServerId() {
        return this.serverId;
    }
    
    public PublicKey getPublicKey() {
        return this.publicKey;
    }
    
    public byte[] getNonce() {
        return this.nonce;
    }
}
