    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.io.DataInputStream;
    006    import java.io.DataOutputStream;
    007    import java.io.IOException;
    008    import java.security.PrivateKey;
    009    import java.security.PublicKey;
    010    import javax.crypto.SecretKey;
    011
    012    public class Packet252SharedKey extends Packet
    013    {
    014        private byte[] sharedSecret = new byte[0];
    015        private byte[] verifyToken = new byte[0];
    016        private SecretKey field_73306_c;
    017
    018        public Packet252SharedKey() {}
    019
    020        @SideOnly(Side.CLIENT)
    021        public Packet252SharedKey(SecretKey par1SecretKey, PublicKey par2PublicKey, byte[] par3ArrayOfByte)
    022        {
    023            this.field_73306_c = par1SecretKey;
    024            this.sharedSecret = CryptManager.func_75894_a(par2PublicKey, par1SecretKey.getEncoded());
    025            this.verifyToken = CryptManager.func_75894_a(par2PublicKey, par3ArrayOfByte);
    026        }
    027
    028        /**
    029         * Abstract. Reads the raw packet data from the data stream.
    030         */
    031        public void readPacketData(DataInputStream par1DataInputStream) throws IOException
    032        {
    033            this.sharedSecret = readBytesFromStream(par1DataInputStream);
    034            this.verifyToken = readBytesFromStream(par1DataInputStream);
    035        }
    036
    037        /**
    038         * Abstract. Writes the raw packet data to the data stream.
    039         */
    040        public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
    041        {
    042            writeByteArray(par1DataOutputStream, this.sharedSecret);
    043            writeByteArray(par1DataOutputStream, this.verifyToken);
    044        }
    045
    046        /**
    047         * Passes this Packet on to the NetHandler for processing.
    048         */
    049        public void processPacket(NetHandler par1NetHandler)
    050        {
    051            par1NetHandler.handleSharedKey(this);
    052        }
    053
    054        /**
    055         * Abstract. Return the size of the packet (not counting the header).
    056         */
    057        public int getPacketSize()
    058        {
    059            return 2 + this.sharedSecret.length + 2 + this.verifyToken.length;
    060        }
    061
    062        public SecretKey func_73303_a(PrivateKey par1PrivateKey)
    063        {
    064            return par1PrivateKey == null ? this.field_73306_c : (this.field_73306_c = CryptManager.func_75887_a(par1PrivateKey, this.sharedSecret));
    065        }
    066
    067        public SecretKey func_73304_d()
    068        {
    069            return this.func_73303_a((PrivateKey)null);
    070        }
    071
    072        public byte[] func_73302_b(PrivateKey par1PrivateKey)
    073        {
    074            return par1PrivateKey == null ? this.verifyToken : CryptManager.func_75889_b(par1PrivateKey, this.verifyToken);
    075        }
    076    }