Whitespace-only code formatting changes.

This commit is contained in:
akwizgran
2015-11-30 09:38:25 +00:00
parent 1950c13ffb
commit 027ae8340f
202 changed files with 2993 additions and 2993 deletions

View File

@@ -43,13 +43,13 @@ public class KeyManagerImplTest extends BriarTestCase {
secret2 = new byte[32];
secret3 = new byte[32];
secret4 = new byte[32];
for(int i = 0; i < secret0.length; i++) secret0[i] = 1;
for(int i = 0; i < secret1.length; i++) secret1[i] = 2;
for(int i = 0; i < secret2.length; i++) secret2[i] = 3;
for(int i = 0; i < secret3.length; i++) secret3[i] = 4;
for(int i = 0; i < secret4.length; i++) secret4[i] = 5;
for (int i = 0; i < secret0.length; i++) secret0[i] = 1;
for (int i = 0; i < secret1.length; i++) secret1[i] = 2;
for (int i = 0; i < secret2.length; i++) secret2[i] = 3;
for (int i = 0; i < secret3.length; i++) secret3[i] = 4;
for (int i = 0; i < secret4.length; i++) secret4[i] = 5;
initialSecret = new byte[32];
for(int i = 0; i < initialSecret.length; i++) initialSecret[i] = 123;
for (int i = 0; i < initialSecret.length; i++) initialSecret[i] = 123;
}
@Test

View File

@@ -51,11 +51,11 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
secret2 = new byte[32];
secret3 = new byte[32];
secret4 = new byte[32];
for(int i = 0; i < secret0.length; i++) secret0[i] = 1;
for(int i = 0; i < secret1.length; i++) secret1[i] = 2;
for(int i = 0; i < secret2.length; i++) secret2[i] = 3;
for(int i = 0; i < secret3.length; i++) secret3[i] = 4;
for(int i = 0; i < secret4.length; i++) secret4[i] = 5;
for (int i = 0; i < secret0.length; i++) secret0[i] = 1;
for (int i = 0; i < secret1.length; i++) secret1[i] = 2;
for (int i = 0; i < secret2.length; i++) secret2[i] = 3;
for (int i = 0; i < secret3.length; i++) secret3[i] = 4;
for (int i = 0; i < secret4.length; i++) secret4[i] = 5;
key0 = new byte[32];
key1 = new byte[32];
key2 = new byte[32];
@@ -66,13 +66,13 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
k2 = new SecretKey(key2);
k3 = new SecretKey(key3);
k4 = new SecretKey(key4);
for(int i = 0; i < key0.length; i++) key0[i] = 1;
for(int i = 0; i < key1.length; i++) key1[i] = 2;
for(int i = 0; i < key2.length; i++) key2[i] = 3;
for(int i = 0; i < key3.length; i++) key3[i] = 4;
for(int i = 0; i < key4.length; i++) key4[i] = 5;
for (int i = 0; i < key0.length; i++) key0[i] = 1;
for (int i = 0; i < key1.length; i++) key1[i] = 2;
for (int i = 0; i < key2.length; i++) key2[i] = 3;
for (int i = 0; i < key3.length; i++) key3[i] = 4;
for (int i = 0; i < key4.length; i++) key4[i] = 5;
initialSecret = new byte[32];
for(int i = 0; i < initialSecret.length; i++) initialSecret[i] = 123;
for (int i = 0; i < initialSecret.length; i++) initialSecret[i] = 123;
}
@Test
@@ -154,7 +154,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 0
oneOf(crypto).deriveTagKey(secret0, false);
will(returnValue(k0));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
with((long) i));
will(new EncodeTagAction());
@@ -162,7 +162,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 1
oneOf(crypto).deriveTagKey(secret1, false);
will(returnValue(k1));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
with((long) i));
will(new EncodeTagAction());
@@ -170,7 +170,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -179,7 +179,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 0
oneOf(crypto).deriveTagKey(secret0, false);
will(returnValue(k0));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
with((long) i));
will(new EncodeTagAction());
@@ -187,7 +187,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 1
oneOf(crypto).deriveTagKey(secret1, false);
will(returnValue(k1));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
with((long) i));
will(new EncodeTagAction());
@@ -195,7 +195,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -256,7 +256,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 0
oneOf(crypto).deriveTagKey(secret0, false);
will(returnValue(k0));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
with((long) i));
will(new EncodeTagAction());
@@ -264,7 +264,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 1
oneOf(crypto).deriveTagKey(secret1, false);
will(returnValue(k1));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
with((long) i));
will(new EncodeTagAction());
@@ -272,7 +272,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -284,7 +284,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 0
oneOf(crypto).deriveTagKey(secret0, false);
will(returnValue(k0));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
with((long) i));
will(new EncodeTagAction());
@@ -292,7 +292,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 1
oneOf(crypto).deriveTagKey(secret1, false);
will(returnValue(k1));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
with((long) i));
will(new EncodeTagAction());
@@ -300,7 +300,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -369,7 +369,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 0
oneOf(crypto).deriveTagKey(secret0, false);
will(returnValue(k0));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
with((long) i));
will(new EncodeTagAction());
@@ -377,7 +377,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 1
oneOf(crypto).deriveTagKey(secret1, false);
will(returnValue(k1));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
with((long) i));
will(new EncodeTagAction());
@@ -385,7 +385,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -402,7 +402,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 0
oneOf(crypto).deriveTagKey(secret0, false);
will(returnValue(k0));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
with((long) i));
will(new EncodeTagAction());
@@ -410,7 +410,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 1
oneOf(crypto).deriveTagKey(secret1, false);
will(returnValue(k1));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
with((long) i));
will(new EncodeTagAction());
@@ -418,7 +418,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the updated tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 1; i < 17; i++) {
for (int i = 1; i < 17; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -478,7 +478,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 0
oneOf(crypto).deriveTagKey(secret0, false);
will(returnValue(k0));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
with((long) i));
will(new EncodeTagAction());
@@ -486,7 +486,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 1
oneOf(crypto).deriveTagKey(secret1, false);
will(returnValue(k1));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
with((long) i));
will(new EncodeTagAction());
@@ -494,7 +494,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -506,7 +506,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should remove the tags for period 0
oneOf(crypto).deriveTagKey(secret0, false);
will(returnValue(k0));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
with((long) i));
will(new EncodeTagAction());
@@ -514,7 +514,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 1
oneOf(crypto).deriveTagKey(secret1, false);
will(returnValue(k1));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
with((long) i));
will(new EncodeTagAction());
@@ -522,7 +522,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -581,7 +581,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 1
oneOf(crypto).deriveTagKey(secret1, false);
will(returnValue(k1));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
with((long) i));
will(new EncodeTagAction());
@@ -589,7 +589,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -597,7 +597,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 3
oneOf(crypto).deriveTagKey(secret3, false);
will(returnValue(k3));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k3),
with((long) i));
will(new EncodeTagAction());
@@ -609,7 +609,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 1
oneOf(crypto).deriveTagKey(secret1, false);
will(returnValue(k1));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
with((long) i));
will(new EncodeTagAction());
@@ -617,7 +617,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -625,7 +625,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should remove the tags for period 3
oneOf(crypto).deriveTagKey(secret3, false);
will(returnValue(k3));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k3),
with((long) i));
will(new EncodeTagAction());
@@ -686,7 +686,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -694,7 +694,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 3
oneOf(crypto).deriveTagKey(secret3, false);
will(returnValue(k3));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k3),
with((long) i));
will(new EncodeTagAction());
@@ -702,7 +702,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 4
oneOf(crypto).deriveTagKey(secret4, false);
will(returnValue(k4));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k4),
with((long) i));
will(new EncodeTagAction());
@@ -714,7 +714,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -722,7 +722,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should remove the tags for period 3
oneOf(crypto).deriveTagKey(secret3, false);
will(returnValue(k3));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k3),
with((long) i));
will(new EncodeTagAction());
@@ -730,7 +730,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 4
oneOf(crypto).deriveTagKey(secret4, false);
will(returnValue(k4));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k4),
with((long) i));
will(new EncodeTagAction());

View File

@@ -14,7 +14,7 @@ public class ReorderingWindowTest extends BriarTestCase {
@Test
public void testWindowSliding() {
ReorderingWindow w = new ReorderingWindow();
for(int i = 0; i < 100; i++) {
for (int i = 0; i < 100; i++) {
assertFalse(w.isSeen(i));
w.setSeen(i);
assertTrue(w.isSeen(i));
@@ -24,7 +24,7 @@ public class ReorderingWindowTest extends BriarTestCase {
@Test
public void testWindowJumping() {
ReorderingWindow w = new ReorderingWindow();
for(int i = 0; i < 100; i += 13) {
for (int i = 0; i < 100; i += 13) {
assertFalse(w.isSeen(i));
w.setSeen(i);
assertTrue(w.isSeen(i));
@@ -42,7 +42,7 @@ public class ReorderingWindowTest extends BriarTestCase {
// Centre is 32, highest value in window is 47
w.setSeen(48);
fail();
} catch(IllegalArgumentException expected) {}
} catch (IllegalArgumentException expected) {}
// Centre is max - 1, highest value in window is max
byte[] bitmap = new byte[REORDERING_WINDOW_SIZE / 8];
w = new ReorderingWindow(MAX_32_BIT_UNSIGNED - 1, bitmap);
@@ -52,7 +52,7 @@ public class ReorderingWindowTest extends BriarTestCase {
try {
w.setSeen(MAX_32_BIT_UNSIGNED + 1);
fail();
} catch(IllegalArgumentException expected) {}
} catch (IllegalArgumentException expected) {}
w.setSeen(MAX_32_BIT_UNSIGNED);
assertTrue(w.isSeen(MAX_32_BIT_UNSIGNED));
// Centre should have moved to max + 1
@@ -65,7 +65,7 @@ public class ReorderingWindowTest extends BriarTestCase {
try {
w.setSeen(MAX_32_BIT_UNSIGNED + 1);
fail();
} catch(IllegalArgumentException expected) {}
} catch (IllegalArgumentException expected) {}
}
@Test
@@ -75,7 +75,7 @@ public class ReorderingWindowTest extends BriarTestCase {
try {
w.setSeen(-1);
fail();
} catch(IllegalArgumentException expected) {}
} catch (IllegalArgumentException expected) {}
// Slide the window
w.setSeen(15);
// Centre is 16, lowest value in window is 0
@@ -87,7 +87,7 @@ public class ReorderingWindowTest extends BriarTestCase {
try {
w.setSeen(0);
fail();
} catch(IllegalArgumentException expected) {}
} catch (IllegalArgumentException expected) {}
// Slide the window
w.setSeen(25);
// Centre is 26, lowest value in window is 10
@@ -95,7 +95,7 @@ public class ReorderingWindowTest extends BriarTestCase {
try {
w.setSeen(9);
fail();
} catch(IllegalArgumentException expected) {}
} catch (IllegalArgumentException expected) {}
// Centre should still be 26
assertEquals(26, w.getCentre());
// The bits corresponding to 10, 15, 16 and 25 should be set
@@ -112,7 +112,7 @@ public class ReorderingWindowTest extends BriarTestCase {
try {
w.setSeen(15);
fail();
} catch(IllegalArgumentException expected) {}
} catch (IllegalArgumentException expected) {}
}
@Test
@@ -121,7 +121,7 @@ public class ReorderingWindowTest extends BriarTestCase {
// Centre is 0; window should cover 0 to 15, inclusive, with none seen
Collection<Long> unseen = w.getUnseen();
assertEquals(16, unseen.size());
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
assertTrue(unseen.contains(Long.valueOf(i)));
assertFalse(w.isSeen(i));
}
@@ -130,8 +130,8 @@ public class ReorderingWindowTest extends BriarTestCase {
// Centre is 5; window should cover 0 to 20, inclusive, with two seen
unseen = w.getUnseen();
assertEquals(19, unseen.size());
for(int i = 0; i < 21; i++) {
if(i == 3 || i == 4) {
for (int i = 0; i < 21; i++) {
if (i == 3 || i == 4) {
assertFalse(unseen.contains(Long.valueOf(i)));
assertTrue(w.isSeen(i));
} else {
@@ -143,8 +143,8 @@ public class ReorderingWindowTest extends BriarTestCase {
// Centre is 20; window should cover 4 to 35, inclusive, with two seen
unseen = w.getUnseen();
assertEquals(30, unseen.size());
for(int i = 4; i < 36; i++) {
if(i == 4 || i == 19) {
for (int i = 4; i < 36; i++) {
if (i == 4 || i == 19) {
assertFalse(unseen.contains(Long.valueOf(i)));
assertTrue(w.isSeen(i));
} else {

View File

@@ -91,7 +91,7 @@ public class StreamWriterImplTest extends BriarTestCase {
oneOf(encrypter).writeFrame(with(any(byte[].class)),
with(MAX_PAYLOAD_LENGTH), with(0), with(false));
}});
for(int i = 0; i < MAX_PAYLOAD_LENGTH; i++) w.write(0);
for (int i = 0; i < MAX_PAYLOAD_LENGTH; i++) w.write(0);
context.assertIsSatisfied();
// Clean up

View File

@@ -24,20 +24,20 @@ class TestStreamDecrypter implements StreamDecrypter {
public int readFrame(byte[] payload) throws IOException {
int offset = 0;
while(offset < HEADER_LENGTH) {
while (offset < HEADER_LENGTH) {
int read = in.read(frame, offset, HEADER_LENGTH - offset);
if(read == -1) throw new EOFException();
if (read == -1) throw new EOFException();
offset += read;
}
boolean finalFrame = (frame[0] & 0x80) == 0x80;
int payloadLength = ByteUtils.readUint16(frame, 0) & 0x7FFF;
while(offset < frame.length) {
while (offset < frame.length) {
int read = in.read(frame, offset, frame.length - offset);
if(read == -1) break;
if (read == -1) break;
offset += read;
}
if(!finalFrame && offset < frame.length) throw new EOFException();
if(offset < HEADER_LENGTH + payloadLength + MAC_LENGTH)
if (!finalFrame && offset < frame.length) throw new EOFException();
if (offset < HEADER_LENGTH + payloadLength + MAC_LENGTH)
throw new FormatException();
System.arraycopy(frame, HEADER_LENGTH, payload, 0, payloadLength);
return payloadLength;

View File

@@ -25,16 +25,16 @@ class TestStreamEncrypter implements StreamEncrypter {
public void writeFrame(byte[] payload, int payloadLength,
int paddingLength, boolean finalFrame) throws IOException {
if(writeTag) {
if (writeTag) {
out.write(tag);
writeTag = false;
}
ByteUtils.writeUint16(payloadLength, frame, 0);
if(finalFrame) frame[0] |= 0x80;
if (finalFrame) frame[0] |= 0x80;
System.arraycopy(payload, 0, frame, HEADER_LENGTH, payloadLength);
for(int i = HEADER_LENGTH + payloadLength; i < frame.length; i++)
for (int i = HEADER_LENGTH + payloadLength; i < frame.length; i++)
frame[i] = 0;
if(finalFrame)
if (finalFrame)
out.write(frame, 0, HEADER_LENGTH + payloadLength + MAC_LENGTH);
else out.write(frame, 0, frame.length);
}

View File

@@ -73,9 +73,9 @@ public class TransportIntegrationTest extends BriarTestCase {
private void read(InputStream in, byte[] dest) throws IOException {
int offset = 0;
while(offset < dest.length) {
while (offset < dest.length) {
int read = in.read(dest, offset, dest.length - offset);
if(read == -1) break;
if (read == -1) break;
offset += read;
}
}

View File

@@ -39,7 +39,7 @@ public class TransportTagRecogniserTest extends BriarTestCase {
// Add secret
oneOf(crypto).deriveTagKey(secret, !alice);
will(returnValue(tagKey));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(tagKey),
with((long) i));
will(new EncodeTagAction());
@@ -47,7 +47,7 @@ public class TransportTagRecogniserTest extends BriarTestCase {
// Remove secret
oneOf(crypto).deriveTagKey(secret, !alice);
will(returnValue(tagKey));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(tagKey),
with((long) i));
will(new EncodeTagAction());
@@ -74,7 +74,7 @@ public class TransportTagRecogniserTest extends BriarTestCase {
// Add secret
oneOf(crypto).deriveTagKey(secret, !alice);
will(returnValue(tagKey));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(tagKey),
with((long) i));
will(new EncodeTagAction());