Removed unnecessary Raw interface.

This commit is contained in:
akwizgran
2011-07-24 17:47:17 +01:00
parent 941460e3bc
commit c98c968b87
24 changed files with 80 additions and 115 deletions

View File

@@ -13,7 +13,7 @@ class BatchIdReader implements ObjectReader<BatchId> {
public BatchId readObject(Reader r) throws IOException {
r.readUserDefinedTag(Tags.BATCH_ID);
byte[] b = r.readRaw();
byte[] b = r.readBytes();
if(b.length != UniqueId.LENGTH) throw new FormatException();
return new BatchId(b);
}

View File

@@ -13,7 +13,7 @@ class GroupIdReader implements ObjectReader<GroupId> {
public GroupId readObject(Reader r) throws IOException {
r.readUserDefinedTag(Tags.GROUP_ID);
byte[] b = r.readRaw();
byte[] b = r.readBytes();
if(b.length != UniqueId.LENGTH) throw new FormatException();
return new GroupId(b);
}

View File

@@ -53,8 +53,8 @@ class GroupImpl implements Group {
w.writeUserDefinedTag(Tags.GROUP);
w.writeString(name);
w.writeBoolean(isRestricted());
if(salt == null) w.writeRaw(publicKey.getEncoded());
else w.writeRaw(salt);
if(salt == null) w.writeBytes(publicKey.getEncoded());
else w.writeBytes(salt);
}
@Override

View File

@@ -29,7 +29,7 @@ class GroupReader implements ObjectReader<Group> {
r.readUserDefinedTag(Tags.GROUP);
String name = r.readString();
boolean restricted = r.readBoolean();
byte[] saltOrKey = r.readRaw();
byte[] saltOrKey = r.readBytes();
r.removeConsumer(digesting);
// Build and return the group
GroupId id = new GroupId(messageDigest.digest());

View File

@@ -44,8 +44,8 @@ class MessageEncoderImpl implements MessageEncoder {
group.writeTo(w);
w.writeInt64(timestamp);
w.writeString(nick);
w.writeRaw(keyPair.getPublic().getEncoded());
w.writeRaw(body);
w.writeBytes(keyPair.getPublic().getEncoded());
w.writeBytes(body);
// Sign the message
byte[] signable = out.toByteArray();
signature.initSign(keyPair.getPrivate());
@@ -53,7 +53,7 @@ class MessageEncoderImpl implements MessageEncoder {
byte[] sig = signature.sign();
signable = null;
// Write the signature
w.writeRaw(sig);
w.writeBytes(sig);
byte[] raw = out.toByteArray();
// The message ID is the hash of the entire message
messageDigest.reset();
@@ -63,7 +63,7 @@ class MessageEncoderImpl implements MessageEncoder {
out.reset();
w = writerFactory.createWriter(out);
w.writeString(nick);
w.writeRaw(keyPair.getPublic().getEncoded());
w.writeBytes(keyPair.getPublic().getEncoded());
messageDigest.reset();
messageDigest.update(out.toByteArray());
AuthorId authorId = new AuthorId(messageDigest.digest());

View File

@@ -41,12 +41,12 @@ class MessageReader implements ObjectReader<Message> {
r.readUserDefinedTag(Tags.MESSAGE);
// Read the parent's message ID
r.readUserDefinedTag(Tags.MESSAGE_ID);
byte[] b = r.readRaw();
byte[] b = r.readBytes();
if(b.length != UniqueId.LENGTH) throw new FormatException();
MessageId parent = new MessageId(b);
// Read the group ID
r.readUserDefinedTag(Tags.GROUP_ID);
b = r.readRaw();
b = r.readBytes();
if(b.length != UniqueId.LENGTH) throw new FormatException();
GroupId group = new GroupId(b);
// Read the timestamp
@@ -57,15 +57,15 @@ class MessageReader implements ObjectReader<Message> {
messageDigest.reset();
r.addConsumer(digesting);
r.readString();
byte[] encodedKey = r.readRaw();
byte[] encodedKey = r.readBytes();
r.removeConsumer(digesting);
AuthorId author = new AuthorId(messageDigest.digest());
// Skip the message body
r.readRaw();
r.readBytes();
// Record the length of the signed data
int messageLength = (int) counting.getCount();
// Read the signature
byte[] sig = r.readRaw();
byte[] sig = r.readBytes();
r.removeConsumer(counting);
r.removeConsumer(copying);
// Verify the signature

View File

@@ -7,10 +7,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.briar.api.serial.Bytes;
import net.sf.briar.api.serial.Consumer;
import net.sf.briar.api.serial.FormatException;
import net.sf.briar.api.serial.ObjectReader;
import net.sf.briar.api.serial.RawByteArray;
import net.sf.briar.api.serial.Reader;
import net.sf.briar.api.serial.Tag;
@@ -309,25 +309,25 @@ class ReaderImpl implements Reader {
|| next == Tag.INT32;
}
public boolean hasRaw() throws IOException {
public boolean hasBytes() throws IOException {
if(!started) readNext(true);
if(eof) return false;
return next == Tag.RAW || (next & Tag.SHORT_MASK) == Tag.SHORT_RAW;
return next == Tag.BYTES || (next & Tag.SHORT_MASK) == Tag.SHORT_BYTES;
}
public byte[] readRaw() throws IOException {
if(!hasRaw()) throw new FormatException();
if(next == Tag.RAW) {
public byte[] readBytes() throws IOException {
if(!hasBytes()) throw new FormatException();
if(next == Tag.BYTES) {
readNext(false);
return readRaw(readLength());
return readBytes(readLength());
} else {
int length = 0xFF & next ^ Tag.SHORT_RAW;
int length = 0xFF & next ^ Tag.SHORT_BYTES;
readNext(length == 0);
return readRaw(length);
return readBytes(length);
}
}
private byte[] readRaw(int length) throws IOException {
private byte[] readBytes(int length) throws IOException {
assert length >= 0;
if(length == 0) return EMPTY_BUFFER;
byte[] b = new byte[length];
@@ -395,7 +395,7 @@ class ReaderImpl implements Reader {
if(hasFloat32()) return Float.valueOf(readFloat32());
if(hasFloat64()) return Double.valueOf(readFloat64());
if(hasString()) return readString();
if(hasRaw()) return new RawByteArray(readRaw());
if(hasBytes()) return new Bytes(readBytes());
if(hasList()) return readList();
if(hasMap()) return readMap();
if(hasNull()) {

View File

@@ -7,7 +7,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import net.sf.briar.api.serial.Raw;
import net.sf.briar.api.serial.Bytes;
import net.sf.briar.api.serial.Tag;
import net.sf.briar.api.serial.Writable;
import net.sf.briar.api.serial.Writer;
@@ -123,20 +123,16 @@ class WriterImpl implements Writer {
else writeInt32(i);
}
public void writeRaw(byte[] b) throws IOException {
if(b.length < 16) out.write((byte) (Tag.SHORT_RAW | b.length));
public void writeBytes(byte[] b) throws IOException {
if(b.length < 16) out.write((byte) (Tag.SHORT_BYTES | b.length));
else {
out.write(Tag.RAW);
out.write(Tag.BYTES);
writeLength(b.length);
}
out.write(b);
bytesWritten += b.length + 1;
}
public void writeRaw(Raw r) throws IOException {
writeRaw(r.getBytes());
}
public void writeList(Collection<?> c) throws IOException {
int length = c.size();
if(length < 16) out.write((byte) (Tag.SHORT_LIST | length));
@@ -158,7 +154,7 @@ class WriterImpl implements Writer {
else if(o instanceof Float) writeFloat32((Float) o);
else if(o instanceof Double) writeFloat64((Double) o);
else if(o instanceof String) writeString((String) o);
else if(o instanceof Raw) writeRaw((Raw) o);
else if(o instanceof Bytes) writeBytes(((Bytes) o).getBytes());
else if(o instanceof List) writeList((List<?>) o);
else if(o instanceof Map) writeMap((Map<?, ?>) o);
else if(o == null) writeNull();