mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Distinguish between recoverable and unrecoverable errors.
This commit is contained in:
@@ -35,7 +35,8 @@ public class ConnectionReaderImplTest extends TransportTest {
|
||||
IncomingEncryptionLayer decrypter = new NullIncomingEncryptionLayer(in);
|
||||
IncomingErrorCorrectionLayer correcter =
|
||||
new NullIncomingErrorCorrectionLayer(decrypter);
|
||||
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey);
|
||||
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey,
|
||||
false);
|
||||
// There should be no bytes available before EOF
|
||||
assertEquals(-1, r.getInputStream().read());
|
||||
}
|
||||
@@ -55,7 +56,8 @@ public class ConnectionReaderImplTest extends TransportTest {
|
||||
IncomingEncryptionLayer decrypter = new NullIncomingEncryptionLayer(in);
|
||||
IncomingErrorCorrectionLayer correcter =
|
||||
new NullIncomingErrorCorrectionLayer(decrypter);
|
||||
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey);
|
||||
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey,
|
||||
false);
|
||||
// There should be one byte available before EOF
|
||||
assertEquals(0, r.getInputStream().read());
|
||||
assertEquals(-1, r.getInputStream().read());
|
||||
@@ -83,7 +85,8 @@ public class ConnectionReaderImplTest extends TransportTest {
|
||||
IncomingEncryptionLayer decrypter = new NullIncomingEncryptionLayer(in);
|
||||
IncomingErrorCorrectionLayer correcter =
|
||||
new NullIncomingErrorCorrectionLayer(decrypter);
|
||||
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey);
|
||||
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey,
|
||||
false);
|
||||
byte[] read = new byte[MAX_PAYLOAD_LENGTH];
|
||||
TestUtils.readFully(r.getInputStream(), read);
|
||||
// Try to read the second frame
|
||||
@@ -119,7 +122,8 @@ public class ConnectionReaderImplTest extends TransportTest {
|
||||
IncomingEncryptionLayer decrypter = new NullIncomingEncryptionLayer(in);
|
||||
IncomingErrorCorrectionLayer correcter =
|
||||
new NullIncomingErrorCorrectionLayer(decrypter);
|
||||
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey);
|
||||
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey,
|
||||
false);
|
||||
byte[] read = new byte[MAX_PAYLOAD_LENGTH - paddingLength];
|
||||
TestUtils.readFully(r.getInputStream(), read);
|
||||
// Try to read the second frame
|
||||
@@ -147,7 +151,8 @@ public class ConnectionReaderImplTest extends TransportTest {
|
||||
IncomingEncryptionLayer decrypter = new NullIncomingEncryptionLayer(in);
|
||||
IncomingErrorCorrectionLayer correcter =
|
||||
new NullIncomingErrorCorrectionLayer(decrypter);
|
||||
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey);
|
||||
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey,
|
||||
false);
|
||||
// The non-zero padding should be rejected
|
||||
try {
|
||||
r.getInputStream().read();
|
||||
@@ -181,7 +186,8 @@ public class ConnectionReaderImplTest extends TransportTest {
|
||||
IncomingEncryptionLayer decrypter = new NullIncomingEncryptionLayer(in);
|
||||
IncomingErrorCorrectionLayer correcter =
|
||||
new NullIncomingErrorCorrectionLayer(decrypter);
|
||||
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey);
|
||||
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey,
|
||||
false);
|
||||
byte[] read = new byte[payloadLength];
|
||||
TestUtils.readFully(r.getInputStream(), read);
|
||||
assertArrayEquals(new byte[payloadLength], read);
|
||||
@@ -207,7 +213,8 @@ public class ConnectionReaderImplTest extends TransportTest {
|
||||
IncomingEncryptionLayer decrypter = new NullIncomingEncryptionLayer(in);
|
||||
IncomingErrorCorrectionLayer correcter =
|
||||
new NullIncomingErrorCorrectionLayer(decrypter);
|
||||
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey);
|
||||
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey,
|
||||
false);
|
||||
try {
|
||||
r.getInputStream().read();
|
||||
fail();
|
||||
@@ -231,7 +238,8 @@ public class ConnectionReaderImplTest extends TransportTest {
|
||||
IncomingEncryptionLayer decrypter = new NullIncomingEncryptionLayer(in);
|
||||
IncomingErrorCorrectionLayer correcter =
|
||||
new NullIncomingErrorCorrectionLayer(decrypter);
|
||||
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey);
|
||||
ConnectionReader r = new ConnectionReaderImpl(correcter, mac, macKey,
|
||||
false);
|
||||
try {
|
||||
r.getInputStream().read();
|
||||
fail();
|
||||
|
||||
@@ -98,7 +98,7 @@ public class FrameReadWriteTest extends BriarTestCase {
|
||||
IncomingErrorCorrectionLayer correcter1 =
|
||||
new NullIncomingErrorCorrectionLayer(decrypter);
|
||||
ConnectionReader reader = new ConnectionReaderImpl(correcter1, mac,
|
||||
macKey);
|
||||
macKey, false);
|
||||
InputStream in1 = reader.getInputStream();
|
||||
byte[] recovered = new byte[frame.length];
|
||||
int offset = 0;
|
||||
|
||||
@@ -39,7 +39,7 @@ class NullIncomingEncryptionLayer implements IncomingEncryptionLayer {
|
||||
int padding = HeaderEncoder.getPaddingLength(buf);
|
||||
length = FRAME_HEADER_LENGTH + payload + padding + MAC_LENGTH;
|
||||
if(length > MAX_FRAME_LENGTH) throw new FormatException();
|
||||
// Read the remainder of the frame/segment
|
||||
// Read the remainder of the frame
|
||||
while(offset < length) {
|
||||
int read = in.read(buf, offset, length - offset);
|
||||
if(read == -1) throw new EOFException();
|
||||
|
||||
Reference in New Issue
Block a user