Allow partial decode of CBOR sequences (#77)
Add QCBORDecode_PartialFinish() to get the offset to which decoding has progressed. Also reports error status of partial decoding.
Co-authored-by: Laurence Lundblade <lgl@securitytheory.com>
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index 8989211..b46908d 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -2391,8 +2391,12 @@
/*
* Public function, see header qcbor/qcbor_decode.h file
*/
-QCBORError QCBORDecode_Finish(QCBORDecodeContext *pMe)
+QCBORError QCBORDecode_PartialFinish(QCBORDecodeContext *pMe, size_t *puConsumed)
{
+ if(puConsumed != NULL) {
+ *puConsumed = pMe->InBuf.cursor;
+ }
+
QCBORError uReturn = pMe->uLastError;
if(uReturn != QCBOR_SUCCESS) {
@@ -2411,6 +2415,15 @@
}
Done:
+ return uReturn;
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+QCBORError QCBORDecode_Finish(QCBORDecodeContext *pMe)
+{
#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS
/* Call the destructor for the string allocator if there is one.
* Always called, even if there are errors; always have to clean up.
@@ -2418,7 +2431,7 @@
StringAllocator_Destruct(&(pMe->StringAllocator));
#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
- return uReturn;
+ return QCBORDecode_PartialFinish(pMe, NULL);
}