diff --git a/pom.xml b/pom.xml
index 0d8dfef1..8954e267 100644
--- a/pom.xml
+++ b/pom.xml
@@ -59,7 +59,7 @@
unknown
- 4.0.0.CR3
+ 4.0.0.CR6
UTF-8
diff --git a/proxy/src/main/java/net/md_5/bungee/netty/CipherBase.java b/proxy/src/main/java/net/md_5/bungee/netty/CipherBase.java
index f5999cdc..0c12c18c 100644
--- a/proxy/src/main/java/net/md_5/bungee/netty/CipherBase.java
+++ b/proxy/src/main/java/net/md_5/bungee/netty/CipherBase.java
@@ -1,6 +1,7 @@
package net.md_5.bungee.netty;
import io.netty.buffer.ByteBuf;
+import io.netty.channel.ChannelHandlerContext;
import javax.crypto.Cipher;
import javax.crypto.ShortBufferException;
import lombok.AccessLevel;
@@ -31,7 +32,7 @@ public class CipherBase
}
}
- protected void cipher(ByteBuf in, ByteBuf out) throws ShortBufferException
+ private byte[] bufToByte(ByteBuf in)
{
byte[] heapIn = heapInLocal.get();
int readableBytes = in.readableBytes();
@@ -41,6 +42,24 @@ public class CipherBase
heapInLocal.set( heapIn );
}
in.readBytes( heapIn, 0, readableBytes );
+ return heapIn;
+ }
+
+ protected ByteBuf cipher(ChannelHandlerContext ctx, ByteBuf in) throws ShortBufferException
+ {
+ int readableBytes = in.readableBytes();
+ byte[] heapIn = bufToByte( in );
+
+ ByteBuf heapOut = ctx.alloc().heapBuffer( cipher.getOutputSize( readableBytes ) );
+ heapOut.writerIndex( cipher.update( heapIn, 0, readableBytes, heapOut.array(), heapOut.arrayOffset() ));
+
+ return heapOut;
+ }
+
+ protected void cipher(ByteBuf in, ByteBuf out) throws ShortBufferException
+ {
+ int readableBytes = in.readableBytes();
+ byte[] heapIn = bufToByte( in );
byte[] heapOut = heapOutLocal.get();
int outputSize = cipher.getOutputSize( readableBytes );
diff --git a/proxy/src/main/java/net/md_5/bungee/netty/CipherDecoder.java b/proxy/src/main/java/net/md_5/bungee/netty/CipherDecoder.java
index cc4055b3..91fba349 100644
--- a/proxy/src/main/java/net/md_5/bungee/netty/CipherDecoder.java
+++ b/proxy/src/main/java/net/md_5/bungee/netty/CipherDecoder.java
@@ -2,10 +2,11 @@ package net.md_5.bungee.netty;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
-import io.netty.handler.codec.ByteToByteDecoder;
+import io.netty.channel.MessageList;
+import io.netty.handler.codec.MessageToMessageDecoder;
import javax.crypto.Cipher;
-public class CipherDecoder extends ByteToByteDecoder
+public class CipherDecoder extends MessageToMessageDecoder
{
private final CipherBase cipher;
@@ -16,8 +17,8 @@ public class CipherDecoder extends ByteToByteDecoder
}
@Override
- protected void decode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception
+ protected void decode(ChannelHandlerContext ctx, ByteBuf msg, MessageList