mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-05 18:32:28 +01:00
Cipher#update is copy-safe
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
30a668aa6a
commit
2ecd10a4ec
@ -92,17 +92,13 @@ public class PlayerSocketConnection extends PlayerConnection {
|
||||
// Decrypt data
|
||||
if (encrypted) {
|
||||
final Cipher cipher = decryptCipher;
|
||||
final int remainingBytes = readBuffer.readableBytes();
|
||||
final byte[] bytes = readBuffer.readRemainingBytes();
|
||||
byte[] output = new byte[cipher.getOutputSize(remainingBytes)];
|
||||
ByteBuffer input = readBuffer.asByteBuffer(0, readBuffer.writerOffset());
|
||||
try {
|
||||
cipher.update(bytes, 0, remainingBytes, output, 0);
|
||||
cipher.update(input, input.duplicate());
|
||||
} catch (ShortBufferException e) {
|
||||
MinecraftServer.getExceptionManager().handleException(e);
|
||||
return;
|
||||
}
|
||||
readBuffer.clear();
|
||||
readBuffer.writeBytes(output);
|
||||
}
|
||||
// Read all packets
|
||||
while (readBuffer.readableBytes() > 0) {
|
||||
@ -278,16 +274,11 @@ public class PlayerSocketConnection extends PlayerConnection {
|
||||
final Cipher cipher = encryptCipher;
|
||||
// Encrypt data first
|
||||
ByteBuffer cipherInput = localBuffer.asByteBuffer(0, localBuffer.writerOffset());
|
||||
BinaryBuffer pooled = PooledBuffers.get();
|
||||
ByteBuffer cipherOutput = pooled.asByteBuffer(0, pooled.capacity());
|
||||
try {
|
||||
cipher.update(cipherInput, cipherOutput);
|
||||
cipher.update(cipherInput, cipherInput.duplicate());
|
||||
} catch (ShortBufferException e) {
|
||||
MinecraftServer.getExceptionManager().handleException(e);
|
||||
}
|
||||
localBuffer.clear();
|
||||
localBuffer.write(cipherOutput.flip());
|
||||
PooledBuffers.add(pooled);
|
||||
}
|
||||
|
||||
this.waitingBuffers.add(localBuffer);
|
||||
|
Loading…
Reference in New Issue
Block a user