private void nextChunk() throws IOException { byteChannel.reset(); if (isByteBuf) { int copied = byteChannel.write(buf.nioBuffer()); buf.skipBytes(copied); } else { region.transferTo(byteChannel, region.transfered()); } byte[] encrypted = backend.wrap(byteChannel.getData(), 0, byteChannel.length()); this.currentChunk = ByteBuffer.wrap(encrypted); this.currentChunkSize = encrypted.length; this.currentHeader = Unpooled.copyLong(8 + currentChunkSize); this.unencryptedChunkSize = byteChannel.length(); }
private void nextChunk() throws IOException { byteChannel.reset(); if (isByteBuf) { int copied = byteChannel.write(buf.nioBuffer()); buf.skipBytes(copied); } else { region.transferTo(byteChannel, region.transfered()); } byte[] encrypted = backend.wrap(byteChannel.getData(), 0, byteChannel.length()); this.currentChunk = ByteBuffer.wrap(encrypted); this.currentChunkSize = encrypted.length; this.currentHeader = Unpooled.copyLong(8 + currentChunkSize); this.unencryptedChunkSize = byteChannel.length(); }
private void nextChunk() throws IOException { if (byteChannel == null) { byteChannel = new ByteArrayWritableChannel(maxOutboundBlockSize); } byteChannel.reset(); if (isByteBuf) { int copied = byteChannel.write(buf.nioBuffer()); buf.skipBytes(copied); } else { region.transferTo(byteChannel, region.transferred()); } byte[] encrypted = backend.wrap(byteChannel.getData(), 0, byteChannel.length()); this.currentChunk = ByteBuffer.wrap(encrypted); this.currentChunkSize = encrypted.length; this.currentHeader = Unpooled.copyLong(8 + currentChunkSize); this.unencryptedChunkSize = byteChannel.length(); }
private void nextChunk() throws IOException { if (byteChannel == null) { byteChannel = new ByteArrayWritableChannel(maxOutboundBlockSize); } byteChannel.reset(); if (isByteBuf) { int copied = byteChannel.write(buf.nioBuffer()); buf.skipBytes(copied); } else { region.transferTo(byteChannel, region.transferred()); } byte[] encrypted = backend.wrap(byteChannel.getData(), 0, byteChannel.length()); this.currentChunk = ByteBuffer.wrap(encrypted); this.currentChunkSize = encrypted.length; this.currentHeader = Unpooled.copyLong(8 + currentChunkSize); this.unencryptedChunkSize = byteChannel.length(); }
@Test public void testEncryptedMessageChunking() throws Exception { File file = File.createTempFile("sasltest", ".txt"); try { TransportConf conf = new TransportConf("shuffle", MapConfigProvider.EMPTY); byte[] data = new byte[8 * 1024]; new Random().nextBytes(data); Files.write(data, file); SaslEncryptionBackend backend = mock(SaslEncryptionBackend.class); // It doesn't really matter what we return here, as long as it's not null. when(backend.wrap(any(byte[].class), anyInt(), anyInt())).thenReturn(data); FileSegmentManagedBuffer msg = new FileSegmentManagedBuffer(conf, file, 0, file.length()); SaslEncryption.EncryptedMessage emsg = new SaslEncryption.EncryptedMessage(backend, msg.convertToNetty(), data.length / 8); ByteArrayWritableChannel channel = new ByteArrayWritableChannel(data.length); while (emsg.transfered() < emsg.count()) { channel.reset(); emsg.transferTo(channel, emsg.transfered()); } verify(backend, times(8)).wrap(any(byte[].class), anyInt(), anyInt()); } finally { file.delete(); } }
@Test public void testEncryptedMessageChunking() throws Exception { File file = File.createTempFile("sasltest", ".txt"); try { TransportConf conf = new TransportConf("shuffle", MapConfigProvider.EMPTY); byte[] data = new byte[8 * 1024]; new Random().nextBytes(data); Files.write(data, file); SaslEncryptionBackend backend = mock(SaslEncryptionBackend.class); // It doesn't really matter what we return here, as long as it's not null. when(backend.wrap(any(byte[].class), anyInt(), anyInt())).thenReturn(data); FileSegmentManagedBuffer msg = new FileSegmentManagedBuffer(conf, file, 0, file.length()); SaslEncryption.EncryptedMessage emsg = new SaslEncryption.EncryptedMessage(backend, msg.convertToNetty(), data.length / 8); ByteArrayWritableChannel channel = new ByteArrayWritableChannel(data.length); while (emsg.transfered() < emsg.count()) { channel.reset(); emsg.transferTo(channel, emsg.transfered()); } verify(backend, times(8)).wrap(any(byte[].class), anyInt(), anyInt()); } finally { file.delete(); } }
byte[] data = new byte[1024]; new Random().nextBytes(data); when(backend.wrap(any(byte[].class), anyInt(), anyInt())).thenReturn(data);
byte[] data = new byte[1024]; new Random().nextBytes(data); when(backend.wrap(any(byte[].class), anyInt(), anyInt())).thenReturn(data);