mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-24 11:15:47 +01:00
Update CipherCodec to try and fix issues.
This commit is contained in:
parent
f9f664f9b6
commit
3b90737273
@ -4,7 +4,6 @@ import io.netty.buffer.ByteBuf;
|
|||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.ByteToByteCodec;
|
import io.netty.handler.codec.ByteToByteCodec;
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
import javax.crypto.ShortBufferException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is a complete solution for encrypting and decoding bytes in a
|
* This class is a complete solution for encrypting and decoding bytes in a
|
||||||
@ -35,16 +34,24 @@ public class CipherCodec extends ByteToByteCodec
|
|||||||
cipher( decrypt, in, out );
|
cipher( decrypt, in, out );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cipher(Cipher cipher, ByteBuf in, ByteBuf out) throws ShortBufferException
|
private void cipher(Cipher cipher, ByteBuf in, ByteBuf out) throws Exception
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
int available = in.readableBytes();
|
int available = in.readableBytes();
|
||||||
int outputSize = cipher.getOutputSize( available );
|
int outputSize = cipher.getOutputSize( available );
|
||||||
if ( out.capacity() < outputSize )
|
int writerIndex = out.writerIndex();
|
||||||
|
if ( out.capacity() + writerIndex < outputSize )
|
||||||
{
|
{
|
||||||
out.capacity( outputSize );
|
out.capacity( outputSize + writerIndex );
|
||||||
}
|
}
|
||||||
int processed = cipher.update( in.nioBuffer(), out.nioBuffer( out.writerIndex(), outputSize ) );
|
int processed = cipher.update( in.nioBuffer(), out.nioBuffer( out.writerIndex(), outputSize ) );
|
||||||
in.readerIndex( in.readerIndex() + processed );
|
in.readerIndex( in.readerIndex() + processed );
|
||||||
out.writerIndex( out.writerIndex() + processed );
|
out.writerIndex( writerIndex + processed );
|
||||||
|
} catch ( Exception ex )
|
||||||
|
{
|
||||||
|
ex.printStackTrace();
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user