src/lib/BasicASN1Reader.h
branchv_0
changeset 30 e27e133731ee
parent 29 c232d8b8efbf
child 31 a87c97aecbf6
--- a/src/lib/BasicASN1Reader.h	Sun Jul 11 00:44:15 2021 +0200
+++ b/src/lib/BasicASN1Reader.h	Sun Jul 11 18:09:19 2021 +0200
@@ -267,6 +267,17 @@
 		commit();
 	}
 
+	bool hasAvailableForReading() {
+		// TODO: API in AbstractParser for checking available bytes?
+		uint8_t tmp;
+		try {
+			peek(&tmp, 1);
+			return true;
+		} catch (...) {
+			return false;
+		}
+	}
+
 protected:
 
 	void update() override {
@@ -276,6 +287,8 @@
 public:
 
 	void close() override {
+		if (hasAvailableForReading()) throw std::logic_error("Unexpected content at the end of the stream"); // TODO: better exception
+
 		checkRemainingItems();
 		// TODO: check the bytes remaining in the buffer
 		if (started) handlers.writeStreamEnd();