Skip to content
Snippets Groups Projects
Commit 308a7017 authored by akwizgran's avatar akwizgran
Browse files

Check that EOF occurs when expected.

parent e8fd3ab7
No related branches found
No related tags found
No related merge requests found
......@@ -28,7 +28,6 @@ import net.sf.briar.api.serial.ReaderFactory;
import com.google.inject.Inject;
/** A bundle that deserialises its contents on demand using a reader. */
class BundleReaderImpl implements BundleReader {
private static enum State { START, FIRST_BATCH, MORE_BATCHES, END };
......@@ -98,6 +97,8 @@ class BundleReaderImpl implements BundleReader {
if(state != State.MORE_BATCHES) throw new IllegalStateException();
if(r.hasListEnd()) {
r.readListEnd();
// That should be all
if(!r.eof()) throw new FormatException();
state = State.END;
return null;
}
......
......@@ -15,7 +15,6 @@ import net.sf.briar.api.serial.Raw;
import net.sf.briar.api.serial.Writer;
import net.sf.briar.api.serial.WriterFactory;
/** A bundle builder that serialises its contents using a writer. */
class BundleWriterImpl implements BundleWriter {
private static enum State { START, FIRST_BATCH, MORE_BATCHES, END };
......
......@@ -60,9 +60,13 @@ class MessageParserImpl implements MessageParser {
AuthorId author = new AuthorId(messageDigest.digest());
// Skip the message body
r.readRaw();
// Verify the signature
// Record the length of the signed data
int messageLength = (int) r.getRawBytesRead();
// Read the signature
byte[] sig = r.readRaw();
// That should be all
if(!r.eof()) throw new FormatException();
// Verify the signature
PublicKey publicKey;
try {
publicKey = keyParser.parsePublicKey(encodedKey);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment