Generalize decode failure testing; close out TODO's (#212)
This closes out two testing TODO items.
The input structure for testing failures is more general.
This PR only affected testing to make the test code nicer (it will help to test dCBOR).
* Generalizing decode failure testing
* Finish converting all failures tests
* Convert EAM test inputs
---------
Co-authored-by: Laurence Lundblade <lgl@securitytheory.com>
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index bc91b72..77514de 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -1,12 +1,12 @@
/*==============================================================================
- Copyright (c) 2016-2018, The Linux Foundation.
- Copyright (c) 2018-2022, Laurence Lundblade.
- Copyright (c) 2021, Arm Limited.
- All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
+ * Copyright (c) 2016-2018, The Linux Foundation.
+ * Copyright (c) 2018-2024, Laurence Lundblade.
+ * Copyright (c) 2021, Arm Limited.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
@@ -1792,57 +1792,58 @@
}
-// TODO: add a test index and report it so it is eaier to figure out which test failed.
-struct FailInput {
- UsefulBufC Input;
- QCBORError nError;
+struct DecodeFailTestInput {
+ const char *szDescription; /* Description of the test */
+ QCBORDecodeMode DecoderMode; /* The QCBOR Decoder Mode for test */
+ UsefulBufC Input; /* Chunk of CBOR that cases error */
+ QCBORError nError; /* The expected error */
};
-static int32_t ProcessFailures(const struct FailInput *pFailInputs, size_t nNumFails)
+static int32_t
+ProcessDecodeFailures(const struct DecodeFailTestInput *pFailInputs, const int nNumFails)
{
- for(const struct FailInput *pF = pFailInputs; pF < pFailInputs + nNumFails; pF++) {
- QCBORDecodeContext DCtx;
- QCBORError uCBORError;
+ int nIndex;
+ QCBORDecodeContext DCtx;
+ QCBORError uCBORError;
+ QCBORItem Item;
- QCBORDecode_Init(&DCtx, pF->Input, QCBOR_DECODE_MODE_NORMAL);
+ for(nIndex = 0; nIndex < nNumFails; nIndex++) {
+ const struct DecodeFailTestInput *pF = &pFailInputs[nIndex];
+
+ QCBORDecode_Init(&DCtx, pF->Input, pF->DecoderMode);
#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS
- // Set up the decoding context including a memory pool so that
- // indefinite length items can be checked
+ /* Set up the decoding context including a memory pool so that
+ * indefinite length items can be checked.
+ */
UsefulBuf_MAKE_STACK_UB(Pool, 100);
uCBORError = QCBORDecode_SetMemPool(&DCtx, Pool, 0);
- if(uCBORError) {
- return -9;
+ if(uCBORError != QCBOR_SUCCESS) {
+ return -1;
}
#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
- const size_t nIndexx = (size_t)(pF - pFailInputs);
- if(nIndexx == 8) {
- uCBORError = 9;
+ if(nIndex == 8) {
+ uCBORError = 9; /* For setting break points */
}
-
- // Iterate until there is an error of some sort error
- QCBORItem Item;
+ /* Iterate until there is an error of some sort of error */
do {
- // Set to something none-zero, something other than QCBOR_TYPE_NONE
+ /* Set to something none-zero, something other than QCBOR_TYPE_NONE */
memset(&Item, 0x33, sizeof(Item));
uCBORError = QCBORDecode_GetNext(&DCtx, &Item);
} while(uCBORError == QCBOR_SUCCESS);
-
-
- // Must get the expected error or the this test fails
- // The data and label type must also be QCBOR_TYPE_NONE
+ /* Must get the expected error or the this test fails
+ * The data and label type must also be QCBOR_TYPE_NONE.
+ */
if(uCBORError != pF->nError ||
Item.uDataType != QCBOR_TYPE_NONE ||
Item.uLabelType != QCBOR_TYPE_NONE) {
- // return index of CBOR + 100
- const size_t nIndex = (size_t)(pF - pFailInputs);
- return (int32_t)(nIndex * 100 + uCBORError);
+ return (int32_t)(nIndex * 1000 + (int)uCBORError);
}
}
@@ -1850,396 +1851,588 @@
}
-static const struct FailInput Failures[] = {
- // Most of this is copied from not_well_formed.h. Here the error code
- // returned is also checked.
+static const struct DecodeFailTestInput Failures[] = {
+ /* Most of this is copied from not_well_formed.h. Here the error
+ * code returned is also checked.
+ */
#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS
- // Indefinite length strings must be closed off
- // An indefinite length byte string not closed off
- { {(uint8_t[]){0x5f, 0x41, 0x00}, 3}, QCBOR_ERR_HIT_END },
- // An indefinite length text string not closed off
- { {(uint8_t[]){0x7f, 0x61, 0x00}, 3}, QCBOR_ERR_HIT_END },
+ /* Indefinite length strings must be closed off */
+ { "An indefinite length byte string not closed off",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"0x5f\x41\x00", 3},
+ QCBOR_ERR_HIT_END
+ },
+ { "An indefinite length text string not closed off",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x7f\x61\x00", 3},
+ QCBOR_ERR_HIT_END
+ },
+ /* All the chunks in an indefinite length string must be of the
+ * type of indefinite length string
+ */
+ { "Indefinite length byte string with text string chunk",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x5f\x61\x00\xff", 4},
+ QCBOR_ERR_INDEFINITE_STRING_CHUNK
+ },
+ { "Indefinite length text string with a byte string chunk",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x7f\x41\x00\xff", 4},
+ QCBOR_ERR_INDEFINITE_STRING_CHUNK
+ },
+ { "Indefinite length byte string with a positive integer chunk",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x5f\x00\xff", 3},
+ QCBOR_ERR_INDEFINITE_STRING_CHUNK
+ },
+ { "Indefinite length byte string with an negative integer chunk",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x5f\x21\xff", 3},
+ QCBOR_ERR_INDEFINITE_STRING_CHUNK
+ },
+ { "Indefinite length byte string with an array chunk",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x5f\x80\xff", 3},
+ QCBOR_ERR_INDEFINITE_STRING_CHUNK
+ },
+ { "Indefinite length byte string with an map chunk",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x5f\xa0\xff", 3},
+ QCBOR_ERR_INDEFINITE_STRING_CHUNK
+ },
- // All the chunks in an indefinite length string must be of the type of
- // indefinite length string
- // indefinite length byte string with text string chunk
- { {(uint8_t[]){0x5f, 0x61, 0x00, 0xff}, 4}, QCBOR_ERR_INDEFINITE_STRING_CHUNK },
- // indefinite length text string with a byte string chunk
- { {(uint8_t[]){0x7f, 0x41, 0x00, 0xff}, 4}, QCBOR_ERR_INDEFINITE_STRING_CHUNK },
- // indefinite length byte string with an positive integer chunk
- { {(uint8_t[]){0x5f, 0x00, 0xff}, 3}, QCBOR_ERR_INDEFINITE_STRING_CHUNK },
- // indefinite length byte string with an negative integer chunk
- { {(uint8_t[]){0x5f, 0x21, 0xff}, 3}, QCBOR_ERR_INDEFINITE_STRING_CHUNK },
- // indefinite length byte string with an array chunk
- { {(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 },
+ { "Indefinite length byte string with tagged integer chunk",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x5f\xc0\x00\xff", 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 },
+ { "Indefinite length byte string with tagged integer chunk",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x5f\xc0\x00\xff", 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},
- // indefinite length text string with indefinite string inside
- { {(uint8_t[]){0x7f, 0x7f, 0x61, 0x00, 0xff, 0xff}, 6}, QCBOR_ERR_INDEFINITE_STRING_CHUNK},
+ { "Indefinite length byte string with an simple type chunk",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x5f\xe0\xff", 3},
+ QCBOR_ERR_INDEFINITE_STRING_CHUNK
+ },
+ { "???",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x5f\x5f\x41\x00\xff\xff", 6},
+ QCBOR_ERR_INDEFINITE_STRING_CHUNK
+ },
+ { "indefinite length text string with indefinite string inside",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x7f\x7f\x61\x00\xff\xff", 6},
+ QCBOR_ERR_INDEFINITE_STRING_CHUNK
+ },
#else /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
- { {(uint8_t[]){0x5f, 0x41, 0x00}, 3}, QCBOR_ERR_INDEF_LEN_STRINGS_DISABLED },
- // An indefinite length text string not closed off
- { {(uint8_t[]){0x7f, 0x61, 0x00}, 3}, QCBOR_ERR_INDEF_LEN_STRINGS_DISABLED },
-
-
- // All the chunks in an indefinite length string must be of the type of
- // indefinite length string
- // indefinite length byte string with text string chunk
- { {(uint8_t[]){0x5f, 0x61, 0x00, 0xff}, 4}, QCBOR_ERR_INDEF_LEN_STRINGS_DISABLED },
- // indefinite length text string with a byte string chunk
- { {(uint8_t[]){0x7f, 0x41, 0x00, 0xff}, 4}, QCBOR_ERR_INDEF_LEN_STRINGS_DISABLED },
- // indefinite length byte string with an positive integer chunk
- { {(uint8_t[]){0x5f, 0x00, 0xff}, 3}, QCBOR_ERR_INDEF_LEN_STRINGS_DISABLED },
- // indefinite length byte string with an negative integer chunk
- { {(uint8_t[]){0x5f, 0x21, 0xff}, 3}, QCBOR_ERR_INDEF_LEN_STRINGS_DISABLED },
- // indefinite length byte string with an array chunk
- { {(uint8_t[]){0x5f, 0x80, 0xff}, 3}, QCBOR_ERR_INDEF_LEN_STRINGS_DISABLED },
- // indefinite length byte string with an map chunk
- { {(uint8_t[]){0x5f, 0xa0, 0xff}, 3}, QCBOR_ERR_INDEF_LEN_STRINGS_DISABLED },
- // indefinite length byte string with tagged integer chunk
- { {(uint8_t[]){0x5f, 0xc0, 0x00, 0xff}, 4}, QCBOR_ERR_INDEF_LEN_STRINGS_DISABLED },
- // indefinite length byte string with an simple type chunk
- { {(uint8_t[]){0x5f, 0xe0, 0xff}, 3}, QCBOR_ERR_INDEF_LEN_STRINGS_DISABLED },
- { {(uint8_t[]){0x5f, 0x5f, 0x41, 0x00, 0xff, 0xff}, 6}, QCBOR_ERR_INDEF_LEN_STRINGS_DISABLED},
- // indefinite length text string with indefinite string inside
- { {(uint8_t[]){0x7f, 0x7f, 0x61, 0x00, 0xff, 0xff}, 6}, QCBOR_ERR_INDEF_LEN_STRINGS_DISABLED},
#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
-
- // Definte length maps and arrays must be closed by having the right number of items
- // A definte length array that is supposed to have 1 item, but has none
- { {(uint8_t[]){0x81}, 1}, QCBOR_ERR_NO_MORE_ITEMS },
- // A definte length array that is supposed to have 2 items, but has only 1
- { {(uint8_t[]){0x82, 0x00}, 2}, QCBOR_ERR_NO_MORE_ITEMS },
- // A definte length array that is supposed to have 511 items, but has only 1
- { {(uint8_t[]){0x9a, 0x01, 0xff, 0x00}, 4}, QCBOR_ERR_HIT_END },
- // A definte length map that is supposed to have 1 item, but has none
- { {(uint8_t[]){0xa1}, 1}, QCBOR_ERR_NO_MORE_ITEMS },
- // A definte length map that is supposed to have s item, but has only 1
- { {(uint8_t[]){0xa2, 0x01, 0x02}, 3}, QCBOR_ERR_NO_MORE_ITEMS },
-
+ /* Definte length maps and arrays must be closed by having the right number of items */
+ { "A definte length array that is supposed to have 1 item, but has none",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x81", 1},
+ QCBOR_ERR_NO_MORE_ITEMS
+ },
+ { "A definte length array that is supposed to have 2 items, but has only 1",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x82\x00", 2},
+ QCBOR_ERR_NO_MORE_ITEMS
+ },
+ { "A definte length array that is supposed to have 511 items, but has only 1",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x9a\x01\xff\x00", 4},
+ QCBOR_ERR_HIT_END
+ },
+ { "A definte length map that is supposed to have 1 item, but has none",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xa1", 1},
+ QCBOR_ERR_NO_MORE_ITEMS
+ },
+ { "A definte length map that is supposed to have s item, but has only 1",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xa2\x01\x02", 3},
+ QCBOR_ERR_NO_MORE_ITEMS
+ },
#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
- // Indefinte length maps and arrays must be ended by a break
- // Indefinite length array with zero items and no break
- { {(uint8_t[]){0x9f}, 1}, QCBOR_ERR_NO_MORE_ITEMS },
- // Indefinite length array with two items and no break
- { {(uint8_t[]){0x9f, 0x01, 0x02}, 3}, QCBOR_ERR_NO_MORE_ITEMS },
- // Indefinite length map with zero items and no break
- { {(uint8_t[]){0xbf}, 1}, QCBOR_ERR_NO_MORE_ITEMS },
- // Indefinite length map with two items and no break
- { {(uint8_t[]){0xbf, 0x01, 0x02, 0x01, 0x02}, 5}, QCBOR_ERR_NO_MORE_ITEMS },
+ /* Indefinte length maps and arrays must be ended by a break */
+ { "Indefinite length array with zero items and no break",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x9f", 1},
+ QCBOR_ERR_NO_MORE_ITEMS },
+ { "Indefinite length array with two items and no break",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x9\x01\x02", 3},
+ QCBOR_ERR_NO_MORE_ITEMS
+ },
+ { "Indefinite length map with zero items and no break",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xbf", 1},
+ QCBOR_ERR_NO_MORE_ITEMS
+ },
+ { "Indefinite length map with two items and no break",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xbf\x01\x02\x01\x02", 5},
+ QCBOR_ERR_NO_MORE_ITEMS
+ },
- // Nested maps and arrays must be closed off (some extra nested test vectors)
- // Unclosed indefinite array containing a closed definite length array
- { {(uint8_t[]){0x9f, 0x80, 0x00}, 3}, QCBOR_ERR_NO_MORE_ITEMS },
- // Definite length array containing an unclosed indefinite length array
- { {(uint8_t[]){0x81, 0x9f}, 2}, QCBOR_ERR_NO_MORE_ITEMS },
- // Unclosed indefinite map containing a closed definite length array
- { {(uint8_t[]){0xbf, 0x01, 0x80, 0x00, 0xa0}, 5}, QCBOR_ERR_NO_MORE_ITEMS },
- // Definite length map containing an unclosed indefinite length array
- { {(uint8_t[]){0xa1, 0x02, 0x9f}, 3}, QCBOR_ERR_NO_MORE_ITEMS },
- // Deeply nested definite length arrays with deepest one unclosed
- { {(uint8_t[]){0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81}, 9}, QCBOR_ERR_NO_MORE_ITEMS },
- // Deeply nested indefinite length arrays with deepest one unclosed
- { {(uint8_t[]){0x9f, 0x9f, 0x9f, 0x9f, 0x9f, 0xff, 0xff, 0xff, 0xff}, 9}, QCBOR_ERR_NO_MORE_ITEMS },
- // Mixed nesting with indefinite unclosed
- { {(uint8_t[]){0x9f, 0x81, 0x9f, 0x81, 0x9f, 0x9f, 0xff, 0xff, 0xff}, 9}, QCBOR_ERR_NO_MORE_ITEMS },
- // Mixed nesting with definite unclosed
- { {(uint8_t[]){0x9f, 0x82, 0x9f, 0x81, 0x9f, 0x9f, 0xff, 0xff, 0xff, 0xff}, 10}, QCBOR_ERR_BAD_BREAK },
- // Unclosed indefinite length map in definite length maps
- { {(uint8_t[]){0xa1, 0x01, 0xa2, 0x02, 0xbf, 0xff, 0x02, 0xbf}, 8},
- QCBOR_ERR_NO_MORE_ITEMS},
- // Unclosed definite length map in indefinite length maps
- { {(uint8_t[]){0xbf, 0x01, 0xbf, 0x02, 0xa1}, 5}, QCBOR_ERR_NO_MORE_ITEMS},
- // Unclosed indefinite length array in definite length maps
- { {(uint8_t[]){0xa1, 0x01, 0xa2, 0x02, 0x9f, 0xff, 0x02, 0x9f}, 8},
- QCBOR_ERR_NO_MORE_ITEMS},
- // Unclosed definite length array in indefinite length maps
- { {(uint8_t[]){0xbf, 0x01, 0xbf, 0x02, 0x81}, 5}, QCBOR_ERR_NO_MORE_ITEMS},
- // Unclosed indefinite length map in definite length arrays
- { {(uint8_t[]){0x81, 0x82, 0xbf, 0xff, 0xbf}, 5}, QCBOR_ERR_NO_MORE_ITEMS},
- // Unclosed definite length map in indefinite length arrays
- { {(uint8_t[]){0x9f, 0x9f, 0xa1}, 3}, QCBOR_ERR_NO_MORE_ITEMS},
+ /* Nested maps and arrays must be closed off (some extra nested test vectors) */
+ { "Unclosed indefinite array containing a closed definite length array",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x9f\x80\x00", 3},
+ QCBOR_ERR_NO_MORE_ITEMS
+ },
+
+ { "Definite length array containing an unclosed indefinite length array",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x81\x9f", 2},
+ QCBOR_ERR_NO_MORE_ITEMS
+ },
+ { "Unclosed indefinite map containing a closed definite length array",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xbf\x01\x80\x00\xa0", 5},
+ QCBOR_ERR_NO_MORE_ITEMS
+ },
+ { "Definite length map containing an unclosed indefinite length array",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xa1\x02\x9f", 3},
+ QCBOR_ERR_NO_MORE_ITEMS
+ },
+ { "Deeply nested definite length arrays with deepest one unclosed",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x81\x81\x81\x81\x81\x81\x81\x81\x81", 9},
+ QCBOR_ERR_NO_MORE_ITEMS
+ },
+ { "Deeply nested indefinite length arrays with deepest one unclosed",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x9f\x9f\x9f\x9f\x9f\xff\xff\xff\xff", 9},
+ QCBOR_ERR_NO_MORE_ITEMS
+ },
+ { "Mixed nesting with indefinite unclosed",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x9f\x81\x9f\x81\x9f\x9f\xff\xff\xff", 9},
+ QCBOR_ERR_NO_MORE_ITEMS },
+ { "Mixed nesting with definite unclosed",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x9f\x82\x9f\x81\x9f\x9f\xff\xff\xff\xff", 10},
+ QCBOR_ERR_BAD_BREAK
+ },
+ { "Unclosed indefinite length map in definite length maps",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xa1\x01\xa2\x02\xbf\xff\x02\xbf", 8},
+ QCBOR_ERR_NO_MORE_ITEMS
+ },
+ { "Unclosed definite length map in indefinite length maps",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xbf\x01\xbf\x02\xa1", 5},
+ QCBOR_ERR_NO_MORE_ITEMS
+ },
+ { "Unclosed indefinite length array in definite length maps",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xa1\x01\xa2\x02\x9f\xff\x02\x9f", 8},
+ QCBOR_ERR_NO_MORE_ITEMS
+ },
+ { "Unclosed definite length array in indefinite length maps",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xbf\x01\xbf\x02\x81", 5},
+ QCBOR_ERR_NO_MORE_ITEMS
+ },
+ { "Unclosed indefinite length map in definite length arrays",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x81\x82\xbf\xff\xbf", 5},
+ QCBOR_ERR_NO_MORE_ITEMS
+ },
+ { "Unclosed definite length map in indefinite length arrays",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x9f\x9f\xa1", 3},
+ QCBOR_ERR_NO_MORE_ITEMS
+ },
+
#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
- // The "argument" for the data item is incomplete
- // Positive integer missing 1 byte argument
- { {(uint8_t[]){0x18}, 1}, QCBOR_ERR_HIT_END },
- // Positive integer missing 2 byte argument
- { {(uint8_t[]){0x19}, 1}, QCBOR_ERR_HIT_END },
- // Positive integer missing 4 byte argument
- { {(uint8_t[]){0x1a}, 1}, QCBOR_ERR_HIT_END },
- // Positive integer missing 8 byte argument
- { {(uint8_t[]){0x1b}, 1}, QCBOR_ERR_HIT_END },
- // Positive integer missing 1 byte of 2 byte argument
- { {(uint8_t[]){0x19, 0x01}, 2}, QCBOR_ERR_HIT_END },
- // Positive integer missing 2 bytes of 4 byte argument
- { {(uint8_t[]){0x1a, 0x01, 0x02}, 3}, QCBOR_ERR_HIT_END },
- // Positive integer missing 1 bytes of 7 byte argument
- { {(uint8_t[]){0x1b, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, 8}, QCBOR_ERR_HIT_END },
- // Negative integer missing 1 byte argument
- { {(uint8_t[]){0x38}, 1}, QCBOR_ERR_HIT_END },
- // Binary string missing 1 byte argument
- { {(uint8_t[]){0x58}, 1}, QCBOR_ERR_HIT_END },
- // Text string missing 1 byte argument
- { {(uint8_t[]){0x78}, 1}, QCBOR_ERR_HIT_END },
- // Array missing 1 byte argument
- { {(uint8_t[]){0x98}, 1}, QCBOR_ERR_HIT_END },
- // Map missing 1 byte argument
- { {(uint8_t[]){0xb8}, 1}, QCBOR_ERR_HIT_END },
- // Tag missing 1 byte argument
- { {(uint8_t[]){0xd8}, 1}, QCBOR_ERR_HIT_END },
- // Simple missing 1 byte argument
- { {(uint8_t[]){0xf8}, 1}, QCBOR_ERR_HIT_END },
- // half-precision with 1 byte argument
- { {(uint8_t[]){0xf9, 0x00}, 2}, QCBOR_ERR_HIT_END },
- // single-precision with 2 byte argument
- { {(uint8_t[]){0xfa, 0x00, 0x00}, 3}, QCBOR_ERR_HIT_END },
- // double-precision with 3 byte argument
- { {(uint8_t[]){0xfb, 0x00, 0x00, 0x00}, 4}, QCBOR_ERR_HIT_END },
+ /* The "argument" for the data item is incomplete */
+ { "Positive integer missing 1 byte argument",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x18", 1},
+ QCBOR_ERR_HIT_END
+ },
+ { "Positive integer missing 2 byte argument",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x19", 1},
+ QCBOR_ERR_HIT_END
+ },
+ { "Positive integer missing 4 byte argument",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x1a", 1},
+ QCBOR_ERR_HIT_END
+ },
+ { "Positive integer missing 8 byte argument",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x1b", 1},
+ QCBOR_ERR_HIT_END
+ },
+ { "Positive integer missing 1 byte of 2 byte argument",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x19\x01", 2},
+ QCBOR_ERR_HIT_END
+ },
+ { "Positive integer missing 2 bytes of 4 byte argument",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x1a\x01\x02", 3},
+ QCBOR_ERR_HIT_END
+ },
+ { "Positive integer missing 1 bytes of 7 byte argument",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x1b\x01\x02\x03\x04\x05\x06\x07", 8},
+ QCBOR_ERR_HIT_END
+ },
+ { "Negative integer missing 1 byte argument",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x38", 1},
+ QCBOR_ERR_HIT_END
+ },
+ { "Binary string missing 1 byte argument",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x58", 1},
+ QCBOR_ERR_HIT_END
+ },
+ { "Text string missing 1 byte argument",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x78", 1},
+ QCBOR_ERR_HIT_END
+ },
+ { "Array missing 1 byte argument",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x98", 1},
+ QCBOR_ERR_HIT_END
+ },
+ { "Map missing 1 byte argument",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xb8", 1},
+ QCBOR_ERR_HIT_END
+ },
+ { "Tag missing 1 byte argument",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xd8", 1},
+ QCBOR_ERR_HIT_END
+ },
+ { "Simple missing 1 byte argument",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8", 1},
+ QCBOR_ERR_HIT_END
+ },
+ { "half-precision with 1 byte argument",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf9\x00", 2},
+ QCBOR_ERR_HIT_END
+ },
+ { "single-precision with 2 byte argument",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\0xfa\x00\x00", 3},
+ QCBOR_ERR_HIT_END
+ },
+ { "double-precision with 3 byte argument",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xfb\x00\x00\x00", 4},
+ QCBOR_ERR_HIT_END
+ },
#ifndef QCBOR_DISABLE_TAGS
- // Tag with no content
- { {(uint8_t[]){0xc0}, 1}, QCBOR_ERR_HIT_END },
+ { "Tag with no content",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xc0", 1},
+ QCBOR_ERR_HIT_END
+ },
#else /* QCBOR_DISABLE_TAGS */
- { {(uint8_t[]){0xc0}, 1}, QCBOR_ERR_TAGS_DISABLED },
+ { "Tag with no content",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xc0", 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
- { {(uint8_t[]){0x81, 0xff}, 2}, QCBOR_ERR_BAD_BREAK },
- // Array of length 2 with 2nd member replaced by a break
- { {(uint8_t[]){0x82, 0x00, 0xff}, 3}, QCBOR_ERR_BAD_BREAK },
- // Map of length 1 with sole member label replaced by a break
- { {(uint8_t[]){0xa1, 0xff}, 2}, QCBOR_ERR_BAD_BREAK },
- // Map of length 1 with sole member label replaced by break
- // Alternate representation that some decoders handle differently
- { {(uint8_t[]){0xa1, 0xff, 0x00}, 3}, QCBOR_ERR_BAD_BREAK },
- // Array of length 1 with 2nd member value replaced by a break
- { {(uint8_t[]){0xa1, 0x00, 0xff}, 3}, QCBOR_ERR_BAD_BREAK },
- // Map of length 2 with 2nd member replaced by a break
- { {(uint8_t[]){0xa2, 0x00, 0x00, 0xff}, 4}, QCBOR_ERR_BAD_BREAK },
+ /* Breaks must not occur in definite length arrays and maps */
+ { "Array of length 1 with sole member replaced by a break",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x81\xff", 2},
+ QCBOR_ERR_BAD_BREAK
+ },
+ { "Array of length 2 with 2nd member replaced by a break",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x82\x00\xff", 3},
+ QCBOR_ERR_BAD_BREAK
+ },
+ { "Map of length 1 with sole member label replaced by a break",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xa1\xff", 2},
+ QCBOR_ERR_BAD_BREAK
+ },
+ /* Map of length 1 with sole member label replaced by break */
+ { "Alternate representation that some decoders handle differently",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xa1\xff\x00", 3},
+ QCBOR_ERR_BAD_BREAK
+ },
+ { "Array of length 1 with 2nd member value replaced by a break",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xa1\x00\xff", 3},
+ QCBOR_ERR_BAD_BREAK
+ },
+ { "Map of length 2 with 2nd member replaced by a break",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xa2\x00\x00\xff", 4},
+ QCBOR_ERR_BAD_BREAK
+ },
- // Breaks must not occur on their own out of an indefinite length data item
- // A bare break is not well formed
- { {(uint8_t[]){0xff}, 1}, QCBOR_ERR_BAD_BREAK },
- // A bare break after a zero length definite length array
- { {(uint8_t[]){0x80, 0xff}, 2}, QCBOR_ERR_BAD_BREAK },
+ /* Breaks must not occur on their own out of an indefinite length data item */
+ { "A bare break is not well formed",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xff", 1},
+ QCBOR_ERR_BAD_BREAK
+ },
+ { "A bare break after a zero length definite length array",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x80\xff", 2},
+ QCBOR_ERR_BAD_BREAK
+ },
#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
- // A bare break after a zero length indefinite length map
- { {(uint8_t[]){0x9f, 0xff, 0xff}, 3}, QCBOR_ERR_BAD_BREAK },
- // A break inside a definite length array inside an indefenite length array
- { {(uint8_t[]){0x9f, 0x81, 0xff}, 3}, QCBOR_ERR_BAD_BREAK },
- // Complicated mixed nesting with break outside indefinite length array
- { {(uint8_t[]){0x9f, 0x82, 0x9f, 0x81, 0x9f, 0x9f, 0xff, 0xff, 0xff, 0xff}, 10}, QCBOR_ERR_BAD_BREAK },
+ { "A bare break after a zero length indefinite length map",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x9f\xff\xff", 3},
+ QCBOR_ERR_BAD_BREAK
+ },
+ { "A break inside a definite length array inside an indefenite length array",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x9f\x81\xff", 3},
+ QCBOR_ERR_BAD_BREAK
+ },
+ { "Complicated mixed nesting with break outside indefinite length array",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\x9f\x82\x9f\x81\x9f\x9f\xff\xff\xff\xff", 10},
+ QCBOR_ERR_BAD_BREAK },
+#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
+
+ /* Forbidden two byte encodings of simple types */
+ { "Must use 0xe0 instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x00", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xe1 instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x01", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xe2 instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x02", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ }, { "Should use 0xe3 instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x03", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xe4 instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x04", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xe5 instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x05", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xe6 instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x06", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xe7 instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x07", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xe8 instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x08", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xe9 instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x09", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xea instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x0a", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xeb instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x0b", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xec instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x0c", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xed instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x0d", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xee instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x0e", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xef instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x0f", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xf0 instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x10", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xf1 instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x11", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xf2 instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x12", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xf3 instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x13", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xf4 instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x14", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xf5 instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x15", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xf6 instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x16", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xef7 instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x17", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Should use 0xef8 instead",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x18", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+ { "Reserved",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xf8\x18", 2},
+ QCBOR_ERR_BAD_TYPE_7
+ },
+
+ /* Maps must have an even number of data items (key & value) */
+ { "Map with 1 item when it should have 2",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xa1\x00", 2},
+ QCBOR_ERR_HIT_END
+ },
+ { "Map with 3 item when it should have 4",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xa2\x00\x00\x00", 2},
+ QCBOR_ERR_HIT_END
+ },
+#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
+ { "Map with 1 item when it should have 2",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xbf\x00\xff", 3},
+ QCBOR_ERR_BAD_BREAK
+ },
+ { "Map with 3 item when it should have 4",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xbf\x00\x00\x00\xff", 5},
+ QCBOR_ERR_BAD_BREAK
+ },
#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
- // Forbidden two byte encodings of simple types
- // Must use 0xe0 instead
- { {(uint8_t[]){0xf8, 0x00}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Should use 0xe1 instead
- { {(uint8_t[]){0xf8, 0x01}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Should use 0xe2 instead
- { {(uint8_t[]){0xf8, 0x02}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Should use 0xe3 instead
- { {(uint8_t[]){0xf8, 0x03}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Should use 0xe4 instead
- { {(uint8_t[]){0xf8, 0x04}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Should use 0xe5 instead
- { {(uint8_t[]){0xf8, 0x05}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Should use 0xe6 instead
- { {(uint8_t[]){0xf8, 0x06}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Should use 0xe7 instead
- { {(uint8_t[]){0xf8, 0x07}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Should use 0xe8 instead
- { {(uint8_t[]){0xf8, 0x08}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Should use 0xe9 instead
- { {(uint8_t[]){0xf8, 0x09}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Should use 0xea instead
- { {(uint8_t[]){0xf8, 0x0a}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Should use 0xeb instead
- { {(uint8_t[]){0xf8, 0x0b}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Should use 0xec instead
- { {(uint8_t[]){0xf8, 0x0c}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Should use 0xed instead
- { {(uint8_t[]){0xf8, 0x0d}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Should use 0xee instead
- { {(uint8_t[]){0xf8, 0x0e}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Should use 0xef instead
- { {(uint8_t[]){0xf8, 0x0f}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Should use 0xf0 instead
- { {(uint8_t[]){0xf8, 0x10}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Should use 0xf1 instead
- { {(uint8_t[]){0xf8, 0x11}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Should use 0xf2 instead
- { {(uint8_t[]){0xf8, 0x12}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Must use 0xf3 instead
- { {(uint8_t[]){0xf8, 0x13}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Must use 0xf4 instead
- { {(uint8_t[]){0xf8, 0x14}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Must use 0xf5 instead
- { {(uint8_t[]){0xf8, 0x15}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Must use 0xf6 instead
- { {(uint8_t[]){0xf8, 0x16}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Must use 0xf7 instead
- { {(uint8_t[]){0xf8, 0x17}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Must use 0xf8 instead
- { {(uint8_t[]){0xf8, 0x18}, 2}, QCBOR_ERR_BAD_TYPE_7 },
- // Reserved
- { {(uint8_t[]){0xf8, 0x1f}, 2}, QCBOR_ERR_BAD_TYPE_7 },
-
- // Integers with additional info indefinite length
- // Positive integer with additional info indefinite length
- { {(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 },
+ /* In addition to not-well-formed, some invalid CBOR */
+ { "Text-based date, with an integer",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xc0\x00", 2},
+ QCBOR_ERR_BAD_OPT_TAG
+ },
+ { "Epoch date, with an byte string",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xc1\x41\x33", 3},
+ QCBOR_ERR_BAD_OPT_TAG
+ },
+ { "tagged as both epoch and string dates",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xc1\xc0\x00", 3},
+ QCBOR_ERR_BAD_OPT_TAG
+ },
+ { "big num tagged an int, not a byte string",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xc2\x00", 2},
+ QCBOR_ERR_BAD_OPT_TAG
+ },
#else /* QCBOR_DISABLE_TAGS */
- { {(uint8_t[]){0xdf, 0x00}, 2}, QCBOR_ERR_TAGS_DISABLED },
- { {(uint8_t[]){0xdf}, 1}, QCBOR_ERR_TAGS_DISABLED },
+ /* In addition to not-well-formed, some invalid CBOR */
+ { "Text-based date, with an integer",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xc0\x00", 2},
+ QCBOR_ERR_TAGS_DISABLED
+ },
+ { "Epoch date, with an byte string",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xc1\x41\x33", 3},
+ QCBOR_ERR_TAGS_DISABLED
+ },
+ { "tagged as both epoch and string dates",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xc1\xc0\x00", 3},
+ QCBOR_ERR_TAGS_DISABLED
+ },
+ { "big num tagged an int, not a byte string",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xc2\x00", 2},
+ 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
- { {(uint8_t[]){0x41}, 1}, QCBOR_ERR_HIT_END },
- // A text string is of length 1 without the 1 byte
- { {(uint8_t[]){0x61}, 1}, QCBOR_ERR_HIT_END },
-
-#if SIZE_MAX > 2147483647
- // Byte string should have 2^32-15 bytes, but has one
- { {(uint8_t[]){0x5a, 0xff, 0xff, 0xff, 0xf0, 0x00}, 6}, QCBOR_ERR_HIT_END },
- // Byte string should have 2^32-15 bytes, but has one
- { {(uint8_t[]){0x7a, 0xff, 0xff, 0xff, 0xf0, 0x00}, 6}, QCBOR_ERR_HIT_END },
- // Byte string should have 2^64 bytes, but has 3
- { {(uint8_t[]){0x5b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x01, 0x02, 0x03}, 6}, QCBOR_ERR_HIT_END },
- // 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
- // 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
- { {(uint8_t[]){0x7a, 0x00, 0x00, 0xff, 0xf0, 0x00}, 6}, QCBOR_ERR_HIT_END },
- // Byte string should have 2^16 bytes, but has 3
- { {(uint8_t[]){0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x01, 0x02, 0x03}, 6}, QCBOR_ERR_HIT_END },
- // Text string should have 2^64 bytes, but has 3
- { {(uint8_t[]){0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x01, 0x02, 0x03}, 6}, QCBOR_ERR_HIT_END },
-#endif
-
- // Use of unassigned additional information values
- // Major type positive integer with reserved value 28
- { {(uint8_t[]){0x1c}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type positive integer with reserved value 29
- { {(uint8_t[]){0x1d}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type positive integer with reserved value 30
- { {(uint8_t[]){0x1e}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type negative integer with reserved value 28
- { {(uint8_t[]){0x3c}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type negative integer with reserved value 29
- { {(uint8_t[]){0x3d}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type negative integer with reserved value 30
- { {(uint8_t[]){0x3e}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type byte string with reserved value 28 length
- { {(uint8_t[]){0x5c}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type byte string with reserved value 29 length
- { {(uint8_t[]){0x5d}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type byte string with reserved value 30 length
- { {(uint8_t[]){0x5e}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type text string with reserved value 28 length
- { {(uint8_t[]){0x7c}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type text string with reserved value 29 length
- { {(uint8_t[]){0x7d}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type text string with reserved value 30 length
- { {(uint8_t[]){0x7e}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type array with reserved value 28 length
- { {(uint8_t[]){0x9c}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type array with reserved value 29 length
- { {(uint8_t[]){0x9d}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type array with reserved value 30 length
- { {(uint8_t[]){0x9e}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type map with reserved value 28 length
- { {(uint8_t[]){0xbc}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type map with reserved value 29 length
- { {(uint8_t[]){0xbd}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type map with reserved value 30 length
- { {(uint8_t[]){0xbe}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type tag with reserved value 28 length
- { {(uint8_t[]){0xdc}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type tag with reserved value 29 length
- { {(uint8_t[]){0xdd}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type tag with reserved value 30 length
- { {(uint8_t[]){0xde}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type simple with reserved value 28 length
- { {(uint8_t[]){0xfc}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type simple with reserved value 29 length
- { {(uint8_t[]){0xfd}, 1}, QCBOR_ERR_UNSUPPORTED },
- // Major type simple with reserved value 30 length
- { {(uint8_t[]){0xfe}, 1}, QCBOR_ERR_UNSUPPORTED },
-
-
- // Maps must have an even number of data items (key & value)
- // Map with 1 item when it should have 2
- { {(uint8_t[]){0xa1, 0x00}, 2}, QCBOR_ERR_HIT_END },
- // Map with 3 item when it should have 4
- { {(uint8_t[]){0xa2, 0x00, 0x00, 0x00}, 2}, QCBOR_ERR_HIT_END },
-#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
- // Map with 1 item when it should have 2
- { {(uint8_t[]){0xbf, 0x00, 0xff}, 3}, QCBOR_ERR_BAD_BREAK },
- // Map with 3 item when it should have 4
- { {(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 },
- // Epoch date, with an byte string
- { {(uint8_t[]){0xc1, 0x41, 0x33}, 3}, QCBOR_ERR_BAD_OPT_TAG },
- // tagged as both epoch and string dates
- { {(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(void)
+
+
+int32_t
+DecodeFailureTests(void)
{
int32_t nResult;
- nResult = ProcessFailures(Failures,C_ARRAY_COUNT(Failures,struct FailInput));
+ nResult = ProcessDecodeFailures(Failures ,C_ARRAY_COUNT(Failures, struct DecodeFailTestInput));
if(nResult) {
return nResult;
}
@@ -5247,52 +5440,89 @@
}
-static const struct FailInput ExponentAndMantissaFailures[] = {
- // Exponent > INT64_MAX
- { {(uint8_t[]){0xC4, 0x82, 0x1B, 0x7f, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0x1B, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF,}, 20}, QCBOR_ERR_BAD_EXP_AND_MANTISSA},
- // Mantissa > INT64_MAX
- { {(uint8_t[]){0xC4, 0x82, 0x1B, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xC3, 0x4A, 0x01, 0x02, 0x03, 0x04, 0x05,
- 0x06, 0x07, 0x08, 0x09, 0x10}, 23}, QCBOR_ERR_BAD_EXP_AND_MANTISSA},
- // End of input
- { {(uint8_t[]){0xC4, 0x82}, 2}, QCBOR_ERR_NO_MORE_ITEMS},
- // End of input
- { {(uint8_t[]){0xC4, 0x82, 0x01}, 3}, QCBOR_ERR_NO_MORE_ITEMS},
- // bad content for big num
- { {(uint8_t[]){0xC4, 0x82, 0x01, 0xc3, 0x01}, 5}, QCBOR_ERR_BAD_OPT_TAG},
- // bad content for big num
- { {(uint8_t[]){0xC4, 0x82, 0xc2, 0x01, 0x1f}, 5}, QCBOR_ERR_BAD_INT},
- // Bad integer for exponent
- { {(uint8_t[]){0xC4, 0x82, 0x01, 0x1f}, 4}, QCBOR_ERR_BAD_INT},
- // Bad integer for mantissa
- { {(uint8_t[]){0xC4, 0x82, 0x1f, 0x01}, 4}, QCBOR_ERR_BAD_INT},
- // 3 items in array
- { {(uint8_t[]){0xC4, 0x83, 0x03, 0x01, 02}, 5}, QCBOR_ERR_BAD_EXP_AND_MANTISSA},
+static const struct DecodeFailTestInput ExponentAndMantissaFailures[] = {
+ { "Exponent > INT64_MAX",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xC4\x82\x1B\x7f\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x1B\x80\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 20},
+ QCBOR_ERR_BAD_EXP_AND_MANTISSA
+ },
+ { "Mantissa > INT64_MAX",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xC4\x82\x1B\x80\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xC3\x4A\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10", 23},
+ QCBOR_ERR_BAD_EXP_AND_MANTISSA
+ },
+ {
+ "End of input",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xC4\x82", 2},
+ QCBOR_ERR_NO_MORE_ITEMS
+ },
+ {"bad content for big num",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xC4\x82\x01\xc3\x01", 5},
+ QCBOR_ERR_BAD_OPT_TAG
+ },
+ {"bad content for big num",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xC4\x82\xc2\x01\x1f", 5},
+ QCBOR_ERR_BAD_INT
+ },
+ {"Bad integer for exponent",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xC4\x82\x01\x1f", 4},
+ QCBOR_ERR_BAD_INT
+ },
+ {"Bad integer for mantissa",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xC4\x82\x1f\x01", 4},
+ QCBOR_ERR_BAD_INT
+ },
+ {"3 items in array",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xC4\x83\x03\x01\x02", 5},
+ QCBOR_ERR_BAD_EXP_AND_MANTISSA},
#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
- // unterminated indefinite length array
- { {(uint8_t[]){0xC4, 0x9f, 0x03, 0x01, 0x02}, 5}, QCBOR_ERR_BAD_EXP_AND_MANTISSA},
+ {"unterminated indefinite length array",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xC4\x9f\x03\x01\x02", 5},
+ QCBOR_ERR_BAD_EXP_AND_MANTISSA
+ },
#else /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
- // unterminated indefinite length array
- { {(uint8_t[]){0xC4, 0x9f, 0x03, 0x01, 0x02}, 5}, QCBOR_ERR_INDEF_LEN_ARRAYS_DISABLED},
+ {"unterminated indefinite length array",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xC4\x9f\x03\x01\x02", 5},
+ QCBOR_ERR_INDEF_LEN_ARRAYS_DISABLED
+ },
#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
- // Empty array
- { {(uint8_t[]){0xC4, 0x80}, 2}, QCBOR_ERR_NO_MORE_ITEMS},
- // Second is not an integer
- { {(uint8_t[]){0xC4, 0x82, 0x03, 0x40}, 4}, QCBOR_ERR_BAD_EXP_AND_MANTISSA},
- // First is not an integer
- { {(uint8_t[]){0xC4, 0x82, 0x40}, 3}, QCBOR_ERR_BAD_EXP_AND_MANTISSA},
- // Not an array
- { {(uint8_t[]){0xC4, 0xa2}, 2}, QCBOR_ERR_BAD_EXP_AND_MANTISSA}
+ {"Empty array",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xC4\x80", 2},
+ QCBOR_ERR_NO_MORE_ITEMS
+ },
+ {"Second is not an integer",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xC4\x82\x03\x40", 4},
+ QCBOR_ERR_BAD_EXP_AND_MANTISSA
+ },
+ {"First is not an integer",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xC4\x82\x40", 3},
+ QCBOR_ERR_BAD_EXP_AND_MANTISSA
+ },
+ {"Not an array",
+ QCBOR_DECODE_MODE_NORMAL,
+ {"\xC4\xA2", 2},
+ QCBOR_ERR_BAD_EXP_AND_MANTISSA
+ }
};
-int32_t ExponentAndMantissaDecodeFailTests(void)
+int32_t
+ExponentAndMantissaDecodeFailTests(void)
{
- return ProcessFailures(ExponentAndMantissaFailures,
- C_ARRAY_COUNT(ExponentAndMantissaFailures,
- struct FailInput));
+ return ProcessDecodeFailures(ExponentAndMantissaFailures,
+ C_ARRAY_COUNT(ExponentAndMantissaFailures,
+ struct DecodeFailTestInput));
}
#endif /* QCBOR_DISABLE_EXP_AND_MANTISSA */
@@ -7785,23 +8015,17 @@
#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')
- )
-]
+ * An array of one that contains a byte string that is an indefinite
+ * length string that CBOR wraps an array of three numbers [42, 43,
+ * 44]. The byte string is an implicit tag 24.
+ *
+ * [
+ * (_ h'83', h'18', h'2A182B', h'182C')
+ * ]
*/
static const uint8_t pWrappedByIndefiniteLength[] = {
0x81,
- 0xd8, 0x18,
0x5f,
0x41, 0x83,
0x41, 0x18,
@@ -8399,7 +8623,6 @@
// 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);
@@ -8408,7 +8631,6 @@
QCBORDecode_EnterArray(&DCtx, NULL);
QCBORDecode_EnterBstrWrapped(&DCtx, 2, NULL);
-#ifndef QCBOR_DISABLE_TAGS
if(QCBORDecode_GetError(&DCtx) != QCBOR_ERR_INPUT_TOO_LARGE) {
/* TODO: This is what happens when trying to enter
* indefinite-length byte string wrapped CBOR. Tolerate for
@@ -8429,12 +8651,6 @@
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 */