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/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index a7ef065..567f654 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -6138,8 +6138,9 @@
int32_t CBORSequenceDecodeTests(void)
{
QCBORDecodeContext DCtx;
- QCBORItem Item;
- QCBORError uCBORError;
+ QCBORItem Item;
+ QCBORError uCBORError;
+ size_t uConsumed;
// --- Test a sequence with extra bytes ---
@@ -6159,12 +6160,24 @@
return 2;
}
+ uCBORError = QCBORDecode_PartialFinish(&DCtx, &uConsumed);
+ if(uCBORError != QCBOR_ERR_EXTRA_BYTES ||
+ uConsumed != 12) {
+ return 102;
+ }
+
// Get a second item
uCBORError = QCBORDecode_GetNext(&DCtx, &Item);
if(uCBORError != QCBOR_ERR_BAD_OPT_TAG) {
return 66;
}
+ uCBORError = QCBORDecode_PartialFinish(&DCtx, &uConsumed);
+ if(uCBORError != QCBOR_ERR_EXTRA_BYTES ||
+ uConsumed != 14) {
+ return 102;
+ }
+
// Get a third item
uCBORError = QCBORDecode_GetNext(&DCtx, &Item);
if(uCBORError != QCBOR_SUCCESS) {