Add getting un decoded arrays and maps (#117)
This adds QCBORDecode_GetArray() and QCBORDecode_GetMap() plus friends. They return undecoded arrays and maps so they can be passed on to other decoder instances or such.
This also adds UsefulBuf_OffsetToPointer() and UsefulInputBuf_PointerToOffset() to UsefulBuf.
Consume no longer validates standard tags like big floats when it is consuming stuff. It still checks for CBOR that is not well formed.
There was some internal restructuring of array and map processing, but the tests are thorough and they are all passing.
This is to address #112
* getting started on returning arrays
* progress...
* returning maps and arrays mostly working
* Checkpoint progress
* Checkpoint: mostly working
* checkpoint -- it is working
* OffsetToPtr documentation and test
* test and documentation
* Fix Get() of nested indef arrays and maps
* Test tags; doc fixes
* Fix #ifdef test fan out
* Last bit of documentation update
---------
Co-authored-by: Laurence Lundblade <lgl@securitytheory.com>
diff --git a/test/UsefulBuf_Tests.c b/test/UsefulBuf_Tests.c
index e93a011..7e83f24 100644
--- a/test/UsefulBuf_Tests.c
+++ b/test/UsefulBuf_Tests.c
@@ -673,6 +673,22 @@
return "Incorrect pointer offset for start";
}
+ if(UsefulBuf_OffsetToPointer(Boo, 0) != &pB[0]) {
+ return "Wrong OffsetToPointer";
+ }
+
+ if(UsefulBuf_OffsetToPointer(Boo, 3) != NULL) {
+ return "Didn't validate offset correctly";
+ }
+
+ if(UsefulBuf_OffsetToPointer(Boo, 2) != &pB[2]) {
+ return "Wrong OffsetToPointer 2";
+ }
+
+ if(UsefulBuf_OffsetToPointer(NULLUsefulBufC, 2) != NULL) {
+ return "Failed OffsetToPtr on NULLUsefulBufC";
+ }
+
return NULL;
}
@@ -800,6 +816,20 @@
return "PointerToOffset not working";
}
+
+ const uint8_t pB[] = {0x01, 0x02, 0x03};
+ UsefulBufC Boo = UsefulBuf_FROM_BYTE_ARRAY_LITERAL(pB);
+
+ UsefulInputBuf_Init(&UIB, Boo);
+
+ if(UsefulInputBuf_OffsetToPointer(&UIB, 0) != &pB[0]) {
+ return "OffsetToPointer fail";
+ }
+
+ if(UsefulInputBuf_OffsetToPointer(&UIB, SIZE_MAX) != NULL) {
+ return "OffsetToPointer SIZE_MAX fail";
+ }
+
return NULL;
}