NettyEncryptionTranslator .java

net.minecraft.network.NettyEncryptionTranslator (class, 55 lines): members: field_150505_b, field_150506_c, decipher, cipher. imports: ByteBuf.

net.minecraft.networkclass55 linescommon1.6 KB

API Surface (2)

ByteBuf decipher(ChannelHandlerContext ctx, ByteBuf buffer)
void cipher(ByteBuf in, ByteBuf out)

Fields & Constants (3)

cipher
field_150505_b
field_150506_c

Full Source

NettyEncryptionTranslator.java55 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.network;
2
3
import io.netty.buffer.ByteBuf;
4
import io.netty.channel.ChannelHandlerContext;
5
import javax.crypto.Cipher;
6
import javax.crypto.ShortBufferException;
7
8
public class NettyEncryptionTranslator
9
{
10
    private final Cipher cipher;
11
    private byte[] field_150505_b = new byte[0];
12
    private byte[] field_150506_c = new byte[0];
13
14
    protected NettyEncryptionTranslator(Cipher cipherIn)
15
    {
16
        this.cipher = cipherIn;
17
    }
18
19
    private byte[] func_150502_a(ByteBuf buf)
20
    {
21
        int i = buf.readableBytes();
22
23
        if (this.field_150505_b.length < i)
24
        {
25
            this.field_150505_b = new byte[i];
26
        }
27
28
        buf.readBytes((byte[])this.field_150505_b, 0, i);
29
        return this.field_150505_b;
30
    }
31
32
    protected ByteBuf decipher(ChannelHandlerContext ctx, ByteBuf buffer) throws ShortBufferException
33
    {
34
        int i = buffer.readableBytes();
35
        byte[] abyte = this.func_150502_a(buffer);
36
        ByteBuf bytebuf = ctx.alloc().heapBuffer(this.cipher.getOutputSize(i));
37
        bytebuf.writerIndex(this.cipher.update(abyte, 0, i, bytebuf.array(), bytebuf.arrayOffset()));
38
        return bytebuf;
39
    }
40
41
    protected void cipher(ByteBuf in, ByteBuf out) throws ShortBufferException
42
    {
43
        int i = in.readableBytes();
44
        byte[] abyte = this.func_150502_a(in);
45
        int j = this.cipher.getOutputSize(i);
46
47
        if (this.field_150506_c.length < j)
48
        {
49
            this.field_150506_c = new byte[j];
50
        }
51
52
        out.writeBytes((byte[])this.field_150506_c, 0, this.cipher.update(abyte, 0, i, this.field_150506_c));
53
    }
54
}
55

Deobfuscated MCP 1.8.9 source of NettyEncryptionTranslator from Marcelektro/MavenMCP-1.8.9 (net/minecraft/network/NettyEncryptionTranslator.java), stored verbatim.