Option to disable all tag processing; Minor bug fix to QCBORDecode_GetDecimalFraction()
This allows disabling of all tag decoding saving about 400 bytes of object code (a lot!).
This also fixes a bug where QCBORDecode_GetDecimalFraction() and
QCBORDecode_GetDecimalFractionBig() would fail on input CBOR that is not a tag when it should succeed.
* Check point work on disabling tags
* Check point tag disable
* Checkpoint work on disabling tags
* check point
* More tests are passing
* Check point ; down to only 3 tests not passing
* all tests passing
* documentation fixes
* minor tidying
* more tidiness
* More documentation
* Check point -- more tidiness
* Check point new mant/exp tests
* main source is probably done; more testing to do
* Documentation fix
* Improve testing of mantissa and exponent a lot
* Final clean up
Co-authored-by: Laurence Lundblade <lgl@securitytheory.com>
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 431836c..742a01b 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -1758,6 +1758,10 @@
const struct someBinaryBytes *pBytes = &paNotWellFormedCBOR[nIterate];
const UsefulBufC Input = (UsefulBufC){pBytes->p, pBytes->n};
+ if(nIterate == 86) {
+ nIterate = 86;
+ }
+
// Set up decoder context. String allocator needed for indefinite
// string test cases
QCBORDecodeContext DCtx;
@@ -1814,6 +1818,11 @@
}
#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
+ const size_t nIndexx = (size_t)(pF - pFailInputs);
+ if(nIndexx == 8) {
+ uCBORError = 9;
+ }
+
// Iterate until there is an error of some sort error
QCBORItem Item;
@@ -1867,8 +1876,13 @@
{ {(uint8_t[]){0x5f, 0x80, 0xff}, 3}, QCBOR_ERR_INDEFINITE_STRING_CHUNK },
// indefinite length byte string with an map chunk
{ {(uint8_t[]){0x5f, 0xa0, 0xff}, 3}, QCBOR_ERR_INDEFINITE_STRING_CHUNK },
+#ifndef QCBOR_DISABLE_TAGS
// indefinite length byte string with tagged integer chunk
{ {(uint8_t[]){0x5f, 0xc0, 0x00, 0xff}, 4}, QCBOR_ERR_INDEFINITE_STRING_CHUNK },
+#else
+ // indefinite length byte string with tagged integer chunk
+ { {(uint8_t[]){0x5f, 0xc0, 0x00, 0xff}, 4}, QCBOR_ERR_TAGS_DISABLED },
+#endif /* QCBOR_DISABLE_TAGS */
// indefinite length byte string with an simple type chunk
{ {(uint8_t[]){0x5f, 0xe0, 0xff}, 3}, QCBOR_ERR_INDEFINITE_STRING_CHUNK },
{ {(uint8_t[]){0x5f, 0x5f, 0x41, 0x00, 0xff, 0xff}, 6}, QCBOR_ERR_INDEFINITE_STRING_CHUNK},
@@ -1999,10 +2013,12 @@
// double-precision with 3 byte argument
{ {(uint8_t[]){0xfb, 0x00, 0x00, 0x00}, 4}, QCBOR_ERR_HIT_END },
-
+#ifndef QCBOR_DISABLE_TAGS
// Tag with no content
{ {(uint8_t[]){0xc0}, 1}, QCBOR_ERR_HIT_END },
-
+#else /* QCBOR_DISABLE_TAGS */
+ { {(uint8_t[]){0xc0}, 1}, QCBOR_ERR_TAGS_DISABLED },
+#endif /* QCBOR_DISABLE_TAGS */
// Breaks must not occur in definite length arrays and maps
// Array of length 1 with sole member replaced by a break
@@ -2094,11 +2110,16 @@
{ {(uint8_t[]){0x1f}, 1}, QCBOR_ERR_BAD_INT },
// Negative integer with additional info indefinite length
{ {(uint8_t[]){0x3f}, 1}, QCBOR_ERR_BAD_INT },
+
+#ifndef QCBOR_DISABLE_TAGS
// CBOR tag with "argument" an indefinite length
{ {(uint8_t[]){0xdf, 0x00}, 2}, QCBOR_ERR_BAD_INT },
// CBOR tag with "argument" an indefinite length alternate vector
{ {(uint8_t[]){0xdf}, 1}, QCBOR_ERR_BAD_INT },
-
+#else /* QCBOR_DISABLE_TAGS */
+ { {(uint8_t[]){0xdf, 0x00}, 2}, QCBOR_ERR_TAGS_DISABLED },
+ { {(uint8_t[]){0xdf}, 1}, QCBOR_ERR_TAGS_DISABLED },
+#endif /* QCBOR_DISABLE_TAGS */
// Missing bytes from a deterministic length string
// A byte string is of length 1 without the 1 byte
@@ -2117,7 +2138,7 @@
// Text string should have 2^64 bytes, but has 3
{ {(uint8_t[]){0x7b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x01, 0x02, 0x03}, 6}, QCBOR_ERR_HIT_END },
-#else
+#else
// Byte string should have 2^32-15 bytes, but has one
{ {(uint8_t[]){0x5a, 0x00, 0x00, 0xff, 0xf0, 0x00}, 6}, QCBOR_ERR_HIT_END },
// Byte string should have 2^32-15 bytes, but has one
@@ -2191,7 +2212,7 @@
{ {(uint8_t[]){0xbf, 0x00, 0x00, 0x00, 0xff}, 5}, QCBOR_ERR_BAD_BREAK },
#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
-
+#ifndef QCBOR_DISABLE_TAGS
// In addition to not-well-formed, some invalid CBOR
// Text-based date, with an integer
{ {(uint8_t[]){0xc0, 0x00}, 2}, QCBOR_ERR_BAD_OPT_TAG },
@@ -2201,6 +2222,17 @@
{ {(uint8_t[]){0xc1, 0xc0, 0x00}, 3}, QCBOR_ERR_BAD_OPT_TAG },
// big num tagged an int, not a byte string
{ {(uint8_t[]){0xc2, 0x00}, 2}, QCBOR_ERR_BAD_OPT_TAG },
+#else /* QCBOR_DISABLE_TAGS */
+ // Text-based date, with an integer
+ { {(uint8_t[]){0xc0, 0x00}, 2}, QCBOR_ERR_TAGS_DISABLED },
+ // Epoch date, with an byte string
+ { {(uint8_t[]){0xc1, 0x41, 0x33}, 3}, QCBOR_ERR_TAGS_DISABLED },
+ // tagged as both epoch and string dates
+ { {(uint8_t[]){0xc1, 0xc0, 0x00}, 3}, QCBOR_ERR_TAGS_DISABLED },
+ // big num tagged an int, not a byte string
+ { {(uint8_t[]){0xc2, 0x00}, 2}, QCBOR_ERR_TAGS_DISABLED },
+#endif /* QCBOR_DISABLE_TAGS */
+
};
int32_t DecodeFailureTests()
@@ -2401,7 +2433,7 @@
#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
-
+/* Test date decoding using GetNext() */
int32_t DateParseTest()
{
QCBORDecodeContext DCtx;
@@ -2532,6 +2564,7 @@
return 0;
}
+
/*
Test cases covered here. Some items cover more than one of these.
positive integer (zero counts as a positive integer)
@@ -2561,7 +2594,73 @@
Untagged values
*/
static const uint8_t spSpiffyDateTestInput[] = {
- 0x86, // array of 6 items
+ 0x87, // array of 7 items
+
+ 0xa6, // Open a map for tests involving untagged items with labels.
+
+ // Untagged integer 0
+ 0x08,
+ 0x00,
+
+ // Utagged date string with string label y
+ 0x61, 0x79,
+ 0x6a, '2','0','8','5','-','0','4','-','1','2', // Untagged date string
+
+ // Untagged single-precision float with value 3.14 with string label x
+ 0x61, 0x78,
+ 0xFA, 0x40, 0x48, 0xF5, 0xC3,
+
+ // Untagged half-precision float with value -2
+ 0x09,
+ 0xF9, 0xC0, 0x00,
+
+ /* Untagged date-only date string */
+ 0x18, 0x63,
+ 0x6A, 0x31, 0x39, 0x38, 0x35, 0x2D, 0x30, 0x34, 0x2D, 0x31, 0x32, /* "1985-04-12" */
+
+ /* Untagged days-count epoch date */
+ 0x11,
+ 0x19, 0x0F, 0x9A, /* 3994 */
+
+ // End of map, back to array
+
+ 0xa7, // Open map of tagged items with labels
+
+ 0x00,
+ 0xc0, // tag for string date
+ 0x6a, '1','9','8','5','-','0','4','-','1','2', // Tagged date string
+
+
+ 0x01,
+ 0xda, 0x03, 0x03, 0x03, 0x03, // An additional tag
+ 0xc1, // tag for epoch date
+ 0x1a, 0x53, 0x72, 0x4E, 0x00, // Epoch date 1400000000; Tue, 13 May 2014 16:53:20 GMT
+
+ 0x05,
+ 0xc1,
+ 0xfb, 0xc3, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, // -9223372036854773760 largest negative
+
+
+ 0x07,
+ 0xc1, // tag for epoch date
+ 0xfb, 0x43, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, // 9223372036854773760 largest supported
+
+ /* Tagged days-count epoch date */
+ 0x63, 0x53, 0x44, 0x45,
+ 0xD8, 0x64, /* tag(100) */
+ 0x39, 0x29, 0xB3, /* -10676 */
+
+ // Untagged -1000 with label z
+ 0x61, 0x7a,
+ 0xda, 0x01, 0x01, 0x01, 0x01, // An additional tag
+ 0x39, 0x03, 0xe7,
+
+ /* Tagged date-only date string */
+ 0x63, 0x53, 0x44, 0x53,
+ 0xD9, 0x03, 0xEC,
+ 0x6A, 0x31, 0x39, 0x38, 0x35, 0x2D, 0x30, 0x34, 0x2D, 0x31, 0x32, /* "1985-04-12" */
+
+ // End of map of tagged items
0xc1,
0xfb, 0xc3, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // -9.2233720368547748E+18, too negative
@@ -2572,144 +2671,34 @@
0xc1, // tag for epoch date
0xf9, 0xfc, 0x00, // Half-precision -Infinity
- 0xad, // Open a map for tests involving labels.
-
- 0x00,
- 0xc0, // tag for string date
- 0x6a, '1','9','8','5','-','0','4','-','1','2', // Tagged date string
-
- 0x01,
- 0xda, 0x03, 0x03, 0x03, 0x03, // An additional tag
- 0xc1, // tag for epoch date
- 0x1a, 0x53, 0x72, 0x4E, 0x00, // Epoch date 1400000000; Tue, 13 May 2014 16:53:20 GMT
-
- // Untagged integer 0
- 0x08,
- 0x00,
-
- // Utagged date string with string label y
- 0x61, 0x79,
- 0x6a, '2','0','8','5','-','0','4','-','1','2', // Untagged date string
-
- // Untagged -1000 with label z
- 0x61, 0x7a,
- 0xda, 0x01, 0x01, 0x01, 0x01, // An additional tag
- 0x39, 0x03, 0xe7,
-
- 0x07,
- 0xc1, // tag for epoch date
- 0xfb, 0x43, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, // 9223372036854773760 largest supported
-
- 0x05,
- 0xc1,
- 0xfb, 0xc3, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, // -9223372036854773760 largest negative
-
- // Untagged single-precision float with value 3.14 with string label x
- 0x61, 0x78,
- 0xFA, 0x40, 0x48, 0xF5, 0xC3,
-
- // Untagged half-precision float with value -2
- 0x09,
- 0xF9, 0xC0, 0x00,
-
- /* Tagged date-only date string */
- 0x63, 0x53, 0x44, 0x53,
- 0xD9, 0x03, 0xEC,
- 0x6A, 0x31, 0x39, 0x38, 0x35, 0x2D, 0x30, 0x34, 0x2D, 0x31, 0x32, /* "1985-04-12" */
-
- /* Untagged date-only date string */
- 0x18, 0x63,
- 0x6A, 0x31, 0x39, 0x38, 0x35, 0x2D, 0x30, 0x34, 0x2D, 0x31, 0x32, /* "1985-04-12" */
-
- /* Tagged days-count epoch date */
- 0x63, 0x53, 0x44, 0x45,
- 0xD8, 0x64, /* tag(100) */
- 0x39, 0x29, 0xB3, /* -10676 */
-
- /* Untagged days-count epoch date */
- 0x11,
- 0x19, 0x0F, 0x9A, /* 3994 */
-
- // End of map, back to array
-
// These two at the end because they are unrecoverable errors
0xc1, // tag for epoch date
0x80, // Erroneous empty array as content for date
0xc0, // tag for string date
0xa0 // Erroneous empty map as content for date
-
};
int32_t SpiffyDateDecodeTest()
{
QCBORDecodeContext DC;
QCBORError uError;
- int64_t nEpochDate2, nEpochDate3, nEpochDate5,
- nEpochDate4, nEpochDate6, nEpochDateFail,
- nEpochDate1400000000, nEpochDays1, nEpochDays2;
- UsefulBufC StringDate1, StringDate2, StringDays1, StringDays2;
- uint64_t uTag1, uTag2;
+ int64_t nEpochDate3, nEpochDate5,
+ nEpochDate4, nEpochDate6,
+ nEpochDays2;
+ UsefulBufC StringDate1, StringDate2, StringDays2;
QCBORDecode_Init(&DC,
UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spSpiffyDateTestInput),
QCBOR_DECODE_MODE_NORMAL);
+
+ /* Items are in an array or map to test look up by label and other
+ * that might not occur in isolated items. But it does make the
+ * test a bit messy. */
QCBORDecode_EnterArray(&DC, NULL);
- // Too-negative float, -9.2233720368547748E+18
- QCBORDecode_GetEpochDate(&DC, QCBOR_TAG_REQUIREMENT_TAG, &nEpochDateFail);
- uError = QCBORDecode_GetAndResetError(&DC);
- if(uError != FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_ERR_DATE_OVERFLOW)) {
- return 1111;
- }
-
- // Too-large integer
- QCBORDecode_GetEpochDate(&DC, QCBOR_TAG_REQUIREMENT_TAG, &nEpochDateFail);
- uError = QCBORDecode_GetAndResetError(&DC);
- if(uError != QCBOR_ERR_DATE_OVERFLOW) {
- return 1;
- }
-
- // Half-precision minus infinity
- QCBORDecode_GetEpochDate(&DC, QCBOR_TAG_REQUIREMENT_TAG, &nEpochDateFail);
- uError = QCBORDecode_GetAndResetError(&DC);
- if(uError != FLOAT_ERR_CODE_NO_HALF_PREC_NO_FLOAT_HW(QCBOR_ERR_DATE_OVERFLOW)) {
- return 2;
- }
-
-
-
QCBORDecode_EnterMap(&DC, NULL);
- // Get largest negative double precision epoch date allowed
- QCBORDecode_GetEpochDateInMapN(&DC,
- 5,
- QCBOR_TAG_REQUIREMENT_OPTIONAL_TAG |
- QCBOR_TAG_REQUIREMENT_ALLOW_ADDITIONAL_TAGS,
- &nEpochDate2);
- uError = QCBORDecode_GetAndResetError(&DC);
- if(uError != FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_SUCCESS)) {
- return 102;
- }
- if(uError == QCBOR_SUCCESS) {
- if(nEpochDate2 != -9223372036854773760LL) {
- return 101;
- }
- }
-
- // Get largest double precision epoch date allowed
- QCBORDecode_GetEpochDateInMapN(&DC, 7, QCBOR_TAG_REQUIREMENT_OPTIONAL_TAG,
- &nEpochDate2);
- uError = QCBORDecode_GetAndResetError(&DC);
- if(uError != FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_SUCCESS)) {
- return 112;
- }
- if(uError == QCBOR_SUCCESS) {
- if(nEpochDate2 != 9223372036854773760ULL) {
- return 111;
- }
- }
-
// A single-precision date
QCBORDecode_GetEpochDateInMapSZ(&DC, "x", QCBOR_TAG_REQUIREMENT_OPTIONAL_TAG,
&nEpochDate5);
@@ -2772,6 +2761,39 @@
// The rest of these succeed even if float features are disabled
+
+ // Untagged integer 0
+ QCBORDecode_GetEpochDateInMapN(&DC, 8, QCBOR_TAG_REQUIREMENT_NOT_A_TAG,
+ &nEpochDate3);
+ // Untagged date string
+ QCBORDecode_GetDateStringInMapSZ(&DC, "y", QCBOR_TAG_REQUIREMENT_NOT_A_TAG,
+ &StringDate2);
+
+ QCBORDecode_GetDaysStringInMapN(&DC, 99, QCBOR_TAG_REQUIREMENT_NOT_A_TAG,
+ &StringDays2);
+
+ QCBORDecode_GetEpochDaysInMapN(&DC, 17, QCBOR_TAG_REQUIREMENT_NOT_A_TAG,
+ &nEpochDays2);
+
+ QCBORDecode_ExitMap(&DC);
+ if(QCBORDecode_GetError(&DC) != QCBOR_SUCCESS) {
+ return 3001;
+ }
+
+ // The map of tagged items
+ QCBORDecode_EnterMap(&DC, NULL);
+
+#ifndef QCBOR_DISABLE_TAGS
+ int64_t nEpochDate2,
+ nEpochDateFail,
+ nEpochDate1400000000, nEpochDays1;
+ UsefulBufC StringDays1;
+ uint64_t uTag1, uTag2;
+
+ // Tagged date string
+ QCBORDecode_GetDateStringInMapN(&DC, 0, QCBOR_TAG_REQUIREMENT_OPTIONAL_TAG,
+ &StringDate1);
+
// Epoch date 1400000000; Tue, 13 May 2014 16:53:20 GMT
QCBORDecode_GetEpochDateInMapN(&DC,
1,
@@ -2779,15 +2801,23 @@
QCBOR_TAG_REQUIREMENT_ALLOW_ADDITIONAL_TAGS,
&nEpochDate1400000000);
uTag1 = QCBORDecode_GetNthTagOfLast(&DC, 0);
- // Tagged date string
- QCBORDecode_GetDateStringInMapN(&DC, 0, QCBOR_TAG_REQUIREMENT_OPTIONAL_TAG,
- &StringDate1);
- // Untagged integer 0
- QCBORDecode_GetEpochDateInMapN(&DC, 8, QCBOR_TAG_REQUIREMENT_NOT_A_TAG,
- &nEpochDate3);
- // Untagged date string
- QCBORDecode_GetDateStringInMapSZ(&DC, "y", QCBOR_TAG_REQUIREMENT_NOT_A_TAG,
- &StringDate2);
+
+ // Get largest negative double precision epoch date allowed
+ QCBORDecode_GetEpochDateInMapN(&DC,
+ 5,
+ QCBOR_TAG_REQUIREMENT_OPTIONAL_TAG |
+ QCBOR_TAG_REQUIREMENT_ALLOW_ADDITIONAL_TAGS,
+ &nEpochDate2);
+ uError = QCBORDecode_GetAndResetError(&DC);
+ if(uError != FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_SUCCESS)) {
+ return 102;
+ }
+ if(uError == QCBOR_SUCCESS) {
+ if(nEpochDate2 != -9223372036854773760LL) {
+ return 101;
+ }
+ }
+
// Untagged -1000 with label z
QCBORDecode_GetEpochDateInMapSZ(&DC,
"z",
@@ -2796,6 +2826,20 @@
&nEpochDate6);
uTag2 = QCBORDecode_GetNthTagOfLast(&DC, 0);
+
+ // Get largest double precision epoch date allowed
+ QCBORDecode_GetEpochDateInMapN(&DC, 7, QCBOR_TAG_REQUIREMENT_OPTIONAL_TAG,
+ &nEpochDate2);
+ uError = QCBORDecode_GetAndResetError(&DC);
+ if(uError != FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_SUCCESS)) {
+ return 112;
+ }
+ if(uError == QCBOR_SUCCESS) {
+ if(nEpochDate2 != 9223372036854773760ULL) {
+ return 111;
+ }
+ }
+
/* The days format is much simpler than the date format
* because it can't be a floating point value. The test
* of the spiffy decode functions sufficiently covers
@@ -2807,20 +2851,36 @@
QCBORDecode_GetDaysStringInMapSZ(&DC, "SDS", QCBOR_TAG_REQUIREMENT_TAG,
&StringDays1);
- QCBORDecode_GetDaysStringInMapN(&DC, 99, QCBOR_TAG_REQUIREMENT_NOT_A_TAG,
- &StringDays2);
-
QCBORDecode_GetEpochDaysInMapSZ(&DC, "SDE", QCBOR_TAG_REQUIREMENT_TAG,
&nEpochDays1);
- QCBORDecode_GetEpochDaysInMapN(&DC, 17, QCBOR_TAG_REQUIREMENT_NOT_A_TAG,
- &nEpochDays2);
-
QCBORDecode_ExitMap(&DC);
if(QCBORDecode_GetError(&DC) != QCBOR_SUCCESS) {
return 3001;
}
+ // Too-negative float, -9.2233720368547748E+18
+ QCBORDecode_GetEpochDate(&DC, QCBOR_TAG_REQUIREMENT_TAG, &nEpochDateFail);
+ uError = QCBORDecode_GetAndResetError(&DC);
+ if(uError != FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_ERR_DATE_OVERFLOW)) {
+ return 1111;
+ }
+
+ // Too-large integer
+ QCBORDecode_GetEpochDate(&DC, QCBOR_TAG_REQUIREMENT_TAG, &nEpochDateFail);
+ uError = QCBORDecode_GetAndResetError(&DC);
+ if(uError != QCBOR_ERR_DATE_OVERFLOW) {
+ return 1;
+ }
+
+ // Half-precision minus infinity
+ QCBORDecode_GetEpochDate(&DC, QCBOR_TAG_REQUIREMENT_TAG, &nEpochDateFail);
+ uError = QCBORDecode_GetAndResetError(&DC);
+ if(uError != FLOAT_ERR_CODE_NO_HALF_PREC_NO_FLOAT_HW(QCBOR_ERR_DATE_OVERFLOW)) {
+ return 2;
+ }
+
+
// Bad content for epoch date
QCBORDecode_GetEpochDate(&DC, QCBOR_TAG_REQUIREMENT_TAG, &nEpochDateFail);
uError = QCBORDecode_GetAndResetError(&DC);
@@ -2840,6 +2900,17 @@
if(uError != QCBOR_ERR_UNRECOVERABLE_TAG_CONTENT) {
return 1000 + (int32_t)uError;
}
+#else /* QCBOR_DISABLE_TAGS */
+ QCBORDecode_GetDateStringInMapN(&DC, 0, QCBOR_TAG_REQUIREMENT_OPTIONAL_TAG,
+ &StringDate1);
+ uError = QCBORDecode_GetAndResetError(&DC);
+ if(uError != QCBOR_ERR_TAGS_DISABLED) {
+ return 4;
+ }
+#endif /* QCBOR_DISABLE_TAGS */
+
+
+#ifndef QCBOR_DISABLE_TAGS
if(nEpochDate1400000000 != 1400000000) {
return 200;
@@ -2849,36 +2920,38 @@
return 201;
}
- if(nEpochDate3 != 0) {
- return 202;
+ if(nEpochDays1 != -10676) {
+ return 205;
}
- if(nEpochDate6 != -1000) {
- return 203;
+ if(UsefulBuf_Compare(StringDays1, UsefulBuf_FromSZ("1985-04-12"))) {
+ return 207;
}
if(uTag2 != 0x01010101) {
return 204;
}
- if(nEpochDays1 != -10676) {
- return 205;
- }
-
- if(nEpochDays2 != 3994) {
- return 206;
+ if(nEpochDate6 != -1000) {
+ return 203;
}
if(UsefulBuf_Compare(StringDate1, UsefulBuf_FromSZ("1985-04-12"))) {
return 205;
}
- if(UsefulBuf_Compare(StringDate2, UsefulBuf_FromSZ("2085-04-12"))) {
+#endif /* QCBOR_DISABLE_TAGS */
+
+ if(nEpochDate3 != 0) {
+ return 202;
+ }
+
+ if(nEpochDays2 != 3994) {
return 206;
}
- if(UsefulBuf_Compare(StringDays1, UsefulBuf_FromSZ("1985-04-12"))) {
- return 207;
+ if(UsefulBuf_Compare(StringDate2, UsefulBuf_FromSZ("2085-04-12"))) {
+ return 206;
}
if(UsefulBuf_Compare(StringDays2, UsefulBuf_FromSZ("1985-04-12"))) {
@@ -2889,7 +2962,6 @@
}
-
// Input for one of the tagging tests
static const uint8_t spTagInput[] = {
0xd9, 0xd9, 0xf7, // CBOR magic number
@@ -3530,8 +3602,19 @@
return 0;
}
-
-
+/*
+ * These are showing the big numbers converted to integers.
+ * The tag numbers are not shown.
+ *
+ * [ 18446744073709551616,
+ * -18446744073709551617,
+ * {"BN+": 18446744073709551616,
+ * 64: 18446744073709551616,
+ * "BN-": -18446744073709551617,
+ * -64: -18446744073709551617
+ * }
+ * ]
+ */
static const uint8_t spBigNumInput[] = {
0x83,
@@ -3547,10 +3630,12 @@
0x38, 0x3F,
0xC3, 0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+#ifndef QCBOR_DISABLE_TAGS
/* The expected big num */
static const uint8_t spBigNum[] = {
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00};
+#endif /* QCBOR_DISABLE_TAGS */
int32_t BignumParseTest()
@@ -3571,6 +3656,7 @@
return -2;
}
+#ifndef QCBOR_DISABLE_TAGS
//
if((nCBORError = QCBORDecode_GetNext(&DCtx, &Item)))
return -3;
@@ -3627,6 +3713,12 @@
UsefulBuf_Compare(Item.val.bigNum, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBigNum))){
return -16;
}
+#else
+
+ if(QCBORDecode_GetNext(&DCtx, &Item) != QCBOR_ERR_TAGS_DISABLED) {
+ return -100;
+ }
+#endif /* QCBOR_DISABLE_TAGS */
return 0;
}
@@ -4015,6 +4107,8 @@
QCBORDecode_Init(&DC, IndefLen, QCBOR_DECODE_MODE_NORMAL);
nResult = QCBORDecode_GetNext(&DC, &Item);
+
+#ifndef QCBOR_DISABLE_TAGS
if(nResult || Item.uDataType != QCBOR_TYPE_ARRAY) {
return -18;
}
@@ -4023,6 +4117,11 @@
if(nResult != QCBOR_ERR_BAD_BREAK) {
return -19;
}
+#else /* QCBOR_DISABLE_TAGS */
+ if(nResult != QCBOR_ERR_TAGS_DISABLED) {
+ return -20;
+ }
+#endif /* QCBOR_DISABLE_TAGS */
return 0;
}
@@ -4549,41 +4648,525 @@
#ifndef QCBOR_DISABLE_EXP_AND_MANTISSA
-/* exponent, mantissa
- [
- 4([-1, 3]),
- 4([-20, 4759477275222530853136]),
- 4([9223372036854775807, -4759477275222530853137]),
- 5([300, 100]),
- 5([-20, 4759477275222530853136]),
- 5([-9223372036854775807, -4759477275222530853137])
- 5([ 9223372036854775806, -4759477275222530853137])
- 5([ 9223372036854775806, 9223372036854775806])]
- ]
- */
-static const uint8_t spExpectedExponentsAndMantissas[] = {
- 0x88,
- 0xC4, 0x82, 0x20,
- 0x03,
- 0xC4, 0x82, 0x33,
- 0xC2, 0x4A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10,
- 0xC4, 0x82, 0x1B, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xC3, 0x4A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10,
- 0xC5, 0x82, 0x19, 0x01, 0x2C,
- 0x18, 0x64,
- 0xC5, 0x82, 0x33,
- 0xC2, 0x4A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10,
- 0xC5, 0x82, 0x3B, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
- 0xC3, 0x4A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10,
- 0xC5, 0x82, 0x1B, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
- 0xC3, 0x4A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10,
- 0xC5, 0x82, 0x1B, 0x7f, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
- 0x1B, 0x7f, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE
+struct EaMTest {
+ const char *szName;
+ UsefulBufC Input;
+ uint8_t uTagRequirement;
+ bool bHasTags;
+
+ /* Expected values for GetNext */
+ QCBORError uExpectedErrorGN;
+ uint8_t uQCBORTypeGN;
+ int64_t nExponentGN;
+ int64_t nMantissaGN;
+ UsefulBufC MantissaGN;
+
+ /* Expected values for GetDecimalFraction */
+ QCBORError uExpectedErrorGDF;
+ int64_t nExponentGDF;
+ int64_t nMantissaGDF;
+
+ /* Expected values for GetDecimalFractionBig */
+ QCBORError uExpectedErrorGDFB;
+ int64_t nExponentGDFB;
+ UsefulBufC MantissaGDFB;
+ bool IsNegativeGDFB;
+
+ /* Expected values for GetBigFloat */
+ QCBORError uExpectedErrorGBF;
+ int64_t nExponentGBF;
+ int64_t nMantissaGBF;
+
+ /* Expected values for GetBigFloatBig */
+ QCBORError uExpectedErrorGBFB;
+ int64_t nExponentGBFB;
+ UsefulBufC MantissaGBFB;
+ bool IsNegativeGBFB;
};
-int32_t ExponentAndMantissaDecodeTests(void)
+
+static const struct EaMTest pEaMTests[] = {
+ {
+ "1. Untagged pair (big float or decimal fraction), no tag required",
+ {(const uint8_t []){0x82, 0x20, 0x03}, 3},
+ QCBOR_TAG_REQUIREMENT_NOT_A_TAG,
+ false,
+
+ QCBOR_SUCCESS, /* for GetNext */
+ QCBOR_TYPE_ARRAY,
+ 0,
+ 0,
+ {(const uint8_t []){0x00}, 1},
+
+ QCBOR_SUCCESS, /* GetDecimalFraction */
+ -1,
+ 3,
+
+ QCBOR_SUCCESS, /* for GetDecimalFractionBig */
+ -1,
+ {(const uint8_t []){0x03}, 1},
+ false,
+
+ QCBOR_SUCCESS, /* for GetBigFloat */
+ -1,
+ 3,
+
+ QCBOR_SUCCESS, /* for GetBigFloatBig */
+ -1,
+ {(const uint8_t []){0x03}, 1},
+ false
+ },
+
+ {
+ "2. Untagged pair (big float or decimal fraction), tag required",
+ {(const uint8_t []){0x82, 0x20, 0x03}, 3},
+ QCBOR_TAG_REQUIREMENT_TAG,
+ false,
+
+ QCBOR_SUCCESS, /* for GetNext */
+ QCBOR_TYPE_ARRAY,
+ 0,
+ 0,
+ {(const uint8_t []){0x00}, 1},
+
+ QCBOR_ERR_UNEXPECTED_TYPE, /* for GetDecimalFraction */
+ 0,
+ 0,
+
+ QCBOR_ERR_UNEXPECTED_TYPE, /* for GetDecimalFractionBig */
+ 0,
+ {(const uint8_t []){0x00}, 1},
+ false,
+
+ QCBOR_ERR_UNEXPECTED_TYPE, /* for GetBigFloat */
+ 0,
+ 0,
+
+ QCBOR_ERR_UNEXPECTED_TYPE, /* for GetBigFloatBig */
+ 0,
+ {(const uint8_t []){0x00}, 1},
+ false
+
+ },
+
+ {
+ "3. Tagged 1.5 decimal fraction, tag 4 optional",
+ {(const uint8_t []){0xC4, 0x82, 0x20, 0x03}, 4},
+ QCBOR_TAG_REQUIREMENT_OPTIONAL_TAG,
+ true,
+
+ QCBOR_SUCCESS, /* for GetNext */
+ QCBOR_TYPE_DECIMAL_FRACTION,
+ -1,
+ 3,
+ {(const uint8_t []){0x00}, 1},
+
+
+ QCBOR_SUCCESS, /* for GetDecimalFraction */
+ -1,
+ 3,
+
+ QCBOR_SUCCESS, /* for GetDecimalFractionBig */
+ -1,
+ {(const uint8_t []){0x03}, 1},
+ false,
+
+ QCBOR_ERR_UNEXPECTED_TYPE, /* for GetBigFloat */
+ 0,
+ 0,
+
+ QCBOR_ERR_UNEXPECTED_TYPE, /* for GetBigFloatBig */
+ 0,
+ {(const uint8_t []){0x00}, 1},
+ false
+ },
+ {
+ "4. Tagged 100 * 2^300 big float, tag 5 optional",
+ {(const uint8_t []){0xC5, 0x82, 0x19, 0x01, 0x2C, 0x18, 0x64}, 7},
+ QCBOR_TAG_REQUIREMENT_OPTIONAL_TAG,
+ true,
+
+ QCBOR_SUCCESS, /* for GetNext */
+ QCBOR_TYPE_BIGFLOAT,
+ 300,
+ 100,
+ {(const uint8_t []){0x00}, 1},
+
+
+ QCBOR_ERR_UNEXPECTED_TYPE, /* for GetDecimalFraction */
+ 0,
+ 0,
+
+ QCBOR_ERR_UNEXPECTED_TYPE, /* for GetDecimalFractionBig */
+ 0,
+ {(const uint8_t []){0x03}, 1},
+ false,
+
+ QCBOR_SUCCESS, /* for GetBigFloat */
+ 300,
+ 100,
+
+ QCBOR_SUCCESS, /* for GetBigFloatBig */
+ 300,
+ {(const uint8_t []){0x64}, 1},
+ false
+ },
+
+ {
+ "5. Tagged 4([-20, 4759477275222530853136]) decimal fraction, tag 4 required",
+ {(const uint8_t []){0xC4, 0x82, 0x33,
+ 0xC2, 0x4A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10,}, 15},
+ QCBOR_TAG_REQUIREMENT_TAG,
+ true,
+
+ QCBOR_SUCCESS, /* for GetNext */
+ QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM,
+ -20,
+ 0,
+ {(const uint8_t []){0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10}, 10},
+
+ QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW, /* for GetDecimalFraction */
+ 0,
+ 0,
+
+ QCBOR_SUCCESS, /* for GetDecimalFractionBig */
+ -20,
+ {(const uint8_t []){0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10}, 10},
+ false,
+
+ QCBOR_ERR_UNEXPECTED_TYPE, /* for GetBigFloat */
+ 0,
+ 0,
+
+ QCBOR_ERR_UNEXPECTED_TYPE, /* for GetBigFloatBig */
+ 0,
+ {(const uint8_t []){0x00}, 0},
+ false
+ },
+
+ {
+ "6. Error: Mantissa and exponent inside a Mantissa and exponent",
+ {(const uint8_t []){0xC4, 0x82, 0x33,
+ 0xC5, 0x82, 0x19, 0x01, 0x2C, 0x18, 0x64}, 10},
+ QCBOR_TAG_REQUIREMENT_TAG,
+ true,
+
+ QCBOR_ERR_BAD_EXP_AND_MANTISSA, /* for GetNext */
+ QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM,
+ 0,
+ 0,
+ {(const uint8_t []){0x00}, 0},
+
+ QCBOR_ERR_BAD_EXP_AND_MANTISSA, /* for GetDecimalFraction */
+ 0,
+ 0,
+
+ QCBOR_ERR_BAD_EXP_AND_MANTISSA, /* for GetDecimalFractionBig */
+ 0,
+ {(const uint8_t []){0x00}, 0},
+ false,
+
+ QCBOR_ERR_BAD_EXP_AND_MANTISSA, /* for GetBigFloat */
+ 0,
+ 0,
+
+ QCBOR_ERR_BAD_EXP_AND_MANTISSA, /* for GetBigFloatBig */
+ 0,
+ {(const uint8_t []){0x00}, 0},
+ false
+ },
+ {
+ "7. Tagged 5([-20, 4294967295]) big float, big num mantissa, tag 5 required",
+ {(const uint8_t []){0xC5, 0x82, 0x33,
+ 0xC2, 0x44, 0xff, 0xff, 0xff, 0xff}, 9},
+ QCBOR_TAG_REQUIREMENT_TAG,
+ true,
+
+ QCBOR_SUCCESS, /* for GetNext */
+ QCBOR_TYPE_BIGFLOAT_POS_BIGNUM,
+ -20,
+ 0,
+ {(const uint8_t []){0xff, 0xff, 0xff, 0xff}, 4},
+
+ QCBOR_ERR_UNEXPECTED_TYPE, /* for GetDecimalFraction */
+ 0,
+ 0,
+
+ QCBOR_ERR_UNEXPECTED_TYPE, /* for GetDecimalFractionBig */
+ -20,
+ {(const uint8_t []){0x00}, 1},
+ false,
+
+ QCBOR_SUCCESS, /* for GetBigFloat */
+ -20,
+ 4294967295,
+
+ QCBOR_SUCCESS, /* for GetBigFloatBig */
+ -20,
+ {(const uint8_t []){0xff, 0xff, 0xff, 0xff}, 4},
+ false
+ },
+
+ {
+ /* Special case for test 8. Don't renumber it. */
+ "8. Untagged pair with big num (big float or decimal fraction), tag optional",
+ {(const uint8_t []){0x82, 0x33, 0xC2, 0x4A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10}, 14},
+ QCBOR_TAG_REQUIREMENT_OPTIONAL_TAG,
+ true,
+
+ QCBOR_SUCCESS, /* for GetNext */
+ QCBOR_TYPE_ARRAY,
+ 0,
+ 0,
+ {(const uint8_t []){0x00}, 1},
+
+ QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW, /* GetDecimalFraction */
+ 0,
+ 0,
+
+ QCBOR_SUCCESS, /* for GetDecimalFractionBig */
+ -20,
+ {(const uint8_t []){0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10}, 10},
+ false,
+
+ QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW, /* for GetBigFloat */
+ 0,
+ 0,
+
+ QCBOR_SUCCESS, /* for GetBigFloatBig */
+ -20,
+ {(const uint8_t []){0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10}, 10},
+ false
+ },
+
+ {
+ "9. decimal fraction with large exponent and negative big num mantissa",
+ {(const uint8_t []){0xC4, 0x82, 0x1B, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xC3, 0x4A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10}, 23},
+ QCBOR_TAG_REQUIREMENT_OPTIONAL_TAG,
+ true,
+
+ QCBOR_SUCCESS, /* for GetNext */
+ QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM,
+ 9223372036854775807,
+ 0,
+ {(const uint8_t []){0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10}, 10},
+
+ QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW, /* GetDecimalFraction */
+ 0,
+ 0,
+
+ QCBOR_SUCCESS, /* for GetDecimalFractionBig */
+ 9223372036854775807,
+ {(const uint8_t []){0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10}, 10},
+ true,
+
+ QCBOR_ERR_UNEXPECTED_TYPE, /* for GetBigFloat */
+ 0,
+ 0,
+
+ QCBOR_ERR_UNEXPECTED_TYPE, /* for GetBigFloatBig */
+ 0,
+ {(const uint8_t []){0x00}, 1},
+ false
+ },
+};
+
+
+
+int32_t ProcessEaMTests(void)
{
+ size_t uIndex;
+ QCBORDecodeContext DCtx;
+ QCBORItem Item;
+ QCBORError uError;
+ int64_t nMantissa, nExponent;
+ MakeUsefulBufOnStack( MantissaBuf, 200);
+ UsefulBufC Mantissa;
+ bool bMantissaIsNegative;
+
+ for(uIndex = 0; uIndex < C_ARRAY_COUNT(pEaMTests, struct EaMTest); uIndex++) {
+ const struct EaMTest *pT = &pEaMTests[uIndex];
+ /* Decode with GetNext */
+ QCBORDecode_Init(&DCtx, pT->Input, 0);
+
+ if(uIndex + 1 == 9) {
+ nExponent = 99; // just to set a break point
+ }
+
+ uError = QCBORDecode_GetNext(&DCtx, &Item);
+#ifdef QCBOR_DISABLE_TAGS
+ /* Test 8 is a special case when tags are disabled */
+ if(pT->bHasTags && uIndex + 1 != 8) {
+ if(uError != QCBOR_ERR_TAGS_DISABLED) {
+ return (int32_t)(1+uIndex) * 1000 + 9;
+ }
+ } else {
+#endif
+ /* Now check return code, data type, mantissa and exponent */
+ if(pT->uExpectedErrorGN != uError) {
+ return (int32_t)(1+uIndex) * 1000 + 1;
+ }
+ if(uError == QCBOR_SUCCESS && pT->uQCBORTypeGN != QCBOR_TYPE_ARRAY) {
+ if(pT->uQCBORTypeGN != Item.uDataType) {
+ return (int32_t)(1+uIndex) * 1000 + 2;
+ }
+ if(pT->nExponentGN != Item.val.expAndMantissa.nExponent) {
+ return (int32_t)(1+uIndex) * 1000 + 3;
+ }
+ if(Item.uDataType == QCBOR_TYPE_DECIMAL_FRACTION || Item.uDataType == QCBOR_TYPE_BIGFLOAT ) {
+ if(pT->nMantissaGN != Item.val.expAndMantissa.Mantissa.nInt) {
+ return (int32_t)(1+uIndex) * 1000 + 4;
+ }
+ } else {
+ if(UsefulBuf_Compare(Item.val.expAndMantissa.Mantissa.bigNum, pT->MantissaGN)) {
+ return (int32_t)(1+uIndex) * 1000 + 5;
+ }
+ }
+ }
+#ifdef QCBOR_DISABLE_TAGS
+ }
+#endif
+
+ /* Decode with GetDecimalFraction */
+ QCBORDecode_Init(&DCtx, pT->Input, 0);
+ QCBORDecode_GetDecimalFraction(&DCtx,
+ pT->uTagRequirement,
+ &nMantissa,
+ &nExponent);
+ uError = QCBORDecode_GetAndResetError(&DCtx);
+#ifdef QCBOR_DISABLE_TAGS
+ if(pT->bHasTags) {
+ if(uError != QCBOR_ERR_TAGS_DISABLED) {
+ return (int32_t)(1+uIndex) * 1000 + 39;
+ }
+ } else {
+#endif
+ /* Now check return code, mantissa and exponent */
+ if(pT->uExpectedErrorGDF != uError) {
+ return (int32_t)(1+uIndex) * 1000 + 31;
+ }
+ if(uError == QCBOR_SUCCESS) {
+ if(pT->nExponentGDF != nExponent) {
+ return (int32_t)(1+uIndex) * 1000 + 32;
+ }
+ if(pT->nMantissaGDF != nMantissa) {
+ return (int32_t)(1+uIndex) * 1000 + 33;
+ }
+ }
+#ifdef QCBOR_DISABLE_TAGS
+ }
+#endif
+
+ /* Decode with GetDecimalFractionBig */
+ QCBORDecode_Init(&DCtx, pT->Input, 0);
+ QCBORDecode_GetDecimalFractionBig(&DCtx,
+ pT->uTagRequirement,
+ MantissaBuf,
+ &Mantissa,
+ &bMantissaIsNegative,
+ &nExponent);
+ uError = QCBORDecode_GetAndResetError(&DCtx);
+#ifdef QCBOR_DISABLE_TAGS
+ if(pT->bHasTags) {
+ if(uError != QCBOR_ERR_TAGS_DISABLED) {
+ return (int32_t)(1+uIndex) * 1000 + 49;
+ }
+ } else {
+#endif
+ /* Now check return code, mantissa (bytes and sign) and exponent */
+ if(pT->uExpectedErrorGDFB != uError) {
+ return (int32_t)(1+uIndex) * 1000 + 41;
+ }
+ if(uError == QCBOR_SUCCESS) {
+ if(pT->nExponentGDFB != nExponent) {
+ return (int32_t)(1+uIndex) * 1000 + 42;
+ }
+ if(pT->IsNegativeGDFB != bMantissaIsNegative) {
+ return (int32_t)(1+uIndex) * 1000 + 43;
+ }
+ if(UsefulBuf_Compare(Mantissa, pT->MantissaGDFB)) {
+ return (int32_t)(1+uIndex) * 1000 + 44;
+ }
+ }
+#ifdef QCBOR_DISABLE_TAGS
+ }
+#endif
+
+ /* Decode with GetBigFloat */
+ QCBORDecode_Init(&DCtx, pT->Input, 0);
+ QCBORDecode_GetBigFloat(&DCtx,
+ pT->uTagRequirement,
+ &nMantissa,
+ &nExponent);
+ uError = QCBORDecode_GetAndResetError(&DCtx);
+#ifdef QCBOR_DISABLE_TAGS
+ if(pT->bHasTags) {
+ if(uError != QCBOR_ERR_TAGS_DISABLED) {
+ return (int32_t)(1+uIndex) * 1000 + 19;
+ }
+ } else {
+#endif
+ /* Now check return code, mantissa and exponent */
+ if(pT->uExpectedErrorGBF != uError) {
+ return (int32_t)(1+uIndex) * 1000 + 11;
+ }
+ if(uError == QCBOR_SUCCESS) {
+ if(pT->nExponentGBF != nExponent) {
+ return (int32_t)(1+uIndex) * 1000 + 12;
+ }
+ if(pT->nMantissaGBF != nMantissa) {
+ return (int32_t)(1+uIndex) * 1000 + 13;
+ }
+ }
+#ifdef QCBOR_DISABLE_TAGS
+ }
+#endif
+
+ /* Decode with GetBigFloatBig */
+ QCBORDecode_Init(&DCtx, pT->Input, 0);
+ QCBORDecode_GetBigFloatBig(&DCtx,
+ pT->uTagRequirement,
+ MantissaBuf,
+ &Mantissa,
+ &bMantissaIsNegative,
+ &nExponent);
+ uError = QCBORDecode_GetAndResetError(&DCtx);
+#ifdef QCBOR_DISABLE_TAGS
+ if(pT->bHasTags) {
+ if(uError != QCBOR_ERR_TAGS_DISABLED) {
+ return (int32_t)(1+uIndex) * 1000 + 29;
+ }
+ } else {
+#endif
+ /* Now check return code, mantissa (bytes and sign) and exponent */
+ if(pT->uExpectedErrorGBFB != uError) {
+ return (int32_t)(1+uIndex) * 1000 + 21;
+ }
+ if(uError == QCBOR_SUCCESS) {
+ if(pT->nExponentGBFB != nExponent) {
+ return (int32_t)(1+uIndex) * 1000 + 22;
+ }
+ if(pT->IsNegativeGBFB != bMantissaIsNegative) {
+ return (int32_t)(1+uIndex) * 1000 + 23;
+ }
+ if(UsefulBuf_Compare(Mantissa, pT->MantissaGBFB)) {
+ return (int32_t)(1+uIndex) * 1000 + 24;
+ }
+ }
+#ifdef QCBOR_DISABLE_TAGS
+ }
+#endif
+ }
+
+ return 0;
+}
+
+
+int32_t ExponentAndMantissaDecodeTestsSecondary(void)
+{
+#ifndef QCBOR_DISABLE_TAGS
QCBORDecodeContext DC;
QCBORError uErr;
QCBORItem item;
@@ -4593,111 +5176,6 @@
UsefulBufC BN = UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBigNumMantissa);
- QCBORDecode_Init(&DC,
- UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spExpectedExponentsAndMantissas),
- QCBOR_DECODE_MODE_NORMAL);
-
- uErr = QCBORDecode_GetNext(&DC, &item);
- if(uErr != QCBOR_SUCCESS) {
- return 1;
- }
-
- if(item.uDataType != QCBOR_TYPE_ARRAY) {
- return 2;
- }
-
- uErr = QCBORDecode_GetNext(&DC, &item);
- if(uErr != QCBOR_SUCCESS) {
- return 3;
- }
-
- if(item.uDataType != QCBOR_TYPE_DECIMAL_FRACTION ||
- item.val.expAndMantissa.Mantissa.nInt != 3 ||
- item.val.expAndMantissa.nExponent != -1) {
- return 4;
- }
-
- uErr = QCBORDecode_GetNext(&DC, &item);
- if(uErr != QCBOR_SUCCESS) {
- return 5;
- }
-
- if(item.uDataType != QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM ||
- item.val.expAndMantissa.nExponent != -20 ||
- UsefulBuf_Compare(item.val.expAndMantissa.Mantissa.bigNum, BN)) {
- return 6;
- }
-
- uErr = QCBORDecode_GetNext(&DC, &item);
- if(uErr != QCBOR_SUCCESS) {
- return 7;
- }
-
- if(item.uDataType != QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM ||
- item.val.expAndMantissa.nExponent != 9223372036854775807 ||
- UsefulBuf_Compare(item.val.expAndMantissa.Mantissa.bigNum, BN)) {
- return 8;
- }
-
- uErr = QCBORDecode_GetNext(&DC, &item);
- if(uErr != QCBOR_SUCCESS) {
- return 9;
- }
-
- if(item.uDataType != QCBOR_TYPE_BIGFLOAT ||
- item.val.expAndMantissa.Mantissa.nInt != 100 ||
- item.val.expAndMantissa.nExponent != 300) {
- return 10;
- }
-
- // 5([-20, 4759477275222530853136]),
- uErr = QCBORDecode_GetNext(&DC, &item);
- if(uErr != QCBOR_SUCCESS) {
- return 11;
- }
- if(item.uDataType != QCBOR_TYPE_BIGFLOAT_POS_BIGNUM ||
- item.val.expAndMantissa.nExponent != -20 ||
- UsefulBuf_Compare(item.val.expAndMantissa.Mantissa.bigNum, BN)) {
- return 12;
- }
-
- // 5([-9223372036854775807, -4759477275222530853137])
- uErr = QCBORDecode_GetNext(&DC, &item);
- if(uErr != QCBOR_SUCCESS) {
- return 13;
- }
- if(item.uDataType != QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM ||
- item.val.expAndMantissa.nExponent != -9223372036854775807 ||
- UsefulBuf_Compare(item.val.expAndMantissa.Mantissa.bigNum, BN)) {
- return 14;
- }
-
- // 5([ 9223372036854775806, -4759477275222530853137])
- uErr = QCBORDecode_GetNext(&DC, &item);
- if(uErr != QCBOR_SUCCESS) {
- return 15;
- }
- if(item.uDataType != QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM ||
- item.val.expAndMantissa.nExponent != 9223372036854775806 ||
- UsefulBuf_Compare(item.val.expAndMantissa.Mantissa.bigNum, BN)) {
- return 16;
- }
-
- // 5([ 9223372036854775806, 9223372036854775806])]
- uErr = QCBORDecode_GetNext(&DC, &item);
- if(uErr != QCBOR_SUCCESS) {
- return 17;
- }
- if(item.uDataType != QCBOR_TYPE_BIGFLOAT ||
- item.val.expAndMantissa.nExponent != 9223372036854775806 ||
- item.val.expAndMantissa.Mantissa.nInt!= 9223372036854775806 ) {
- return 18;
- }
-
- uErr = QCBORDecode_Finish(&DC);
- if(uErr != QCBOR_SUCCESS) {
- return 18;
- }
/* Now encode some stuff and then decode it */
uint8_t pBuf[40];
@@ -4752,58 +5230,23 @@
return 106;
}
-
- int64_t nExp, nMant;
- UsefulBuf_MAKE_STACK_UB( MantBuf, 20);
- UsefulBufC Mant;
- bool bIsNeg;
-
- QCBORDecode_Init(&DC,
- UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spExpectedExponentsAndMantissas),
- QCBOR_DECODE_MODE_NORMAL);
- QCBORDecode_EnterArray(&DC, NULL);
-
- // 4([-1, 3]),
- QCBORDecode_GetDecimalFraction(&DC, QCBOR_TAG_REQUIREMENT_TAG, &nExp, &nMant);
-
- // 4([-20, 4759477275222530853136]),
- QCBORDecode_GetDecimalFractionBig(&DC, QCBOR_TAG_REQUIREMENT_TAG, MantBuf,
- &Mant, &bIsNeg, &nExp);
-
- // 4([9223372036854775807, -4759477275222530853137]),
- QCBORDecode_GetDecimalFractionBig(&DC, QCBOR_TAG_REQUIREMENT_OPTIONAL_TAG,
- MantBuf, &Mant, &bIsNeg, &nExp);
-
- // 5([300, 100]),
- QCBORDecode_GetBigFloat(&DC, QCBOR_TAG_REQUIREMENT_TAG, &nExp, &nMant);
-
- // 5([-20, 4759477275222530853136]),
- QCBORDecode_GetBigFloatBig(&DC, QCBOR_TAG_REQUIREMENT_TAG, MantBuf, &Mant,
- &bIsNeg, &nExp);
-
- // 5([-9223372036854775807, -4759477275222530853137])
- QCBORDecode_GetBigFloatBig(&DC, QCBOR_TAG_REQUIREMENT_TAG, MantBuf, &Mant,
- &bIsNeg, &nExp);
-
- // 5([ 9223372036854775806, -4759477275222530853137])
- QCBORDecode_GetBigFloatBig(&DC, QCBOR_TAG_REQUIREMENT_TAG, MantBuf, &Mant,
- &bIsNeg, &nExp);
-
- // 5([ 9223372036854775806, 9223372036854775806])]
- QCBORDecode_GetBigFloatBig(&DC, QCBOR_TAG_REQUIREMENT_TAG, MantBuf, &Mant,
- &bIsNeg, &nExp);
-
- QCBORDecode_ExitArray(&DC);
-
- uErr = QCBORDecode_Finish(&DC);
- if(uErr != QCBOR_SUCCESS) {
- return 200;
- }
+#endif /* QCBOR_TAGS_DISABLED */
return 0;
}
+int32_t ExponentAndMantissaDecodeTests(void)
+{
+ int32_t rv = ProcessEaMTests();
+ if(rv) {
+ return rv;
+ }
+
+ return ExponentAndMantissaDecodeTestsSecondary();
+}
+
+
static const struct FailInput ExponentAndMantissaFailures[] = {
// Exponent > INT64_MAX
{ {(uint8_t[]){0xC4, 0x82, 0x1B, 0x7f, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
@@ -5211,10 +5654,14 @@
}
*/
static const uint8_t spRecoverableMapErrors[] = {
+#ifndef QCBOR_DISABLE_TAGS
0xa6,
- 0x01, 0xd8, 0xe0, 0xd8, 0xe1, 0xd8, 0xe2, 0xd8, 0xe3, 0xd8, 0x04, 0x00,
- 0x03, 0x3b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x04, 0xc1, 0xfb, 0x7e, 0x37, 0xe4, 0x3c, 0x88, 0x00, 0x75, 0x9c,
+ 0x01, 0xd8, 0xe0, 0xd8, 0xe1, 0xd8, 0xe2, 0xd8, 0xe3, 0xd8, 0x04, 0x00,
+#else
+ 0xa4,
+#endif
+ 0x03, 0x3b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x05, 0x00,
0x05, 0x00,
0x08, 0x08,
@@ -5487,6 +5934,7 @@
int64_t nInt;
QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spRecoverableMapErrors), 0);
QCBORDecode_EnterMap(&DCtx, NULL);
+#ifndef QCBOR_DISABLE_TAGS
QCBORDecode_GetInt64InMapN(&DCtx, 0x01, &nInt);
uErr = QCBORDecode_GetError(&DCtx);
if(uErr != QCBOR_ERR_TOO_MANY_TAGS) {
@@ -5496,6 +5944,7 @@
return 2121;
}
(void)QCBORDecode_GetAndResetError(&DCtx);
+#endif
QCBORDecode_GetInt64InMapN(&DCtx, 0x03, &nInt);
@@ -5504,11 +5953,13 @@
return 2023;
}
+#ifndef QCBOR_DISABLE_TAGS
QCBORDecode_GetEpochDateInMapN(&DCtx, 0x04, QCBOR_TAG_REQUIREMENT_TAG, &nInt);
uErr = QCBORDecode_GetAndResetError(&DCtx);
if(uErr != FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_ERR_DATE_OVERFLOW)) {
return 2024;
}
+#endif
QCBORDecode_GetInt64InMapN(&DCtx, 0x05, &nInt);
uErr = QCBORDecode_GetAndResetError(&DCtx);
@@ -5623,6 +6074,7 @@
return 2600;
}
+#ifndef QCBOR_DISABLE_TAGS
QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBadConsumeInput2), 0);
QCBORDecode_VGetNextConsume(&DCtx, &Item1);
if(QCBORDecode_GetError(&DCtx) != QCBOR_SUCCESS) {
@@ -5634,6 +6086,8 @@
if(QCBORDecode_GetError(&DCtx) != QCBOR_ERR_UNRECOVERABLE_TAG_CONTENT) {
return 2800;
}
+#endif
+
QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBadConsumeInput4), 0);
QCBORDecode_VGetNextConsume(&DCtx, &Item1);
@@ -5676,6 +6130,7 @@
static const struct NumberConversion NumberConversions[] = {
+#ifndef QCBOR_DISABLE_TAGS
{
"too large to fit into int64_t",
{(uint8_t[]){0xc3, 0x48, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 10},
@@ -5794,77 +6249,6 @@
FLOAT_ERR_CODE_NO_FLOAT_HW(EXP_AND_MANTISSA_ERROR(QCBOR_SUCCESS))
},
{
- "Positive integer 18446744073709551615",
- {(uint8_t[]){0x1b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 9},
- 0,
- QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW,
- 18446744073709551615ULL,
- QCBOR_SUCCESS,
- 18446744073709551615.0,
- FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_SUCCESS)
- },
- {
- "Positive bignum 0xffff",
- {(uint8_t[]){0xC2, 0x42, 0xff, 0xff}, 4},
- 65536-1,
- QCBOR_SUCCESS,
- 0xffff,
- QCBOR_SUCCESS,
- 65535.0,
- FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_SUCCESS)
- },
- {
- "Postive integer 0",
- {(uint8_t[]){0x0}, 1},
- 0LL,
- QCBOR_SUCCESS,
- 0ULL,
- QCBOR_SUCCESS,
- 0.0,
- FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_SUCCESS)
- },
- {
- "Negative integer -18446744073709551616",
- {(uint8_t[]){0x3b, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, 9},
- -9223372036854775807-1, // INT64_MIN
- QCBOR_SUCCESS,
- 0ULL,
- QCBOR_ERR_NUMBER_SIGN_CONVERSION,
- -9223372036854775808.0,
- FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_SUCCESS)
- },
- {
- "Double Floating point value 100.3",
- {(uint8_t[]){0xfb, 0x40, 0x59, 0x13, 0x33, 0x33, 0x33, 0x33, 0x33}, 9},
- 100L,
- FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_SUCCESS),
- 100ULL,
- FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_SUCCESS),
- 100.3,
- FLOAT_ERR_CODE_NO_FLOAT(QCBOR_SUCCESS),
- },
- {
- "Floating point value NaN 0xfa7fc00000",
- {(uint8_t[]){0xfa, 0x7f, 0xc0, 0x00, 0x00}, 5},
- 0,
- FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_ERR_FLOAT_EXCEPTION),
- 0,
- FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_ERR_FLOAT_EXCEPTION),
- NAN,
- FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_SUCCESS),
- },
- {
- "half-precision Floating point value -4",
- {(uint8_t[]){0xf9, 0xc4, 0x00}, 3},
- // Normal case with all enabled.
- -4,
- FLOAT_ERR_CODE_NO_HALF_PREC_NO_FLOAT_HW(QCBOR_SUCCESS),
- 0,
- FLOAT_ERR_CODE_NO_HALF_PREC_NO_FLOAT_HW(QCBOR_ERR_NUMBER_SIGN_CONVERSION),
- -4.0,
- FLOAT_ERR_CODE_NO_HALF_PREC(QCBOR_SUCCESS)
- },
- {
"Decimal fraction 3/10",
{(uint8_t[]){0xC4, 0x82, 0x20, 0x03}, 4},
0,
@@ -5875,17 +6259,6 @@
FLOAT_ERR_CODE_NO_FLOAT_HW(EXP_AND_MANTISSA_ERROR(QCBOR_SUCCESS))
},
{
- "+inifinity single precision",
- {(uint8_t[]){0xfa, 0x7f, 0x80, 0x00, 0x00}, 5},
- 0,
- FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_ERR_FLOAT_EXCEPTION),
- 0,
- FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW),
- INFINITY,
- FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_SUCCESS)
- },
-
- {
"extreme pos bignum",
{(uint8_t[]){0xc2, 0x59, 0x01, 0x90,
// 50 rows of 8 is 400 digits.
@@ -6038,6 +6411,90 @@
-INFINITY,
FLOAT_ERR_CODE_NO_FLOAT_HW(EXP_AND_MANTISSA_ERROR(QCBOR_SUCCESS))
},
+ {
+ "Positive bignum 0xffff",
+ {(uint8_t[]){0xC2, 0x42, 0xff, 0xff}, 4},
+ 65536-1,
+ QCBOR_SUCCESS,
+ 0xffff,
+ QCBOR_SUCCESS,
+ 65535.0,
+ FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_SUCCESS)
+ },
+#endif /* QCBOR_DISABLE_TAGS */
+ {
+ "Positive integer 18446744073709551615",
+ {(uint8_t[]){0x1b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 9},
+ 0,
+ QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW,
+ 18446744073709551615ULL,
+ QCBOR_SUCCESS,
+ 18446744073709551615.0,
+ FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_SUCCESS)
+ },
+
+ {
+ "Postive integer 0",
+ {(uint8_t[]){0x0}, 1},
+ 0LL,
+ QCBOR_SUCCESS,
+ 0ULL,
+ QCBOR_SUCCESS,
+ 0.0,
+ FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_SUCCESS)
+ },
+ {
+ "Negative integer -18446744073709551616",
+ {(uint8_t[]){0x3b, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, 9},
+ -9223372036854775807-1, // INT64_MIN
+ QCBOR_SUCCESS,
+ 0ULL,
+ QCBOR_ERR_NUMBER_SIGN_CONVERSION,
+ -9223372036854775808.0,
+ FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_SUCCESS)
+ },
+ {
+ "Double Floating point value 100.3",
+ {(uint8_t[]){0xfb, 0x40, 0x59, 0x13, 0x33, 0x33, 0x33, 0x33, 0x33}, 9},
+ 100L,
+ FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_SUCCESS),
+ 100ULL,
+ FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_SUCCESS),
+ 100.3,
+ FLOAT_ERR_CODE_NO_FLOAT(QCBOR_SUCCESS),
+ },
+ {
+ "Floating point value NaN 0xfa7fc00000",
+ {(uint8_t[]){0xfa, 0x7f, 0xc0, 0x00, 0x00}, 5},
+ 0,
+ FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_ERR_FLOAT_EXCEPTION),
+ 0,
+ FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_ERR_FLOAT_EXCEPTION),
+ NAN,
+ FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_SUCCESS),
+ },
+ {
+ "half-precision Floating point value -4",
+ {(uint8_t[]){0xf9, 0xc4, 0x00}, 3},
+ // Normal case with all enabled.
+ -4,
+ FLOAT_ERR_CODE_NO_HALF_PREC_NO_FLOAT_HW(QCBOR_SUCCESS),
+ 0,
+ FLOAT_ERR_CODE_NO_HALF_PREC_NO_FLOAT_HW(QCBOR_ERR_NUMBER_SIGN_CONVERSION),
+ -4.0,
+ FLOAT_ERR_CODE_NO_HALF_PREC(QCBOR_SUCCESS)
+ },
+ {
+ "+inifinity single precision",
+ {(uint8_t[]){0xfa, 0x7f, 0x80, 0x00, 0x00}, 5},
+ 0,
+ FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_ERR_FLOAT_EXCEPTION),
+ 0,
+ FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW),
+ INFINITY,
+ FLOAT_ERR_CODE_NO_FLOAT_HW(QCBOR_SUCCESS)
+ },
+
};
@@ -6155,6 +6612,23 @@
#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
+
+
+static const uint8_t spSequenceTestInput[] = {
+ /* 1. The valid date string "1985-04-12" */
+ 0x6a, '1','9','8','5','-','0','4','-','1','2', // Date string
+
+ /* 2. */
+ 0x00,
+
+ /* 3. A valid epoch date, 1400000000; Tue, 13 May 2014 16:53:20 GMT */
+ 0x1a, 0x53, 0x72, 0x4E, 0x00,
+
+ /* 4. */
+ 0x62, 'h', 'i',
+};
+
+
int32_t CBORSequenceDecodeTests(void)
{
QCBORDecodeContext DCtx;
@@ -6164,46 +6638,43 @@
// --- Test a sequence with extra bytes ---
- // The input for the date test happens to be a sequence so it
- // is reused. It is a sequence because it doesn't start as
- // an array or map.
QCBORDecode_Init(&DCtx,
- UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spDateTestInput),
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spSequenceTestInput),
QCBOR_DECODE_MODE_NORMAL);
- // Get the first item
+ // Get 1.
uCBORError = QCBORDecode_GetNext(&DCtx, &Item);
if(uCBORError != QCBOR_SUCCESS) {
return 1;
}
- if(Item.uDataType != QCBOR_TYPE_DATE_STRING) {
+ if(Item.uDataType != QCBOR_TYPE_TEXT_STRING ) {
return 2;
}
uCBORError = QCBORDecode_PartialFinish(&DCtx, &uConsumed);
if(uCBORError != QCBOR_ERR_EXTRA_BYTES ||
+ uConsumed != 11) {
+ return 102;
+ }
+
+ // Get 2.
+ uCBORError = QCBORDecode_GetNext(&DCtx, &Item);
+ if(uCBORError != QCBOR_SUCCESS) {
+ return 66;
+ }
+
+ 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
+ // Get 3.
uCBORError = QCBORDecode_GetNext(&DCtx, &Item);
if(uCBORError != QCBOR_SUCCESS) {
return 2;
}
- if(Item.uDataType != QCBOR_TYPE_DATE_EPOCH) {
+ if(Item.uDataType != QCBOR_TYPE_INT64) {
return 3;
}
@@ -6220,7 +6691,6 @@
return 4;
}
-
// --- Test an empty input ----
uint8_t empty[1];
UsefulBufC Empty = {empty, 0};
@@ -7034,6 +7504,12 @@
#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS
+/*
+ An array of three map entries
+ 1) Indefinite length string label for indefinite lenght byte string
+ 2) Indefinite length string label for an integer
+ 3) Indefinite length string label for an indefinite-length negative big num
+ */
static const uint8_t spMapWithIndefLenStrings[] = {
0xa3,
0x7f, 0x61, 'l', 0x64, 'a', 'b', 'e', 'l' , 0x61, '1', 0xff,
@@ -7059,6 +7535,8 @@
UsefulBufC ByteString;
QCBORDecode_EnterMap(&DCtx, NULL);
QCBORDecode_GetByteStringInMapSZ(&DCtx, "label1", &ByteString);
+
+#ifndef QCBOR_DISABLE_TAGS
if(QCBORDecode_GetAndResetError(&DCtx)) {
return 1;
}
@@ -7083,6 +7561,7 @@
"label2",
0xff,
&uDouble);
+
#ifndef QCBOR_DISABLE_FLOAT_HW_USE
if(QCBORDecode_GetAndResetError(&DCtx)) {
return 5;
@@ -7097,13 +7576,23 @@
#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
-
QCBORDecode_ExitMap(&DCtx);
if(QCBORDecode_Finish(&DCtx)) {
return 99;
}
+#else /* QCBOR_DISABLE_TAGS */
+ /* The big num in the input is a CBOR tag and you can't do
+ * map lookups in a map with a tag so this test does very little
+ * when tags are disabled. That is OK, the test coverage is still
+ * good when they are not.
+ */
+ if(QCBORDecode_GetAndResetError(&DCtx) != QCBOR_ERR_TAGS_DISABLED) {
+ return 1002;
+ }
+#endif /*QCBOR_DISABLE_TAGS */
+
return 0;
}
#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
@@ -7179,6 +7668,20 @@
#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS
+
+/*
+An array of one that contains
+ a byte string that is tagged 24 which means CBOR-encoded data
+ the byte string is an indefinite length string
+ the wrapped byte string is an array of three numbers
+ [42, 43, 44]
+
+[
+ 24(
+ (_ h'83', h'18', h'2A182B', h'182C')
+ )
+]
+ */
static const uint8_t pWrappedByIndefiniteLength[] = {
0x81,
0xd8, 0x18,
@@ -7779,6 +8282,7 @@
// Rewind an indefnite length byte-string wrapped sequence
#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS
+ // TODO: rewrite this test to not use tags
QCBORDecode_Init(&DCtx,
UsefulBuf_FROM_BYTE_ARRAY_LITERAL(pWrappedByIndefiniteLength),
0);
@@ -7787,11 +8291,13 @@
QCBORDecode_EnterArray(&DCtx, NULL);
QCBORDecode_EnterBstrWrapped(&DCtx, 2, NULL);
+#ifndef QCBOR_DISABLE_TAGS
if(QCBORDecode_GetError(&DCtx) != QCBOR_ERR_INPUT_TOO_LARGE) {
- /* this is what happens when trying to enter
- indefinite-length byte string
- wrapped CBOR. Tolerate for now. Eventually it needs
- to be fixed so this works, but that is not simple. */
+ /* TODO: This is what happens when trying to enter
+ * indefinite-length byte string wrapped CBOR. Tolerate for
+ * now. Eventually it needs to be fixed so this works, but that
+ * is not simple.
+ */
return 7300;
}
@@ -7805,6 +8311,13 @@
if(i != 42) {
return 7220;
}*/
+
+#else /* QCBOR_DISABLE_TAGS */
+ if(QCBORDecode_GetError(&DCtx) != QCBOR_ERR_TAGS_DISABLED) {
+ return 7301;
+ }
+#endif /* QCBOR_DISABLE_TAGS */
+
#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */