CipherBase.java
net.minecraft.network.CipherBase
信息
- 全限定名:net.minecraft.network.CipherBase
- 类型:public class
- 包:net.minecraft.network
- 源码路径:src/main/java/net/minecraft/network/CipherBase.java
- 起始行号:L8
- 职责:
TODO
字段/常量
-
cipher- 类型:
Cipher - 修饰符:
private final - 源码定位:
L9 - 说明:
TODO
- 类型:
-
heapIn- 类型:
byte[] - 修饰符:
private - 源码定位:
L10 - 说明:
TODO
- 类型:
-
heapOut- 类型:
byte[] - 修饰符:
private - 源码定位:
L11 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
protected CipherBase(Cipher cipher) @ L13
- 构造器名:CipherBase
- 源码定位:L13
- 修饰符:protected
参数:
- cipher: Cipher
说明:
TODO
方法
下面的方法块按源码顺序生成。
private byte[] bufToByte(ByteBuf in) @ L17
- 方法名:bufToByte
- 源码定位:L17
- 返回类型:byte[]
- 修饰符:private
参数:
- in: ByteBuf
说明:
TODO
protected ByteBuf decipher(ChannelHandlerContext ctx, ByteBuf in) @ L27
- 方法名:decipher
- 源码定位:L27
- 返回类型:ByteBuf
- 修饰符:protected
参数:
- ctx: ChannelHandlerContext
- in: ByteBuf
说明:
TODO
protected void encipher(ByteBuf in, ByteBuf out) @ L35
- 方法名:encipher
- 源码定位:L35
- 返回类型:void
- 修饰符:protected
参数:
- in: ByteBuf
- out: ByteBuf
说明:
TODO
代码
public class CipherBase {
private final Cipher cipher;
private byte[] heapIn = new byte[0];
private byte[] heapOut = new byte[0];
protected CipherBase(Cipher cipher) {
this.cipher = cipher;
}
private byte[] bufToByte(ByteBuf in) {
int readableBytes = in.readableBytes();
if (this.heapIn.length < readableBytes) {
this.heapIn = new byte[readableBytes];
}
in.readBytes(this.heapIn, 0, readableBytes);
return this.heapIn;
}
protected ByteBuf decipher(ChannelHandlerContext ctx, ByteBuf in) throws ShortBufferException {
int readableBytes = in.readableBytes();
byte[] heapIn = this.bufToByte(in);
ByteBuf heapOut = ctx.alloc().heapBuffer(this.cipher.getOutputSize(readableBytes));
heapOut.writerIndex(this.cipher.update(heapIn, 0, readableBytes, heapOut.array(), heapOut.arrayOffset()));
return heapOut;
}
protected void encipher(ByteBuf in, ByteBuf out) throws ShortBufferException {
int readableBytes = in.readableBytes();
byte[] heapIn = this.bufToByte(in);
int outputSize = this.cipher.getOutputSize(readableBytes);
if (this.heapOut.length < outputSize) {
this.heapOut = new byte[outputSize];
}
out.writeBytes(this.heapOut, 0, this.cipher.update(heapIn, 0, readableBytes, this.heapOut));
}
}引用的其他类
- 无