--- a/src/lib/AbstractParser.cpp Sun Jul 11 00:44:15 2021 +0200
+++ b/src/lib/AbstractParser.cpp Sun Jul 11 18:09:19 2021 +0200
@@ -79,7 +79,7 @@
}
void AbstractParser::peek(uint8_t* buffer, const size_t length) {
- implementation->buffer.read(buffer, length);
+ implementation->buffer.peek(buffer, length);
}
size_t AbstractParser::getBytesRead() {
--- 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();