mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-21 15:19:53 +01:00
Check that EOF occurs when expected.
This commit is contained in:
@@ -28,7 +28,6 @@ import net.sf.briar.api.serial.ReaderFactory;
|
|||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
/** A bundle that deserialises its contents on demand using a reader. */
|
|
||||||
class BundleReaderImpl implements BundleReader {
|
class BundleReaderImpl implements BundleReader {
|
||||||
|
|
||||||
private static enum State { START, FIRST_BATCH, MORE_BATCHES, END };
|
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(state != State.MORE_BATCHES) throw new IllegalStateException();
|
||||||
if(r.hasListEnd()) {
|
if(r.hasListEnd()) {
|
||||||
r.readListEnd();
|
r.readListEnd();
|
||||||
|
// That should be all
|
||||||
|
if(!r.eof()) throw new FormatException();
|
||||||
state = State.END;
|
state = State.END;
|
||||||
return null;
|
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.Writer;
|
||||||
import net.sf.briar.api.serial.WriterFactory;
|
import net.sf.briar.api.serial.WriterFactory;
|
||||||
|
|
||||||
/** A bundle builder that serialises its contents using a writer. */
|
|
||||||
class BundleWriterImpl implements BundleWriter {
|
class BundleWriterImpl implements BundleWriter {
|
||||||
|
|
||||||
private static enum State { START, FIRST_BATCH, MORE_BATCHES, END };
|
private static enum State { START, FIRST_BATCH, MORE_BATCHES, END };
|
||||||
|
|||||||
@@ -60,9 +60,13 @@ class MessageParserImpl implements MessageParser {
|
|||||||
AuthorId author = new AuthorId(messageDigest.digest());
|
AuthorId author = new AuthorId(messageDigest.digest());
|
||||||
// Skip the message body
|
// Skip the message body
|
||||||
r.readRaw();
|
r.readRaw();
|
||||||
// Verify the signature
|
// Record the length of the signed data
|
||||||
int messageLength = (int) r.getRawBytesRead();
|
int messageLength = (int) r.getRawBytesRead();
|
||||||
|
// Read the signature
|
||||||
byte[] sig = r.readRaw();
|
byte[] sig = r.readRaw();
|
||||||
|
// That should be all
|
||||||
|
if(!r.eof()) throw new FormatException();
|
||||||
|
// Verify the signature
|
||||||
PublicKey publicKey;
|
PublicKey publicKey;
|
||||||
try {
|
try {
|
||||||
publicKey = keyParser.parsePublicKey(encodedKey);
|
publicKey = keyParser.parsePublicKey(encodedKey);
|
||||||
|
|||||||
Reference in New Issue
Block a user