add support for undef decoding
diff --git a/inc/qcbor/qcbor_spiffy_decode.h b/inc/qcbor/qcbor_spiffy_decode.h
index f17ac15..3e69221 100644
--- a/inc/qcbor/qcbor_spiffy_decode.h
+++ b/inc/qcbor/qcbor_spiffy_decode.h
@@ -952,9 +952,9 @@
@param[in] pCtx The decode context.
- The CBOR item to decode must be either the CBOR simple value (CBOR
- type 7) @c null. The reason to call this is to see if an error is returned
- or not indicating whether the item is a CBOR null. If it is not then the
+ The CBOR item to decode must be the CBOR simple value (CBOR type 7)
+ @c null. The reason to call this is to see if an error is returned or
+ not indicating whether the item is a CBOR null. If it is not then the
@ref QCBOR_ERR_UNEXPECTED_TYPE error is set.
*/
static void QCBORDecode_GetNull(QCBORDecodeContext *pCtx);
@@ -966,6 +966,24 @@
const char *szLabel);
+/**
+ @brief Decode the next item as a CBOR "undefined" item.
+
+ @param[in] pCtx The decode context.
+
+ The CBOR item to decode must be the CBOR simple value (CBOR type 7)
+ @c undefined. The reason to call this is to see if an error is
+ returned or not indicating whether the item is a CBOR undefed
+ item. If it is not then the @ref QCBOR_ERR_UNEXPECTED_TYPE error is
+ set.
+*/
+static void QCBORDecode_GetUndefined(QCBORDecodeContext *pCtx);
+
+static void QCBORDecode_GetUndefinedInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel);
+
+static void QCBORDecode_GetUndefinedInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel);
/**
@@ -2057,8 +2075,7 @@
QCBORItem item;
QCBORDecode_VGetNext(pMe, &item);
- if(pMe->uLastError == QCBOR_SUCCESS &&
- item.uDataType != QCBOR_TYPE_NULL) {
+ if(pMe->uLastError == QCBOR_SUCCESS && item.uDataType != QCBOR_TYPE_NULL) {
pMe->uLastError = QCBOR_ERR_UNEXPECTED_TYPE;
}
}
@@ -2080,6 +2097,34 @@
}
static inline void
+QCBORDecode_GetUndefined(QCBORDecodeContext *pMe)
+{
+ QCBORItem item;
+
+ QCBORDecode_VGetNext(pMe, &item);
+ if(pMe->uLastError == QCBOR_SUCCESS && item.uDataType != QCBOR_TYPE_UNDEF) {
+ pMe->uLastError = QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+}
+
+static inline void
+QCBORDecode_GetUndefinedInMapN(QCBORDecodeContext *pMe,
+ int64_t nLabel)
+{
+ QCBORItem Item;
+ QCBORDecode_GetItemInMapN(pMe, nLabel, QCBOR_TYPE_UNDEF, &Item);
+}
+
+static inline void
+QCBORDecode_GetUndefinedInMapSZ(QCBORDecodeContext *pMe,
+ const char * szLabel)
+{
+ QCBORItem Item;
+ QCBORDecode_GetItemInMapSZ(pMe, szLabel, QCBOR_TYPE_UNDEF, &Item);
+}
+
+
+static inline void
QCBORDecode_GetDateString(QCBORDecodeContext *pMe,
uint8_t uTagRequirement,
UsefulBufC *pValue)
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 476ab13..236f59c 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -7801,6 +7801,10 @@
0xa1, 0x08, 0xf6
};
+static const uint8_t spUndefinedInMap[] =
+{
+ 0xa1, 0x08, 0xf7
+};
int32_t BoolTest(void)
@@ -7808,8 +7812,9 @@
QCBORDecodeContext DCtx;
bool b;
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBooleansInMap), 0);
-
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBooleansInMap),
+ 0);
QCBORDecode_EnterMap(&DCtx, NULL);
QCBORDecode_GetBool(&DCtx, &b);
if(QCBORDecode_GetAndResetError(&DCtx) || !b) {
@@ -7832,16 +7837,18 @@
return 4;
}
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBooleansInMapWrongType), 0);
-
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBooleansInMapWrongType),
+ 0);
QCBORDecode_EnterMap(&DCtx, NULL);
QCBORDecode_GetBool(&DCtx, &b);
if(QCBORDecode_GetAndResetError(&DCtx) != QCBOR_ERR_UNEXPECTED_TYPE) {
return 5;
}
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBooleansInMapNWF), 0);
-
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBooleansInMapNWF),
+ 0);
QCBORDecode_EnterMap(&DCtx, NULL);
QCBORDecode_GetBool(&DCtx, &b);
if(QCBORDecode_GetAndResetError(&DCtx) != QCBOR_ERR_HIT_END) {
@@ -7849,33 +7856,95 @@
}
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spNullInMap), 0);
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spNullInMap),
+ 0);
QCBORDecode_EnterMap(&DCtx, NULL);
QCBORDecode_GetNull(&DCtx);
if(QCBORDecode_GetAndResetError(&DCtx)) {
return 7;
}
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBooleansInMap), 0);
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBooleansInMap),
+ 0);
QCBORDecode_EnterMap(&DCtx, NULL);
QCBORDecode_GetNull(&DCtx);
if(QCBORDecode_GetAndResetError(&DCtx) != QCBOR_ERR_UNEXPECTED_TYPE) {
return 8;
}
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spNullInMap), 0);
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spNullInMap),
+ 0);
QCBORDecode_EnterMap(&DCtx, NULL);
QCBORDecode_GetNullInMapN(&DCtx, 8);
if(QCBORDecode_GetAndResetError(&DCtx)) {
return 9;
}
- QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBooleansInMap), 0);
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBooleansInMap),
+ 0);
QCBORDecode_EnterMap(&DCtx, NULL);
QCBORDecode_GetNullInMapN(&DCtx, 8);
if(QCBORDecode_GetAndResetError(&DCtx) != QCBOR_ERR_UNEXPECTED_TYPE) {
return 10;
}
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBooleansInMapNWF),
+ 0);
+ QCBORDecode_EnterMap(&DCtx, NULL);
+ QCBORDecode_GetUndefined(&DCtx);
+ if(QCBORDecode_GetAndResetError(&DCtx) != QCBOR_ERR_HIT_END) {
+ return 11;
+ }
+
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spUndefinedInMap),
+ 0);
+ QCBORDecode_EnterMap(&DCtx, NULL);
+ QCBORDecode_GetUndefined(&DCtx);
+ if(QCBORDecode_GetAndResetError(&DCtx)) {
+ return 12;
+ }
+
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBooleansInMap),
+ 0);
+ QCBORDecode_EnterMap(&DCtx, NULL);
+ QCBORDecode_GetUndefined(&DCtx);
+ if(QCBORDecode_GetAndResetError(&DCtx) != QCBOR_ERR_UNEXPECTED_TYPE) {
+ return 13;
+ }
+
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spUndefinedInMap),
+ 0);
+ QCBORDecode_EnterMap(&DCtx, NULL);
+ QCBORDecode_GetUndefinedInMapN(&DCtx, 8);
+ if(QCBORDecode_GetAndResetError(&DCtx)) {
+ return 14;
+ }
+
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBooleansInMap),
+ 0);
+ QCBORDecode_EnterMap(&DCtx, NULL);
+ QCBORDecode_GetUndefinedInMapN(&DCtx, 8);
+ if(QCBORDecode_GetAndResetError(&DCtx) != QCBOR_ERR_UNEXPECTED_TYPE) {
+ return 15;
+ }
+
+ QCBORDecode_Init(&DCtx,
+ UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spBooleansInMapNWF),
+ 0);
+ QCBORDecode_EnterMap(&DCtx, NULL);
+ QCBORDecode_GetUndefined(&DCtx);
+ if(QCBORDecode_GetAndResetError(&DCtx) != QCBOR_ERR_HIT_END) {
+ return 15;
+ }
+
return 0;
}