diff -r c232d8b8efbf -r e27e133731ee src/lib/BasicASN1Reader.h --- 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();