Files
briar/components/net/sf/briar/protocol/BatchIdReader.java
akwizgran a573e87c04 ReaderImpl now maintains either one or two bytes of lookahead,
depending on the value of the first byte, so that an object's initial
tag is included in the data seen by the ObjectReader. Digests and
signatures can therefore be calculated over objects by their readers
without any risk of ambiguity.
2011-07-22 17:39:59 +01:00

21 lines
597 B
Java

package net.sf.briar.protocol;
import java.io.IOException;
import net.sf.briar.api.protocol.BatchId;
import net.sf.briar.api.protocol.Tags;
import net.sf.briar.api.protocol.UniqueId;
import net.sf.briar.api.serial.FormatException;
import net.sf.briar.api.serial.ObjectReader;
import net.sf.briar.api.serial.Reader;
public class BatchIdReader implements ObjectReader<BatchId> {
public BatchId readObject(Reader r) throws IOException {
r.readUserDefinedTag(Tags.BATCH_ID);
byte[] b = r.readRaw();
if(b.length != UniqueId.LENGTH) throw new FormatException();
return new BatchId(b);
}
}