Check that EOF occurs when expected.

This commit is contained in:
akwizgran
2011-07-15 20:23:59 +01:00
parent e8fd3ab7a3
commit 308a7017be
3 changed files with 7 additions and 3 deletions

View File

@@ -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;
}

View File

@@ -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 };

View File

@@ -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);