From 41c4c4d8086163dc729f3383d190fe0e2ac500d3 Mon Sep 17 00:00:00 2001 From: akwizgran <akwizgran@users.sourceforge.net> Date: Sat, 2 May 2015 21:05:23 +0100 Subject: [PATCH] Renamed raw data type. --- .../src/org/briarproject/api/data/Reader.java | 6 +- .../src/org/briarproject/api/data/Writer.java | 2 +- .../src/org/briarproject/data/ReaderImpl.java | 18 ++--- .../src/org/briarproject/data/WriterImpl.java | 6 +- .../briarproject/invitation/Connector.java | 16 ++--- .../messaging/AuthorFactoryImpl.java | 2 +- .../briarproject/messaging/AuthorReader.java | 2 +- .../messaging/GroupFactoryImpl.java | 2 +- .../briarproject/messaging/GroupReader.java | 2 +- .../messaging/MessageFactoryImpl.java | 12 ++-- .../briarproject/messaging/MessageReader.java | 8 +-- .../messaging/PacketReaderImpl.java | 6 +- .../messaging/PacketWriterImpl.java | 8 +-- .../org/briarproject/data/ReaderImplTest.java | 72 +++++++++---------- .../org/briarproject/data/WriterImplTest.java | 10 +-- .../messaging/PacketReaderImplTest.java | 12 ++-- 16 files changed, 92 insertions(+), 92 deletions(-) diff --git a/briar-api/src/org/briarproject/api/data/Reader.java b/briar-api/src/org/briarproject/api/data/Reader.java index 326f4a9e49..f8cc528d1c 100644 --- a/briar-api/src/org/briarproject/api/data/Reader.java +++ b/briar-api/src/org/briarproject/api/data/Reader.java @@ -30,9 +30,9 @@ public interface Reader { String readString(int maxLength) throws IOException; void skipString() throws IOException; - boolean hasBytes() throws IOException; - byte[] readBytes(int maxLength) throws IOException; - void skipBytes() throws IOException; + boolean hasRaw() throws IOException; + byte[] readRaw(int maxLength) throws IOException; + void skipRaw() throws IOException; boolean hasList() throws IOException; void readListStart() throws IOException; diff --git a/briar-api/src/org/briarproject/api/data/Writer.java b/briar-api/src/org/briarproject/api/data/Writer.java index ae915a992c..083313572f 100644 --- a/briar-api/src/org/briarproject/api/data/Writer.java +++ b/briar-api/src/org/briarproject/api/data/Writer.java @@ -17,7 +17,7 @@ public interface Writer { void writeInteger(long l) throws IOException; void writeFloat(double d) throws IOException; void writeString(String s) throws IOException; - void writeBytes(byte[] b) throws IOException; + void writeRaw(byte[] b) throws IOException; void writeList(Collection<?> c) throws IOException; void writeListStart() throws IOException; diff --git a/briar-core/src/org/briarproject/data/ReaderImpl.java b/briar-core/src/org/briarproject/data/ReaderImpl.java index 5011e0bf75..aadeb448c4 100644 --- a/briar-core/src/org/briarproject/data/ReaderImpl.java +++ b/briar-core/src/org/briarproject/data/ReaderImpl.java @@ -90,7 +90,7 @@ class ReaderImpl implements Reader { else if(hasInteger()) skipInteger(); else if(hasFloat()) skipFloat(); else if(hasString()) skipString(); - else if(hasBytes()) skipBytes(); + else if(hasRaw()) skipRaw(); else if(hasList()) skipList(); else if(hasMap()) skipMap(); else if(hasNull()) skipNull(); @@ -262,16 +262,16 @@ class ReaderImpl implements Reader { hasLookahead = false; } - public boolean hasBytes() throws IOException { + public boolean hasRaw() throws IOException { if(!hasLookahead) readLookahead(); if(eof) return false; return next == RAW_8 || next == RAW_16 || next == RAW_32; } - public byte[] readBytes(int maxLength) throws IOException { - if(!hasBytes()) throw new FormatException(); + public byte[] readRaw(int maxLength) throws IOException { + if(!hasRaw()) throw new FormatException(); consumeLookahead(); - int length = readBytesLength(true); + int length = readRawLength(true); if(length < 0 || length > maxLength) throw new FormatException(); if(length == 0) return EMPTY_BUFFER; byte[] b = new byte[length]; @@ -279,16 +279,16 @@ class ReaderImpl implements Reader { return b; } - private int readBytesLength(boolean consume) throws IOException { + private int readRawLength(boolean consume) throws IOException { if(next == RAW_8) return readInt8(consume); if(next == RAW_16) return readInt16(consume); if(next == RAW_32) return readInt32(consume); throw new FormatException(); } - public void skipBytes() throws IOException { - if(!hasBytes()) throw new FormatException(); - int length = readBytesLength(false); + public void skipRaw() throws IOException { + if(!hasRaw()) throw new FormatException(); + int length = readRawLength(false); if(length < 0) throw new FormatException(); skip(length); hasLookahead = false; diff --git a/briar-core/src/org/briarproject/data/WriterImpl.java b/briar-core/src/org/briarproject/data/WriterImpl.java index fa6c066345..cd0d833f6d 100644 --- a/briar-core/src/org/briarproject/data/WriterImpl.java +++ b/briar-core/src/org/briarproject/data/WriterImpl.java @@ -124,7 +124,7 @@ class WriterImpl implements Writer { write(b); } - public void writeBytes(byte[] b) throws IOException { + public void writeRaw(byte[] b) throws IOException { if(b.length <= Byte.MAX_VALUE) { write(RAW_8); write((byte) b.length); @@ -153,8 +153,8 @@ class WriterImpl implements Writer { else if(o instanceof Float) writeFloat((Float) o); else if(o instanceof Double) writeFloat((Double) o); else if(o instanceof String) writeString((String) o); - else if(o instanceof byte[]) writeBytes((byte[]) o); - else if(o instanceof Bytes) writeBytes(((Bytes) o).getBytes()); + else if(o instanceof byte[]) writeRaw((byte[]) o); + else if(o instanceof Bytes) writeRaw(((Bytes) o).getBytes()); else if(o instanceof List<?>) writeList((List<?>) o); else if(o instanceof Map<?, ?>) writeMap((Map<?, ?>) o); else if(o == null) writeNull(); diff --git a/briar-core/src/org/briarproject/invitation/Connector.java b/briar-core/src/org/briarproject/invitation/Connector.java index cf85fc9f03..c80d578ffa 100644 --- a/briar-core/src/org/briarproject/invitation/Connector.java +++ b/briar-core/src/org/briarproject/invitation/Connector.java @@ -124,14 +124,14 @@ abstract class Connector extends Thread { } protected void sendPublicKeyHash(Writer w) throws IOException { - w.writeBytes(messageDigest.digest(keyPair.getPublic().getEncoded())); + w.writeRaw(messageDigest.digest(keyPair.getPublic().getEncoded())); w.flush(); if(LOG.isLoggable(INFO)) LOG.info(pluginName + " sent hash"); } protected byte[] receivePublicKeyHash(Reader r) throws IOException { int hashLength = messageDigest.getDigestLength(); - byte[] b = r.readBytes(hashLength); + byte[] b = r.readRaw(hashLength); if(b.length < hashLength) throw new FormatException(); if(LOG.isLoggable(INFO)) LOG.info(pluginName + " received hash"); return b; @@ -139,14 +139,14 @@ abstract class Connector extends Thread { protected void sendPublicKey(Writer w) throws IOException { byte[] key = keyPair.getPublic().getEncoded(); - w.writeBytes(key); + w.writeRaw(key); w.flush(); if(LOG.isLoggable(INFO)) LOG.info(pluginName + " sent key"); } protected byte[] receivePublicKey(Reader r) throws GeneralSecurityException, IOException { - byte[] b = r.readBytes(MAX_PUBLIC_KEY_LENGTH); + byte[] b = r.readRaw(MAX_PUBLIC_KEY_LENGTH); keyParser.parsePublicKey(b); if(LOG.isLoggable(INFO)) LOG.info(pluginName + " received key"); return b; @@ -192,8 +192,8 @@ abstract class Connector extends Thread { byte[] sig = signature.sign(); // Write the name, public key and signature w.writeString(localAuthor.getName()); - w.writeBytes(localAuthor.getPublicKey()); - w.writeBytes(sig); + w.writeRaw(localAuthor.getPublicKey()); + w.writeRaw(sig); w.flush(); if(LOG.isLoggable(INFO)) LOG.info(pluginName + " sent pseudonym"); } @@ -202,8 +202,8 @@ abstract class Connector extends Thread { throws GeneralSecurityException, IOException { // Read the name, public key and signature String name = r.readString(MAX_AUTHOR_NAME_LENGTH); - byte[] publicKey = r.readBytes(MAX_PUBLIC_KEY_LENGTH); - byte[] sig = r.readBytes(MAX_SIGNATURE_LENGTH); + byte[] publicKey = r.readRaw(MAX_PUBLIC_KEY_LENGTH); + byte[] sig = r.readRaw(MAX_SIGNATURE_LENGTH); if(LOG.isLoggable(INFO)) LOG.info(pluginName + " received pseudonym"); // Verify the signature Signature signature = crypto.getSignature(); diff --git a/briar-core/src/org/briarproject/messaging/AuthorFactoryImpl.java b/briar-core/src/org/briarproject/messaging/AuthorFactoryImpl.java index 0566da46d7..9b8b3f57cc 100644 --- a/briar-core/src/org/briarproject/messaging/AuthorFactoryImpl.java +++ b/briar-core/src/org/briarproject/messaging/AuthorFactoryImpl.java @@ -45,7 +45,7 @@ class AuthorFactoryImpl implements AuthorFactory { try { w.writeListStart(); w.writeString(name); - w.writeBytes(publicKey); + w.writeRaw(publicKey); w.writeListEnd(); } catch(IOException e) { // Shouldn't happen with ByteArrayOutputStream diff --git a/briar-core/src/org/briarproject/messaging/AuthorReader.java b/briar-core/src/org/briarproject/messaging/AuthorReader.java index 1ac309eea8..467a054f96 100644 --- a/briar-core/src/org/briarproject/messaging/AuthorReader.java +++ b/briar-core/src/org/briarproject/messaging/AuthorReader.java @@ -29,7 +29,7 @@ class AuthorReader implements ObjectReader<Author> { r.readListStart(); String name = r.readString(MAX_AUTHOR_NAME_LENGTH); if(name.length() == 0) throw new FormatException(); - byte[] publicKey = r.readBytes(MAX_PUBLIC_KEY_LENGTH); + byte[] publicKey = r.readRaw(MAX_PUBLIC_KEY_LENGTH); r.readListEnd(); // Reset the reader r.removeConsumer(digesting); diff --git a/briar-core/src/org/briarproject/messaging/GroupFactoryImpl.java b/briar-core/src/org/briarproject/messaging/GroupFactoryImpl.java index 04afa129e0..f0e335bb8f 100644 --- a/briar-core/src/org/briarproject/messaging/GroupFactoryImpl.java +++ b/briar-core/src/org/briarproject/messaging/GroupFactoryImpl.java @@ -38,7 +38,7 @@ class GroupFactoryImpl implements GroupFactory { try { w.writeListStart(); w.writeString(name); - w.writeBytes(salt); + w.writeRaw(salt); w.writeListEnd(); } catch(IOException e) { // Shouldn't happen with ByteArrayOutputStream diff --git a/briar-core/src/org/briarproject/messaging/GroupReader.java b/briar-core/src/org/briarproject/messaging/GroupReader.java index db5f09b68f..84ccaf4d92 100644 --- a/briar-core/src/org/briarproject/messaging/GroupReader.java +++ b/briar-core/src/org/briarproject/messaging/GroupReader.java @@ -28,7 +28,7 @@ class GroupReader implements ObjectReader<Group> { r.readListStart(); String name = r.readString(MAX_GROUP_NAME_LENGTH); if(name.length() == 0) throw new FormatException(); - byte[] salt = r.readBytes(GROUP_SALT_LENGTH); + byte[] salt = r.readRaw(GROUP_SALT_LENGTH); if(salt.length != GROUP_SALT_LENGTH) throw new FormatException(); r.readListEnd(); r.removeConsumer(digesting); diff --git a/briar-core/src/org/briarproject/messaging/MessageFactoryImpl.java b/briar-core/src/org/briarproject/messaging/MessageFactoryImpl.java index d3e6651fb5..ec5e8f9b37 100644 --- a/briar-core/src/org/briarproject/messaging/MessageFactoryImpl.java +++ b/briar-core/src/org/briarproject/messaging/MessageFactoryImpl.java @@ -84,7 +84,7 @@ class MessageFactoryImpl implements MessageFactory { // Write the message w.writeListStart(); if(parent == null) w.writeNull(); - else w.writeBytes(parent.getBytes()); + else w.writeRaw(parent.getBytes()); writeGroup(w, group); if(author == null) w.writeNull(); else writeAuthor(w, author); @@ -92,8 +92,8 @@ class MessageFactoryImpl implements MessageFactory { w.writeInteger(timestamp); byte[] salt = new byte[MESSAGE_SALT_LENGTH]; random.nextBytes(salt); - w.writeBytes(salt); - w.writeBytes(body); + w.writeRaw(salt); + w.writeRaw(body); int bodyStart = (int) counting.getCount() - body.length; // Sign the message with the author's private key, if there is one if(privateKey == null) { @@ -103,7 +103,7 @@ class MessageFactoryImpl implements MessageFactory { byte[] sig = signature.sign(); if(sig.length > MAX_SIGNATURE_LENGTH) throw new IllegalArgumentException(); - w.writeBytes(sig); + w.writeRaw(sig); } w.writeListEnd(); // Hash the message, including the signature, to get the message ID @@ -116,14 +116,14 @@ class MessageFactoryImpl implements MessageFactory { private void writeGroup(Writer w, Group g) throws IOException { w.writeListStart(); w.writeString(g.getName()); - w.writeBytes(g.getSalt()); + w.writeRaw(g.getSalt()); w.writeListEnd(); } private void writeAuthor(Writer w, Author a) throws IOException { w.writeListStart(); w.writeString(a.getName()); - w.writeBytes(a.getPublicKey()); + w.writeRaw(a.getPublicKey()); w.writeListEnd(); } } diff --git a/briar-core/src/org/briarproject/messaging/MessageReader.java b/briar-core/src/org/briarproject/messaging/MessageReader.java index 1c7ba8bc74..66fa6999da 100644 --- a/briar-core/src/org/briarproject/messaging/MessageReader.java +++ b/briar-core/src/org/briarproject/messaging/MessageReader.java @@ -40,7 +40,7 @@ class MessageReader implements ObjectReader<UnverifiedMessage> { if(r.hasNull()) { r.readNull(); } else { - byte[] b = r.readBytes(UniqueId.LENGTH); + byte[] b = r.readRaw(UniqueId.LENGTH); if(b.length < UniqueId.LENGTH) throw new FormatException(); parent = new MessageId(b); } @@ -56,10 +56,10 @@ class MessageReader implements ObjectReader<UnverifiedMessage> { long timestamp = r.readInteger(); if(timestamp < 0) throw new FormatException(); // Read the salt - byte[] salt = r.readBytes(MESSAGE_SALT_LENGTH); + byte[] salt = r.readRaw(MESSAGE_SALT_LENGTH); if(salt.length < MESSAGE_SALT_LENGTH) throw new FormatException(); // Read the message body - byte[] body = r.readBytes(MAX_BODY_LENGTH); + byte[] body = r.readRaw(MAX_BODY_LENGTH); // Record the offset of the body within the message int bodyStart = (int) counting.getCount() - body.length; // Record the length of the data covered by the author's signature @@ -67,7 +67,7 @@ class MessageReader implements ObjectReader<UnverifiedMessage> { // Read the author's signature, if there is one byte[] signature = null; if(author == null) r.readNull(); - else signature = r.readBytes(MAX_SIGNATURE_LENGTH); + else signature = r.readRaw(MAX_SIGNATURE_LENGTH); // Read the end of the message r.readListEnd(); // Reset the reader diff --git a/briar-core/src/org/briarproject/messaging/PacketReaderImpl.java b/briar-core/src/org/briarproject/messaging/PacketReaderImpl.java index e23605654c..e5d2845b46 100644 --- a/briar-core/src/org/briarproject/messaging/PacketReaderImpl.java +++ b/briar-core/src/org/briarproject/messaging/PacketReaderImpl.java @@ -122,7 +122,7 @@ class PacketReaderImpl implements PacketReader { List<MessageId> acked = new ArrayList<MessageId>(); r.readListStart(); while(!r.hasListEnd()) { - byte[] b = r.readBytes(UniqueId.LENGTH); + byte[] b = r.readRaw(UniqueId.LENGTH); if(b.length != UniqueId.LENGTH) throw new FormatException(); acked.add(new MessageId(b)); @@ -168,7 +168,7 @@ class PacketReaderImpl implements PacketReader { List<MessageId> offered = new ArrayList<MessageId>(); r.readListStart(); while(!r.hasListEnd()) { - byte[] b = r.readBytes(UniqueId.LENGTH); + byte[] b = r.readRaw(UniqueId.LENGTH); if(b.length != UniqueId.LENGTH) throw new FormatException(); offered.add(new MessageId(b)); @@ -198,7 +198,7 @@ class PacketReaderImpl implements PacketReader { r.readListStart(); List<MessageId> requested = new ArrayList<MessageId>(); while(!r.hasListEnd()) { - byte[] b = r.readBytes(UniqueId.LENGTH); + byte[] b = r.readRaw(UniqueId.LENGTH); if(b.length != UniqueId.LENGTH) throw new FormatException(); requested.add(new MessageId(b)); diff --git a/briar-core/src/org/briarproject/messaging/PacketWriterImpl.java b/briar-core/src/org/briarproject/messaging/PacketWriterImpl.java index c2cf06003d..b084e01d6f 100644 --- a/briar-core/src/org/briarproject/messaging/PacketWriterImpl.java +++ b/briar-core/src/org/briarproject/messaging/PacketWriterImpl.java @@ -85,7 +85,7 @@ class PacketWriterImpl implements PacketWriter { Writer w = writerFactory.createWriter(payload); w.writeListStart(); w.writeListStart(); - for(MessageId m : a.getMessageIds()) w.writeBytes(m.getBytes()); + for(MessageId m : a.getMessageIds()) w.writeRaw(m.getBytes()); w.writeListEnd(); w.writeListEnd(); writePacket(ACK); @@ -103,7 +103,7 @@ class PacketWriterImpl implements PacketWriter { Writer w = writerFactory.createWriter(payload); w.writeListStart(); w.writeListStart(); - for(MessageId m : o.getMessageIds()) w.writeBytes(m.getBytes()); + for(MessageId m : o.getMessageIds()) w.writeRaw(m.getBytes()); w.writeListEnd(); w.writeListEnd(); writePacket(OFFER); @@ -114,7 +114,7 @@ class PacketWriterImpl implements PacketWriter { Writer w = writerFactory.createWriter(payload); w.writeListStart(); w.writeListStart(); - for(MessageId m : r.getMessageIds()) w.writeBytes(m.getBytes()); + for(MessageId m : r.getMessageIds()) w.writeRaw(m.getBytes()); w.writeListEnd(); w.writeListEnd(); writePacket(REQUEST); @@ -157,7 +157,7 @@ class PacketWriterImpl implements PacketWriter { for(Group g : u.getGroups()) { w.writeListStart(); w.writeString(g.getName()); - w.writeBytes(g.getSalt()); + w.writeRaw(g.getSalt()); w.writeListEnd(); } w.writeListEnd(); diff --git a/briar-tests/src/org/briarproject/data/ReaderImplTest.java b/briar-tests/src/org/briarproject/data/ReaderImplTest.java index d9e389ab89..4fcd88949f 100644 --- a/briar-tests/src/org/briarproject/data/ReaderImplTest.java +++ b/briar-tests/src/org/briarproject/data/ReaderImplTest.java @@ -330,138 +330,138 @@ public class ReaderImplTest extends BriarTestCase { } @Test - public void testReadBytes8() throws Exception { + public void testReadRaw8() throws Exception { byte[] longest = new byte[Byte.MAX_VALUE]; String longHex = StringUtils.toHexString(longest); // {1, 2, 3}, {}, and 127 zero bytes setContents("51" + "03" + "010203" + "51" + "00" + "51" + "7F" + longHex); - assertArrayEquals(new byte[] {1, 2, 3}, r.readBytes(Integer.MAX_VALUE)); - assertArrayEquals(new byte[0], r.readBytes(Integer.MAX_VALUE)); - assertArrayEquals(longest, r.readBytes(Integer.MAX_VALUE)); + assertArrayEquals(new byte[] {1, 2, 3}, r.readRaw(Integer.MAX_VALUE)); + assertArrayEquals(new byte[0], r.readRaw(Integer.MAX_VALUE)); + assertArrayEquals(longest, r.readRaw(Integer.MAX_VALUE)); assertTrue(r.eof()); } @Test - public void testReadBytes8ChecksMaxLength() throws Exception { + public void testReadRaw8ChecksMaxLength() throws Exception { // {1, 2, 3} twice setContents("51" + "03" + "010203" + "51" + "03" + "010203"); - assertArrayEquals(new byte[] {1, 2, 3}, r.readBytes(3)); - assertTrue(r.hasBytes()); + assertArrayEquals(new byte[] {1, 2, 3}, r.readRaw(3)); + assertTrue(r.hasRaw()); try { - r.readBytes(2); + r.readRaw(2); fail(); } catch(FormatException expected) {} } @Test - public void testSkipBytes8() throws Exception { + public void testSkipRaw8() throws Exception { byte[] longest = new byte[Byte.MAX_VALUE]; String longHex = StringUtils.toHexString(longest); // {1, 2, 3}, {}, and 127 zero bytes setContents("51" + "03" + "010203" + "51" + "00" + "51" + "7F" + longHex); - r.skipBytes(); - r.skipBytes(); - r.skipBytes(); + r.skipRaw(); + r.skipRaw(); + r.skipRaw(); assertTrue(r.eof()); } @Test - public void testReadBytes16() throws Exception { + public void testReadRaw16() throws Exception { byte[] shortest = new byte[Byte.MAX_VALUE + 1]; String shortHex = StringUtils.toHexString(shortest); byte[] longest = new byte[Short.MAX_VALUE]; String longHex = StringUtils.toHexString(longest); // 128 zero bytes and 2^15 - 1 zero bytes setContents("52" + "0080" + shortHex + "52" + "7FFF" + longHex); - assertArrayEquals(shortest, r.readBytes(Integer.MAX_VALUE)); - assertArrayEquals(longest, r.readBytes(Integer.MAX_VALUE)); + assertArrayEquals(shortest, r.readRaw(Integer.MAX_VALUE)); + assertArrayEquals(longest, r.readRaw(Integer.MAX_VALUE)); assertTrue(r.eof()); } @Test - public void testReadBytes16ChecksMaxLength() throws Exception { + public void testReadRaw16ChecksMaxLength() throws Exception { byte[] shortest = new byte[Byte.MAX_VALUE + 1]; String shortHex = StringUtils.toHexString(shortest); // 128 zero bytes, twice setContents("52" + "0080" + shortHex + "52" + "0080" + shortHex); - assertArrayEquals(shortest, r.readBytes(Byte.MAX_VALUE + 1)); - assertTrue(r.hasBytes()); + assertArrayEquals(shortest, r.readRaw(Byte.MAX_VALUE + 1)); + assertTrue(r.hasRaw()); try { - r.readBytes(Byte.MAX_VALUE); + r.readRaw(Byte.MAX_VALUE); fail(); } catch(FormatException expected) {} } @Test - public void testSkipBytes16() throws Exception { + public void testSkipRaw16() throws Exception { byte[] shortest = new byte[Byte.MAX_VALUE + 1]; String shortHex = StringUtils.toHexString(shortest); byte[] longest = new byte[Short.MAX_VALUE]; String longHex = StringUtils.toHexString(longest); // 128 zero bytes and 2^15 - 1 zero bytes setContents("52" + "0080" + shortHex + "52" + "7FFF" + longHex); - r.skipBytes(); - r.skipBytes(); + r.skipRaw(); + r.skipRaw(); assertTrue(r.eof()); } @Test - public void testReadBytes32() throws Exception { + public void testReadRaw32() throws Exception { byte[] shortest = new byte[Short.MAX_VALUE + 1]; String shortHex = StringUtils.toHexString(shortest); // 2^15 zero bytes setContents("54" + "00008000" + shortHex); - assertArrayEquals(shortest, r.readBytes(Integer.MAX_VALUE)); + assertArrayEquals(shortest, r.readRaw(Integer.MAX_VALUE)); assertTrue(r.eof()); } @Test - public void testReadBytes32ChecksMaxLength() throws Exception { + public void testReadRaw32ChecksMaxLength() throws Exception { byte[] shortest = new byte[Short.MAX_VALUE + 1]; String shortHex = StringUtils.toHexString(shortest); // 2^15 zero bytes, twice setContents("54" + "00008000" + shortHex + "54" + "00008000" + shortHex); - assertArrayEquals(shortest, r.readBytes(Short.MAX_VALUE + 1)); - assertTrue(r.hasBytes()); + assertArrayEquals(shortest, r.readRaw(Short.MAX_VALUE + 1)); + assertTrue(r.hasRaw()); try { - r.readBytes(Short.MAX_VALUE); + r.readRaw(Short.MAX_VALUE); fail(); } catch(FormatException expected) {} } @Test - public void testSkipBytes32() throws Exception { + public void testSkipRaw32() throws Exception { byte[] shortest = new byte[Short.MAX_VALUE + 1]; String shortHex = StringUtils.toHexString(shortest); // 2^15 zero bytes, twice setContents("54" + "00008000" + shortHex + "54" + "00008000" + shortHex); - r.skipBytes(); - r.skipBytes(); + r.skipRaw(); + r.skipRaw(); assertTrue(r.eof()); } @Test - public void testBytesMustHaveMinimalLength() throws Exception { + public void testRawMustHaveMinimalLength() throws Exception { // RAW_16 could be encoded as RAW_8 byte[] longest8 = new byte[Byte.MAX_VALUE]; String long8Hex = StringUtils.toHexString(longest8); setContents("51" + "7F" + long8Hex + "52" + "007F" + long8Hex); - assertArrayEquals(longest8, r.readBytes(Integer.MAX_VALUE)); + assertArrayEquals(longest8, r.readRaw(Integer.MAX_VALUE)); try { - r.readBytes(Integer.MAX_VALUE); + r.readRaw(Integer.MAX_VALUE); fail(); } catch(FormatException expected) {} // RAW_32 could be encoded as RAW_16 byte[] longest16 = new byte[Short.MAX_VALUE]; String long16Hex = StringUtils.toHexString(longest16); setContents("52" + "7FFF" + long16Hex + "54" + "00007FFF" + long16Hex); - assertArrayEquals(longest16, r.readBytes(Integer.MAX_VALUE)); + assertArrayEquals(longest16, r.readRaw(Integer.MAX_VALUE)); try { - r.readBytes(Integer.MAX_VALUE); + r.readRaw(Integer.MAX_VALUE); fail(); } catch(FormatException expected) {} } diff --git a/briar-tests/src/org/briarproject/data/WriterImplTest.java b/briar-tests/src/org/briarproject/data/WriterImplTest.java index ab145c0ad4..3b3be5f491 100644 --- a/briar-tests/src/org/briarproject/data/WriterImplTest.java +++ b/briar-tests/src/org/briarproject/data/WriterImplTest.java @@ -116,8 +116,8 @@ public class WriterImplTest extends BriarTestCase { public void testWriteBytes8() throws IOException { byte[] longest = new byte[Byte.MAX_VALUE]; String longHex = StringUtils.toHexString(longest); - w.writeBytes(new byte[] {1, 2, 3}); - w.writeBytes(longest); + w.writeRaw(new byte[] {1, 2, 3}); + w.writeRaw(longest); // RAW_8 tag, length 3, bytes, RAW_8 tag, length 127, bytes checkContents("51" + "03" + "010203" + "51" + "7F" + longHex); } @@ -128,8 +128,8 @@ public class WriterImplTest extends BriarTestCase { String shortHex = StringUtils.toHexString(shortest); byte[] longest = new byte[Short.MAX_VALUE]; String longHex = StringUtils.toHexString(longest); - w.writeBytes(shortest); - w.writeBytes(longest); + w.writeRaw(shortest); + w.writeRaw(longest); // RAW_16 tag, length 128, bytes, RAW_16 tag, length 2^15 - 1, bytes checkContents("52" + "0080" + shortHex + "52" + "7FFF" + longHex); } @@ -138,7 +138,7 @@ public class WriterImplTest extends BriarTestCase { public void testWriteBytes32() throws IOException { byte[] shortest = new byte[Short.MAX_VALUE + 1]; String shortHex = StringUtils.toHexString(shortest); - w.writeBytes(shortest); + w.writeRaw(shortest); // RAW_32 tag, length 2^15, bytes checkContents("54" + "00008000" + shortHex); } diff --git a/briar-tests/src/org/briarproject/messaging/PacketReaderImplTest.java b/briar-tests/src/org/briarproject/messaging/PacketReaderImplTest.java index 50ccabbd45..1f4f55e91a 100644 --- a/briar-tests/src/org/briarproject/messaging/PacketReaderImplTest.java +++ b/briar-tests/src/org/briarproject/messaging/PacketReaderImplTest.java @@ -144,9 +144,9 @@ public class PacketReaderImplTest extends BriarTestCase { w.writeListStart(); while(out.size() + UNIQUE_ID_LENGTH + LIST_END_LENGTH * 2 < HEADER_LENGTH + MAX_PAYLOAD_LENGTH) { - w.writeBytes(TestUtils.getRandomId()); + w.writeRaw(TestUtils.getRandomId()); } - if(tooBig) w.writeBytes(TestUtils.getRandomId()); + if(tooBig) w.writeRaw(TestUtils.getRandomId()); w.writeListEnd(); w.writeListEnd(); assertEquals(tooBig, out.size() > HEADER_LENGTH + MAX_PAYLOAD_LENGTH); @@ -178,9 +178,9 @@ public class PacketReaderImplTest extends BriarTestCase { w.writeListStart(); while(out.size() + UNIQUE_ID_LENGTH + LIST_END_LENGTH * 2 < HEADER_LENGTH + MAX_PAYLOAD_LENGTH) { - w.writeBytes(TestUtils.getRandomId()); + w.writeRaw(TestUtils.getRandomId()); } - if(tooBig) w.writeBytes(TestUtils.getRandomId()); + if(tooBig) w.writeRaw(TestUtils.getRandomId()); w.writeListEnd(); w.writeListEnd(); assertEquals(tooBig, out.size() > HEADER_LENGTH + MAX_PAYLOAD_LENGTH); @@ -212,9 +212,9 @@ public class PacketReaderImplTest extends BriarTestCase { w.writeListStart(); while(out.size() + UNIQUE_ID_LENGTH + LIST_END_LENGTH * 2 < HEADER_LENGTH + MAX_PAYLOAD_LENGTH) { - w.writeBytes(TestUtils.getRandomId()); + w.writeRaw(TestUtils.getRandomId()); } - if(tooBig) w.writeBytes(TestUtils.getRandomId()); + if(tooBig) w.writeRaw(TestUtils.getRandomId()); w.writeListEnd(); w.writeListEnd(); assertEquals(tooBig, out.size() > HEADER_LENGTH + MAX_PAYLOAD_LENGTH); -- GitLab