diff --git a/components/net/sf/briar/transport/ConnectionReaderFactoryImpl.java b/components/net/sf/briar/transport/ConnectionReaderFactoryImpl.java
index 4149b3768..1a82bd835 100644
--- a/components/net/sf/briar/transport/ConnectionReaderFactoryImpl.java
+++ b/components/net/sf/briar/transport/ConnectionReaderFactoryImpl.java
@@ -49,7 +49,7 @@ class ConnectionReaderFactoryImpl implements ConnectionReaderFactory {
Cipher tagCipher = crypto.getTagCipher();
Cipher frameCipher = crypto.getFrameCipher();
Mac mac = crypto.getMac();
- FrameSource decrypter = new ConnectionDecrypter(in, tagCipher,
+ IncomingEncryptionLayer decrypter = new IncomingEncryptionLayerImpl(in, tagCipher,
frameCipher, tagKey, frameKey, mac.getMacLength(), false);
// Create the reader
return new ConnectionReaderImpl(decrypter, mac, macKey);
diff --git a/components/net/sf/briar/transport/ConnectionReaderImpl.java b/components/net/sf/briar/transport/ConnectionReaderImpl.java
index 1d7b1de19..9ee8b7180 100644
--- a/components/net/sf/briar/transport/ConnectionReaderImpl.java
+++ b/components/net/sf/briar/transport/ConnectionReaderImpl.java
@@ -16,7 +16,7 @@ import net.sf.briar.api.transport.ConnectionReader;
class ConnectionReaderImpl extends InputStream implements ConnectionReader {
- private final FrameSource decrypter;
+ private final IncomingEncryptionLayer decrypter;
private final Mac mac;
private final int macLength;
private final byte[] buf;
@@ -24,7 +24,7 @@ class ConnectionReaderImpl extends InputStream implements ConnectionReader {
private long frame = 0L;
private int bufOffset = 0, bufLength = 0;
- ConnectionReaderImpl(FrameSource decrypter, Mac mac, ErasableKey macKey) {
+ ConnectionReaderImpl(IncomingEncryptionLayer decrypter, Mac mac, ErasableKey macKey) {
this.decrypter = decrypter;
this.mac = mac;
// Initialise the MAC
diff --git a/components/net/sf/briar/transport/ConnectionWriterFactoryImpl.java b/components/net/sf/briar/transport/ConnectionWriterFactoryImpl.java
index e368d1f39..3af3e0a56 100644
--- a/components/net/sf/briar/transport/ConnectionWriterFactoryImpl.java
+++ b/components/net/sf/briar/transport/ConnectionWriterFactoryImpl.java
@@ -48,7 +48,7 @@ class ConnectionWriterFactoryImpl implements ConnectionWriterFactory {
// Create the encrypter
Cipher tagCipher = crypto.getTagCipher();
Cipher frameCipher = crypto.getFrameCipher();
- ConnectionEncrypter encrypter = new ConnectionEncrypterImpl(out,
+ OutgoingEncryptionLayer encrypter = new OutgoingEncryptionLayerImpl(out,
capacity, tagCipher, frameCipher, tagKey, frameKey, false);
// Create the writer
Mac mac = crypto.getMac();
diff --git a/components/net/sf/briar/transport/ConnectionWriterImpl.java b/components/net/sf/briar/transport/ConnectionWriterImpl.java
index fd823dd0f..87e7089f9 100644
--- a/components/net/sf/briar/transport/ConnectionWriterImpl.java
+++ b/components/net/sf/briar/transport/ConnectionWriterImpl.java
@@ -22,14 +22,14 @@ import net.sf.briar.api.transport.ConnectionWriter;
*/
class ConnectionWriterImpl extends OutputStream implements ConnectionWriter {
- private final ConnectionEncrypter encrypter;
+ private final OutgoingEncryptionLayer encrypter;
private final Mac mac;
private final byte[] buf;
private int bufLength = FRAME_HEADER_LENGTH;
private long frame = 0L;
- ConnectionWriterImpl(ConnectionEncrypter encrypter, Mac mac,
+ ConnectionWriterImpl(OutgoingEncryptionLayer encrypter, Mac mac,
ErasableKey macKey) {
this.encrypter = encrypter;
this.mac = mac;
diff --git a/components/net/sf/briar/transport/FrameSink.java b/components/net/sf/briar/transport/FrameSink.java
deleted file mode 100644
index 710f60a5e..000000000
--- a/components/net/sf/briar/transport/FrameSink.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package net.sf.briar.transport;
-
-import java.io.IOException;
-
-interface FrameSink {
-
- /** Writes the given frame. */
- void writeFrame(byte[] b, int len) throws IOException;
-}
diff --git a/components/net/sf/briar/transport/FrameSource.java b/components/net/sf/briar/transport/IncomingEncryptionLayer.java
similarity index 86%
rename from components/net/sf/briar/transport/FrameSource.java
rename to components/net/sf/briar/transport/IncomingEncryptionLayer.java
index 7347b6ccb..bd4bd1982 100644
--- a/components/net/sf/briar/transport/FrameSource.java
+++ b/components/net/sf/briar/transport/IncomingEncryptionLayer.java
@@ -2,7 +2,7 @@ package net.sf.briar.transport;
import java.io.IOException;
-interface FrameSource {
+interface IncomingEncryptionLayer {
/**
* Reads a frame into the given buffer and returns its length, or -1 if no
diff --git a/components/net/sf/briar/transport/ConnectionDecrypter.java b/components/net/sf/briar/transport/IncomingEncryptionLayerImpl.java
similarity index 93%
rename from components/net/sf/briar/transport/ConnectionDecrypter.java
rename to components/net/sf/briar/transport/IncomingEncryptionLayerImpl.java
index 928f56ca7..b8f684d0a 100644
--- a/components/net/sf/briar/transport/ConnectionDecrypter.java
+++ b/components/net/sf/briar/transport/IncomingEncryptionLayerImpl.java
@@ -16,7 +16,7 @@ import javax.crypto.spec.IvParameterSpec;
import net.sf.briar.api.FormatException;
import net.sf.briar.api.crypto.ErasableKey;
-class ConnectionDecrypter implements FrameSource {
+class IncomingEncryptionLayerImpl implements IncomingEncryptionLayer {
private final InputStream in;
private final Cipher tagCipher, frameCipher;
@@ -27,9 +27,9 @@ class ConnectionDecrypter implements FrameSource {
private long frame = 0L;
- ConnectionDecrypter(InputStream in, Cipher tagCipher, Cipher frameCipher,
- ErasableKey tagKey, ErasableKey frameKey, int macLength,
- boolean tagEverySegment) {
+ IncomingEncryptionLayerImpl(InputStream in, Cipher tagCipher,
+ Cipher frameCipher, ErasableKey tagKey, ErasableKey frameKey,
+ int macLength, boolean tagEverySegment) {
this.in = in;
this.tagCipher = tagCipher;
this.frameCipher = frameCipher;
diff --git a/components/net/sf/briar/transport/SegmentedConnectionDecrypter.java b/components/net/sf/briar/transport/IncomingSegmentedEncryptionLayer.java
similarity index 95%
rename from components/net/sf/briar/transport/SegmentedConnectionDecrypter.java
rename to components/net/sf/briar/transport/IncomingSegmentedEncryptionLayer.java
index 59af5f185..dfa063c93 100644
--- a/components/net/sf/briar/transport/SegmentedConnectionDecrypter.java
+++ b/components/net/sf/briar/transport/IncomingSegmentedEncryptionLayer.java
@@ -16,7 +16,7 @@ import net.sf.briar.api.crypto.ErasableKey;
import net.sf.briar.api.plugins.Segment;
import net.sf.briar.api.plugins.SegmentSource;
-class SegmentedConnectionDecrypter implements FrameSource {
+class IncomingSegmentedEncryptionLayer implements IncomingEncryptionLayer {
private final SegmentSource in;
private final Cipher tagCipher, frameCipher;
@@ -28,7 +28,7 @@ class SegmentedConnectionDecrypter implements FrameSource {
private long frame = 0L;
- SegmentedConnectionDecrypter(SegmentSource in, Cipher tagCipher,
+ IncomingSegmentedEncryptionLayer(SegmentSource in, Cipher tagCipher,
Cipher frameCipher, ErasableKey tagKey, ErasableKey frameKey,
int macLength, boolean tagEverySegment) {
this.in = in;
diff --git a/components/net/sf/briar/transport/ConnectionEncrypter.java b/components/net/sf/briar/transport/OutgoingEncryptionLayer.java
similarity index 70%
rename from components/net/sf/briar/transport/ConnectionEncrypter.java
rename to components/net/sf/briar/transport/OutgoingEncryptionLayer.java
index 82bbf357a..bd902736a 100644
--- a/components/net/sf/briar/transport/ConnectionEncrypter.java
+++ b/components/net/sf/briar/transport/OutgoingEncryptionLayer.java
@@ -3,7 +3,10 @@ package net.sf.briar.transport;
import java.io.IOException;
/** Encrypts authenticated data to be sent over a connection. */
-interface ConnectionEncrypter extends FrameSink {
+interface OutgoingEncryptionLayer {
+
+ /** Writes the given frame. */
+ void writeFrame(byte[] b, int len) throws IOException;
/** Flushes the output stream. */
void flush() throws IOException;
diff --git a/components/net/sf/briar/transport/ConnectionEncrypterImpl.java b/components/net/sf/briar/transport/OutgoingEncryptionLayerImpl.java
similarity index 92%
rename from components/net/sf/briar/transport/ConnectionEncrypterImpl.java
rename to components/net/sf/briar/transport/OutgoingEncryptionLayerImpl.java
index 08e40577a..33cb92943 100644
--- a/components/net/sf/briar/transport/ConnectionEncrypterImpl.java
+++ b/components/net/sf/briar/transport/OutgoingEncryptionLayerImpl.java
@@ -12,7 +12,7 @@ import javax.crypto.spec.IvParameterSpec;
import net.sf.briar.api.crypto.ErasableKey;
-class ConnectionEncrypterImpl implements ConnectionEncrypter {
+class OutgoingEncryptionLayerImpl implements OutgoingEncryptionLayer {
private final OutputStream out;
private final Cipher tagCipher, frameCipher;
@@ -22,7 +22,7 @@ class ConnectionEncrypterImpl implements ConnectionEncrypter {
private long capacity, frame = 0L;
- ConnectionEncrypterImpl(OutputStream out, long capacity, Cipher tagCipher,
+ OutgoingEncryptionLayerImpl(OutputStream out, long capacity, Cipher tagCipher,
Cipher frameCipher, ErasableKey tagKey, ErasableKey frameKey,
boolean tagEverySegment) {
this.out = out;
diff --git a/components/net/sf/briar/transport/SegmentedConnectionEncrypter.java b/components/net/sf/briar/transport/OutgoingSegmentedEncryptionLayer.java
similarity index 94%
rename from components/net/sf/briar/transport/SegmentedConnectionEncrypter.java
rename to components/net/sf/briar/transport/OutgoingSegmentedEncryptionLayer.java
index 29af654f2..99ce32f90 100644
--- a/components/net/sf/briar/transport/SegmentedConnectionEncrypter.java
+++ b/components/net/sf/briar/transport/OutgoingSegmentedEncryptionLayer.java
@@ -14,7 +14,7 @@ import net.sf.briar.api.crypto.ErasableKey;
import net.sf.briar.api.plugins.Segment;
import net.sf.briar.api.plugins.SegmentSink;
-class SegmentedConnectionEncrypter implements ConnectionEncrypter {
+class OutgoingSegmentedEncryptionLayer implements OutgoingEncryptionLayer {
private final SegmentSink out;
private final Cipher tagCipher, frameCipher;
@@ -25,7 +25,7 @@ class SegmentedConnectionEncrypter implements ConnectionEncrypter {
private long capacity, frame = 0L;
- SegmentedConnectionEncrypter(SegmentSink out, long capacity,
+ OutgoingSegmentedEncryptionLayer(SegmentSink out, long capacity,
Cipher tagCipher, Cipher frameCipher, ErasableKey tagKey,
ErasableKey frameKey, boolean tagEverySegment) {
this.out = out;
diff --git a/test/build.xml b/test/build.xml
index f0d631622..a92959b50 100644
--- a/test/build.xml
+++ b/test/build.xml
@@ -49,8 +49,6 @@
-
-
@@ -58,8 +56,10 @@
-
-
+
+
+
+
diff --git a/test/net/sf/briar/transport/ConnectionReaderImplTest.java b/test/net/sf/briar/transport/ConnectionReaderImplTest.java
index 798f8e457..bb385b919 100644
--- a/test/net/sf/briar/transport/ConnectionReaderImplTest.java
+++ b/test/net/sf/briar/transport/ConnectionReaderImplTest.java
@@ -31,7 +31,7 @@ public class ConnectionReaderImplTest extends TransportTest {
mac.doFinal(frame, FRAME_HEADER_LENGTH + payloadLength);
// Read the frame
ByteArrayInputStream in = new ByteArrayInputStream(frame);
- FrameSource d = new NullConnectionDecrypter(in, macLength);
+ IncomingEncryptionLayer d = new NullConnectionDecrypter(in, macLength);
ConnectionReader r = new ConnectionReaderImpl(d, mac, macKey);
// There should be no bytes available before EOF
assertEquals(-1, r.getInputStream().read());
@@ -49,7 +49,7 @@ public class ConnectionReaderImplTest extends TransportTest {
mac.doFinal(frame, FRAME_HEADER_LENGTH + payloadLength);
// Read the frame
ByteArrayInputStream in = new ByteArrayInputStream(frame);
- FrameSource d = new NullConnectionDecrypter(in, macLength);
+ IncomingEncryptionLayer d = new NullConnectionDecrypter(in, macLength);
ConnectionReader r = new ConnectionReaderImpl(d, mac, macKey);
// There should be one byte available before EOF
assertEquals(0, r.getInputStream().read());
@@ -75,7 +75,7 @@ public class ConnectionReaderImplTest extends TransportTest {
out.write(frame1);
// Read the first frame
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
- FrameSource d = new NullConnectionDecrypter(in, macLength);
+ IncomingEncryptionLayer d = new NullConnectionDecrypter(in, macLength);
ConnectionReader r = new ConnectionReaderImpl(d, mac, macKey);
byte[] read = new byte[maxPayloadLength];
TestUtils.readFully(r.getInputStream(), read);
@@ -109,7 +109,7 @@ public class ConnectionReaderImplTest extends TransportTest {
out.write(frame1);
// Read the first frame
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
- FrameSource d = new NullConnectionDecrypter(in, macLength);
+ IncomingEncryptionLayer d = new NullConnectionDecrypter(in, macLength);
ConnectionReader r = new ConnectionReaderImpl(d, mac, macKey);
byte[] read = new byte[maxPayloadLength - paddingLength];
TestUtils.readFully(r.getInputStream(), read);
@@ -135,7 +135,7 @@ public class ConnectionReaderImplTest extends TransportTest {
mac.doFinal(frame, FRAME_HEADER_LENGTH + payloadLength + paddingLength);
// Read the frame
ByteArrayInputStream in = new ByteArrayInputStream(frame);
- FrameSource d = new NullConnectionDecrypter(in, macLength);
+ IncomingEncryptionLayer d = new NullConnectionDecrypter(in, macLength);
ConnectionReader r = new ConnectionReaderImpl(d, mac, macKey);
// The non-zero padding should be rejected
try {
@@ -167,7 +167,7 @@ public class ConnectionReaderImplTest extends TransportTest {
out.write(frame1);
// Read the frames
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
- FrameSource d = new NullConnectionDecrypter(in, macLength);
+ IncomingEncryptionLayer d = new NullConnectionDecrypter(in, macLength);
ConnectionReader r = new ConnectionReaderImpl(d, mac, macKey);
byte[] read = new byte[payloadLength];
TestUtils.readFully(r.getInputStream(), read);
@@ -191,7 +191,7 @@ public class ConnectionReaderImplTest extends TransportTest {
frame[12] ^= 1;
// Try to read the frame - not a single byte should be read
ByteArrayInputStream in = new ByteArrayInputStream(frame);
- FrameSource d = new NullConnectionDecrypter(in, macLength);
+ IncomingEncryptionLayer d = new NullConnectionDecrypter(in, macLength);
ConnectionReader r = new ConnectionReaderImpl(d, mac, macKey);
try {
r.getInputStream().read();
@@ -213,7 +213,7 @@ public class ConnectionReaderImplTest extends TransportTest {
frame[17] ^= 1;
// Try to read the frame - not a single byte should be read
ByteArrayInputStream in = new ByteArrayInputStream(frame);
- FrameSource d = new NullConnectionDecrypter(in, macLength);
+ IncomingEncryptionLayer d = new NullConnectionDecrypter(in, macLength);
ConnectionReader r = new ConnectionReaderImpl(d, mac, macKey);
try {
r.getInputStream().read();
diff --git a/test/net/sf/briar/transport/ConnectionWriterImplTest.java b/test/net/sf/briar/transport/ConnectionWriterImplTest.java
index 7076deb49..43f6cf47c 100644
--- a/test/net/sf/briar/transport/ConnectionWriterImplTest.java
+++ b/test/net/sf/briar/transport/ConnectionWriterImplTest.java
@@ -20,7 +20,7 @@ public class ConnectionWriterImplTest extends TransportTest {
@Test
public void testFlushWithoutWriteProducesNothing() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
- ConnectionEncrypter e = new NullConnectionEncrypter(out);
+ OutgoingEncryptionLayer e = new NullConnectionEncrypter(out);
ConnectionWriter w = new ConnectionWriterImpl(e, mac, macKey);
w.getOutputStream().flush();
w.getOutputStream().flush();
@@ -40,7 +40,7 @@ public class ConnectionWriterImplTest extends TransportTest {
mac.doFinal(frame, FRAME_HEADER_LENGTH + payloadLength);
// Check that the ConnectionWriter gets the same results
ByteArrayOutputStream out = new ByteArrayOutputStream();
- ConnectionEncrypter e = new NullConnectionEncrypter(out);
+ OutgoingEncryptionLayer e = new NullConnectionEncrypter(out);
ConnectionWriter w = new ConnectionWriterImpl(e, mac, macKey);
w.getOutputStream().write(0);
w.getOutputStream().flush();
@@ -50,7 +50,7 @@ public class ConnectionWriterImplTest extends TransportTest {
@Test
public void testWriteByteToMaxLengthWritesFrame() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
- ConnectionEncrypter e = new NullConnectionEncrypter(out);
+ OutgoingEncryptionLayer e = new NullConnectionEncrypter(out);
ConnectionWriter w = new ConnectionWriterImpl(e, mac, macKey);
OutputStream out1 = w.getOutputStream();
// The first maxPayloadLength - 1 bytes should be buffered
@@ -64,7 +64,7 @@ public class ConnectionWriterImplTest extends TransportTest {
@Test
public void testWriteArrayToMaxLengthWritesFrame() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
- ConnectionEncrypter e = new NullConnectionEncrypter(out);
+ OutgoingEncryptionLayer e = new NullConnectionEncrypter(out);
ConnectionWriter w = new ConnectionWriterImpl(e, mac, macKey);
OutputStream out1 = w.getOutputStream();
// The first maxPayloadLength - 1 bytes should be buffered
@@ -99,7 +99,7 @@ public class ConnectionWriterImplTest extends TransportTest {
byte[] expected = out.toByteArray();
// Check that the ConnectionWriter gets the same results
out.reset();
- ConnectionEncrypter e = new NullConnectionEncrypter(out);
+ OutgoingEncryptionLayer e = new NullConnectionEncrypter(out);
ConnectionWriter w = new ConnectionWriterImpl(e, mac, macKey);
w.getOutputStream().write(new byte[123]);
w.getOutputStream().flush();
diff --git a/test/net/sf/briar/transport/FrameReadWriteTest.java b/test/net/sf/briar/transport/FrameReadWriteTest.java
index 051f9f66b..53b4a8f1c 100644
--- a/test/net/sf/briar/transport/FrameReadWriteTest.java
+++ b/test/net/sf/briar/transport/FrameReadWriteTest.java
@@ -74,7 +74,7 @@ public class FrameReadWriteTest extends BriarTestCase {
ErasableKey macCopy = macKey.copy();
// Write the frames
ByteArrayOutputStream out = new ByteArrayOutputStream();
- ConnectionEncrypter encrypter = new ConnectionEncrypterImpl(out,
+ OutgoingEncryptionLayer encrypter = new OutgoingEncryptionLayerImpl(out,
Long.MAX_VALUE, tagCipher, frameCipher, tagCopy, frameCopy,
false);
ConnectionWriter writer = new ConnectionWriterImpl(encrypter, mac,
@@ -91,7 +91,7 @@ public class FrameReadWriteTest extends BriarTestCase {
assertArrayEquals(tag, recoveredTag);
assertTrue(TagEncoder.validateTag(tag, 0, tagCipher, tagKey));
// Read the frames back
- FrameSource decrypter = new ConnectionDecrypter(in, tagCipher,
+ IncomingEncryptionLayer decrypter = new IncomingEncryptionLayerImpl(in, tagCipher,
frameCipher, tagKey, frameKey, mac.getMacLength(), false);
ConnectionReader reader = new ConnectionReaderImpl(decrypter, mac,
macKey);
diff --git a/test/net/sf/briar/transport/ConnectionDecrypterTest.java b/test/net/sf/briar/transport/IncomingEncryptionLayerImplTest.java
similarity index 89%
rename from test/net/sf/briar/transport/ConnectionDecrypterTest.java
rename to test/net/sf/briar/transport/IncomingEncryptionLayerImplTest.java
index b79bff4d4..6ac04ef08 100644
--- a/test/net/sf/briar/transport/ConnectionDecrypterTest.java
+++ b/test/net/sf/briar/transport/IncomingEncryptionLayerImplTest.java
@@ -20,14 +20,14 @@ import org.junit.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
-public class ConnectionDecrypterTest extends BriarTestCase {
+public class IncomingEncryptionLayerImplTest extends BriarTestCase {
private static final int MAC_LENGTH = 32;
private final Cipher tagCipher, frameCipher;
private final ErasableKey tagKey, frameKey;
- public ConnectionDecrypterTest() {
+ public IncomingEncryptionLayerImplTest() {
super();
Injector i = Guice.createInjector(new CryptoModule());
CryptoComponent crypto = i.getInstance(CryptoComponent.class);
@@ -59,9 +59,9 @@ public class ConnectionDecrypterTest extends BriarTestCase {
out.write(ciphertext);
out.write(ciphertext1);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
- // Use a ConnectionDecrypter to decrypt the ciphertext
- FrameSource decrypter = new ConnectionDecrypter(in, tagCipher,
- frameCipher, tagKey, frameKey, MAC_LENGTH, false);
+ // Use the encryption layer to decrypt the ciphertext
+ IncomingEncryptionLayer decrypter = new IncomingEncryptionLayerImpl(in,
+ tagCipher, frameCipher, tagKey, frameKey, MAC_LENGTH, false);
// First frame
byte[] decrypted = new byte[MAX_FRAME_LENGTH];
assertEquals(plaintext.length, decrypter.readFrame(decrypted));
@@ -99,9 +99,9 @@ public class ConnectionDecrypterTest extends BriarTestCase {
out.write(ciphertext);
out.write(ciphertext1);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
- // Use a ConnectionDecrypter to decrypt the ciphertext
- FrameSource decrypter = new ConnectionDecrypter(in, tagCipher,
- frameCipher, tagKey, frameKey, MAC_LENGTH, true);
+ // Use the encryption layer to decrypt the ciphertext
+ IncomingEncryptionLayer decrypter = new IncomingEncryptionLayerImpl(in,
+ tagCipher, frameCipher, tagKey, frameKey, MAC_LENGTH, true);
// First frame
byte[] decrypted = new byte[MAX_FRAME_LENGTH];
assertEquals(plaintext.length, decrypter.readFrame(decrypted));
diff --git a/test/net/sf/briar/transport/SegmentedConnectionDecrypterTest.java b/test/net/sf/briar/transport/IncomingSegmentedEncryptionLayerTest.java
similarity index 85%
rename from test/net/sf/briar/transport/SegmentedConnectionDecrypterTest.java
rename to test/net/sf/briar/transport/IncomingSegmentedEncryptionLayerTest.java
index 539b6dd0b..d3e580ff5 100644
--- a/test/net/sf/briar/transport/SegmentedConnectionDecrypterTest.java
+++ b/test/net/sf/briar/transport/IncomingSegmentedEncryptionLayerTest.java
@@ -21,14 +21,14 @@ import org.junit.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
-public class SegmentedConnectionDecrypterTest extends BriarTestCase {
+public class IncomingSegmentedEncryptionLayerTest extends BriarTestCase {
private static final int MAC_LENGTH = 32;
private final Cipher tagCipher, frameCipher;
private final ErasableKey tagKey, frameKey;
- public SegmentedConnectionDecrypterTest() {
+ public IncomingSegmentedEncryptionLayerTest() {
super();
Injector i = Guice.createInjector(new CryptoModule());
CryptoComponent crypto = i.getInstance(CryptoComponent.class);
@@ -55,11 +55,12 @@ public class SegmentedConnectionDecrypterTest extends BriarTestCase {
frameCipher.init(Cipher.ENCRYPT_MODE, frameKey, ivSpec);
byte[] ciphertext1 = frameCipher.doFinal(plaintext1, 0,
plaintext1.length);
- // Use a connection decrypter to decrypt the ciphertext
+ // Use the encryption layer to decrypt the ciphertext
byte[][] frames = new byte[][] { ciphertext, ciphertext1 };
SegmentSource in = new ByteArraySegmentSource(frames);
- FrameSource decrypter = new SegmentedConnectionDecrypter(in, tagCipher,
- frameCipher, tagKey, frameKey, MAC_LENGTH, false);
+ IncomingEncryptionLayer decrypter =
+ new IncomingSegmentedEncryptionLayer(in, tagCipher, frameCipher,
+ tagKey, frameKey, MAC_LENGTH, false);
// First frame
byte[] decrypted = new byte[MAX_FRAME_LENGTH];
assertEquals(plaintext.length, decrypter.readFrame(decrypted));
@@ -92,11 +93,12 @@ public class SegmentedConnectionDecrypterTest extends BriarTestCase {
frameCipher.init(Cipher.ENCRYPT_MODE, frameKey, ivSpec);
frameCipher.doFinal(plaintext1, 0, plaintext1.length, ciphertext1,
TAG_LENGTH);
- // Use a connection decrypter to decrypt the ciphertext
+ // Use the encryption layer to decrypt the ciphertext
byte[][] frames = new byte[][] { ciphertext, ciphertext1 };
SegmentSource in = new ByteArraySegmentSource(frames);
- FrameSource decrypter = new SegmentedConnectionDecrypter(in, tagCipher,
- frameCipher, tagKey, frameKey, MAC_LENGTH, true);
+ IncomingEncryptionLayer decrypter =
+ new IncomingSegmentedEncryptionLayer(in, tagCipher, frameCipher,
+ tagKey, frameKey, MAC_LENGTH, true);
// First frame
byte[] decrypted = new byte[MAX_FRAME_LENGTH];
assertEquals(plaintext.length, decrypter.readFrame(decrypted));
@@ -112,20 +114,20 @@ public class SegmentedConnectionDecrypterTest extends BriarTestCase {
private static class ByteArraySegmentSource implements SegmentSource {
- private final byte[][] frames;
+ private final byte[][] segments;
- private int frame = 0;
+ private int segmentNumber = 0;
private ByteArraySegmentSource(byte[][] frames) {
- this.frames = frames;
+ this.segments = frames;
}
public boolean readSegment(Segment s) throws IOException {
- if(frame == frames.length) return false;
- byte[] src = frames[frame];
+ if(segmentNumber == segments.length) return false;
+ byte[] src = segments[segmentNumber];
System.arraycopy(src, 0, s.getBuffer(), 0, src.length);
s.setLength(src.length);
- frame++;
+ segmentNumber++;
return true;
}
}
diff --git a/test/net/sf/briar/transport/NullConnectionDecrypter.java b/test/net/sf/briar/transport/NullConnectionDecrypter.java
index 32b5a2164..ac1a59ddc 100644
--- a/test/net/sf/briar/transport/NullConnectionDecrypter.java
+++ b/test/net/sf/briar/transport/NullConnectionDecrypter.java
@@ -10,7 +10,7 @@ import java.io.InputStream;
import net.sf.briar.api.FormatException;
/** A connection decrypter that performs no decryption. */
-class NullConnectionDecrypter implements FrameSource {
+class NullConnectionDecrypter implements IncomingEncryptionLayer {
private final InputStream in;
private final int macLength;
diff --git a/test/net/sf/briar/transport/NullConnectionEncrypter.java b/test/net/sf/briar/transport/NullConnectionEncrypter.java
index 5f59c7896..182f612ca 100644
--- a/test/net/sf/briar/transport/NullConnectionEncrypter.java
+++ b/test/net/sf/briar/transport/NullConnectionEncrypter.java
@@ -4,7 +4,7 @@ import java.io.IOException;
import java.io.OutputStream;
/** A ConnectionEncrypter that performs no encryption. */
-class NullConnectionEncrypter implements ConnectionEncrypter {
+class NullConnectionEncrypter implements OutgoingEncryptionLayer {
private final OutputStream out;
diff --git a/test/net/sf/briar/transport/ConnectionEncrypterImplTest.java b/test/net/sf/briar/transport/OutgoingEncryptionLayerImplTest.java
similarity index 79%
rename from test/net/sf/briar/transport/ConnectionEncrypterImplTest.java
rename to test/net/sf/briar/transport/OutgoingEncryptionLayerImplTest.java
index ddc932518..8aa93d68e 100644
--- a/test/net/sf/briar/transport/ConnectionEncrypterImplTest.java
+++ b/test/net/sf/briar/transport/OutgoingEncryptionLayerImplTest.java
@@ -18,14 +18,14 @@ import org.junit.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
-public class ConnectionEncrypterImplTest extends BriarTestCase {
+public class OutgoingEncryptionLayerImplTest extends BriarTestCase {
private static final int MAC_LENGTH = 32;
private final Cipher tagCipher, frameCipher;
private final ErasableKey tagKey, frameKey;
- public ConnectionEncrypterImplTest() {
+ public OutgoingEncryptionLayerImplTest() {
super();
Injector i = Guice.createInjector(new CryptoModule());
CryptoComponent crypto = i.getInstance(CryptoComponent.class);
@@ -58,16 +58,18 @@ public class ConnectionEncrypterImplTest extends BriarTestCase {
out.write(ciphertext);
out.write(ciphertext1);
byte[] expected = out.toByteArray();
- // Use a ConnectionEncrypter to encrypt the plaintext
+ // Use the encryption layer to encrypt the plaintext
out.reset();
- ConnectionEncrypter e = new ConnectionEncrypterImpl(out, Long.MAX_VALUE,
- tagCipher, frameCipher, tagKey, frameKey, false);
- e.writeFrame(plaintext, plaintext.length);
- e.writeFrame(plaintext1, plaintext1.length);
+ OutgoingEncryptionLayer encrypter = new OutgoingEncryptionLayerImpl(out,
+ Long.MAX_VALUE, tagCipher, frameCipher, tagKey, frameKey,
+ false);
+ encrypter.writeFrame(plaintext, plaintext.length);
+ encrypter.writeFrame(plaintext1, plaintext1.length);
byte[] actual = out.toByteArray();
// Check that the actual ciphertext matches the expected ciphertext
assertArrayEquals(expected, actual);
- assertEquals(Long.MAX_VALUE - actual.length, e.getRemainingCapacity());
+ assertEquals(Long.MAX_VALUE - actual.length,
+ encrypter.getRemainingCapacity());
}
@Test
@@ -97,15 +99,16 @@ public class ConnectionEncrypterImplTest extends BriarTestCase {
out.write(tag1);
out.write(ciphertext1);
byte[] expected = out.toByteArray();
- // Use a ConnectionEncrypter to encrypt the plaintext
+ // Use the encryption layer to encrypt the plaintext
out.reset();
- ConnectionEncrypter e = new ConnectionEncrypterImpl(out, Long.MAX_VALUE,
- tagCipher, frameCipher, tagKey, frameKey, true);
- e.writeFrame(plaintext, plaintext.length);
- e.writeFrame(plaintext1, plaintext1.length);
+ OutgoingEncryptionLayer encrypter = new OutgoingEncryptionLayerImpl(out,
+ Long.MAX_VALUE, tagCipher, frameCipher, tagKey, frameKey, true);
+ encrypter.writeFrame(plaintext, plaintext.length);
+ encrypter.writeFrame(plaintext1, plaintext1.length);
byte[] actual = out.toByteArray();
// Check that the actual ciphertext matches the expected ciphertext
assertArrayEquals(expected, actual);
- assertEquals(Long.MAX_VALUE - actual.length, e.getRemainingCapacity());
+ assertEquals(Long.MAX_VALUE - actual.length,
+ encrypter.getRemainingCapacity());
}
}
diff --git a/test/net/sf/briar/transport/SegmentedConnectionEncrypterTest.java b/test/net/sf/briar/transport/OutgoingSegmentedEncryptionLayerTest.java
similarity index 80%
rename from test/net/sf/briar/transport/SegmentedConnectionEncrypterTest.java
rename to test/net/sf/briar/transport/OutgoingSegmentedEncryptionLayerTest.java
index ab981dbef..ecbbbc1c6 100644
--- a/test/net/sf/briar/transport/SegmentedConnectionEncrypterTest.java
+++ b/test/net/sf/briar/transport/OutgoingSegmentedEncryptionLayerTest.java
@@ -21,14 +21,14 @@ import org.junit.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
-public class SegmentedConnectionEncrypterTest extends BriarTestCase {
+public class OutgoingSegmentedEncryptionLayerTest extends BriarTestCase {
private static final int MAC_LENGTH = 32;
private final Cipher tagCipher, frameCipher;
private final ErasableKey tagKey, frameKey;
- public SegmentedConnectionEncrypterTest() {
+ public OutgoingSegmentedEncryptionLayerTest() {
super();
Injector i = Guice.createInjector(new CryptoModule());
CryptoComponent crypto = i.getInstance(CryptoComponent.class);
@@ -61,18 +61,19 @@ public class SegmentedConnectionEncrypterTest extends BriarTestCase {
out.write(ciphertext);
out.write(ciphertext1);
byte[] expected = out.toByteArray();
- // Use a connection encrypter to encrypt the plaintext
+ // Use the encryption layer to encrypt the plaintext
ByteArraySegmentSink sink = new ByteArraySegmentSink();
- ConnectionEncrypter e = new SegmentedConnectionEncrypter(sink,
- Long.MAX_VALUE, tagCipher, frameCipher, tagKey, frameKey,
- false);
+ OutgoingEncryptionLayer encrypter =
+ new OutgoingSegmentedEncryptionLayer(sink, Long.MAX_VALUE,
+ tagCipher, frameCipher, tagKey, frameKey, false);
// The first frame's buffer must have enough space for the tag
- e.writeFrame(plaintext, plaintext.length);
- e.writeFrame(plaintext1, plaintext1.length);
+ encrypter.writeFrame(plaintext, plaintext.length);
+ encrypter.writeFrame(plaintext1, plaintext1.length);
byte[] actual = out.toByteArray();
// Check that the actual ciphertext matches the expected ciphertext
assertArrayEquals(expected, actual);
- assertEquals(Long.MAX_VALUE - actual.length, e.getRemainingCapacity());
+ assertEquals(Long.MAX_VALUE - actual.length,
+ encrypter.getRemainingCapacity());
}
@Test
@@ -102,16 +103,18 @@ public class SegmentedConnectionEncrypterTest extends BriarTestCase {
out.write(tag1);
out.write(ciphertext1);
byte[] expected = out.toByteArray();
- // Use a connection encrypter to encrypt the plaintext
+ // Use the encryption layer to encrypt the plaintext
SegmentSink sink = new ByteArraySegmentSink();
- ConnectionEncrypter e = new SegmentedConnectionEncrypter(sink,
- Long.MAX_VALUE, tagCipher, frameCipher, tagKey, frameKey, true);
- e.writeFrame(plaintext, plaintext.length);
- e.writeFrame(plaintext1, plaintext1.length);
+ OutgoingEncryptionLayer encrypter =
+ new OutgoingSegmentedEncryptionLayer(sink, Long.MAX_VALUE,
+ tagCipher, frameCipher, tagKey, frameKey, true);
+ encrypter.writeFrame(plaintext, plaintext.length);
+ encrypter.writeFrame(plaintext1, plaintext1.length);
byte[] actual = out.toByteArray();
// Check that the actual ciphertext matches the expected ciphertext
assertArrayEquals(expected, actual);
- assertEquals(Long.MAX_VALUE - actual.length, e.getRemainingCapacity());
+ assertEquals(Long.MAX_VALUE - actual.length,
+ encrypter.getRemainingCapacity());
}
private static class ByteArraySegmentSink extends ByteArrayOutputStream