Redesign of the configuration methods for encoder conformance
Encoder conformance can be ala carte or full options for preferred, CDE or dCBOR
* Rework encode conformance configuration
* Check in before merge
* tests are passing
---------
Co-authored-by: Laurence Lundblade <lgl@securitytheory.com>
diff --git a/test/float_tests.c b/test/float_tests.c
index 892942d..98ebc3d 100644
--- a/test/float_tests.c
+++ b/test/float_tests.c
@@ -414,7 +414,7 @@
for(uTestIndex = 0; FloatTestCases[uTestIndex].Preferred.len != 0; uTestIndex++) {
pTestCase = &FloatTestCases[uTestIndex];
- if(uTestIndex == 40) {
+ if(uTestIndex == 2) {
uDecoded = 1;
}
@@ -444,7 +444,7 @@
/* Number Encode of CDE */
QCBOREncode_Init(&EnCtx, TestOutBuffer);
- QCBOREncode_SerializationCDE(&EnCtx);
+ QCBOREncode_Config(&EnCtx, QCBOR_ENCODE_CONFIG_CDE);
QCBOREncode_AddDouble(&EnCtx, pTestCase->dNumber);
uErr = QCBOREncode_Finish(&EnCtx, &TestOutput);
@@ -457,7 +457,7 @@
/* Number Encode of dCBOR */
QCBOREncode_Init(&EnCtx, TestOutBuffer);
- QCBOREncode_SerializationdCBOR(&EnCtx);
+ QCBOREncode_Config(&EnCtx, QCBOR_ENCODE_CONFIG_DCBOR);
QCBOREncode_AddDouble(&EnCtx, pTestCase->dNumber);
uErr = QCBOREncode_Finish(&EnCtx, &TestOutput);
@@ -470,7 +470,7 @@
if(pTestCase->fNumber != 0) {
QCBOREncode_Init(&EnCtx, TestOutBuffer);
- QCBOREncode_SerializationdCBOR(&EnCtx);
+ QCBOREncode_Config(&EnCtx, QCBOR_ENCODE_CONFIG_DCBOR);
QCBOREncode_AddFloat(&EnCtx, pTestCase->fNumber);
uErr = QCBOREncode_Finish(&EnCtx, &TestOutput);
@@ -567,7 +567,7 @@
/* NaN Encode of Preferred */
QCBOREncode_Init(&EnCtx, TestOutBuffer);
- QCBOREncode_Allow(&EnCtx, QCBOR_ENCODE_ALLOW_NAN_PAYLOAD);
+ QCBOREncode_Config(&EnCtx, QCBOR_ENCODE_CONFIG_ALLOW_NAN_PAYLOAD);
QCBOREncode_AddDouble(&EnCtx, UsefulBufUtil_CopyUint64ToDouble(pNaNTestCase->uDouble));
uErr = QCBOREncode_Finish(&EnCtx, &TestOutput);
if(uErr != QCBOR_SUCCESS) {
@@ -616,7 +616,7 @@
/* NaN Encode of Not Preferred */
QCBOREncode_Init(&EnCtx, TestOutBuffer);
- QCBOREncode_Allow(&EnCtx, QCBOR_ENCODE_ALLOW_NAN_PAYLOAD);
+ QCBOREncode_Config(&EnCtx, QCBOR_ENCODE_CONFIG_ALLOW_NAN_PAYLOAD);
QCBOREncode_AddDoubleNoPreferred(&EnCtx, UsefulBufUtil_CopyUint64ToDouble(pNaNTestCase->uDouble));
uErr = QCBOREncode_Finish(&EnCtx, &TestOutput);
if(uErr != QCBOR_SUCCESS) {
@@ -628,7 +628,7 @@
/* NaN Decode of Not Preferred */
QCBORDecode_Init(&DCtx, pNaNTestCase->Preferred, 0);
- QCBOREncode_Allow(&EnCtx, QCBOR_ENCODE_ALLOW_NAN_PAYLOAD);
+ QCBOREncode_Config(&EnCtx, QCBOR_ENCODE_CONFIG_ALLOW_NAN_PAYLOAD);
uErr = QCBORDecode_GetNext(&DCtx, &Item);
if(uErr != QCBOR_SUCCESS) {
return MakeTestResultCode(uTestIndex+100, 12, uErr);
@@ -664,7 +664,7 @@
/* NaN Decode of Not Preferred */
QCBORDecode_Init(&DCtx, pNaNTestCase->NotPreferred, 0);
- QCBOREncode_Allow(&EnCtx, QCBOR_ENCODE_ALLOW_NAN_PAYLOAD);
+ QCBOREncode_Config(&EnCtx, QCBOR_ENCODE_CONFIG_ALLOW_NAN_PAYLOAD);
uErr = QCBORDecode_GetNext(&DCtx, &Item);
if(uErr != QCBOR_SUCCESS) {
return MakeTestResultCode(uTestIndex+100, 13, uErr);
@@ -677,8 +677,7 @@
/* NaN Encode of DCBOR */
QCBOREncode_Init(&EnCtx, TestOutBuffer);
- QCBOREncode_Allow(&EnCtx, QCBOR_ENCODE_ALLOW_NAN_PAYLOAD);
- QCBOREncode_SerializationdCBOR(&EnCtx);
+ QCBOREncode_Config(&EnCtx, QCBOR_ENCODE_CONFIG_DCBOR | QCBOR_ENCODE_CONFIG_ALLOW_NAN_PAYLOAD);
QCBOREncode_AddDouble(&EnCtx, UsefulBufUtil_CopyUint64ToDouble(pNaNTestCase->uDouble));
uErr = QCBOREncode_Finish(&EnCtx, &TestOutput);
if(uErr != QCBOR_SUCCESS) {
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 9360da2..0fabc4f 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -2610,7 +2610,7 @@
}
#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS */
- if(nIndex == 0) {
+ if(nIndex == 57) {
uCBORError = 9; /* For setting break points */
}
@@ -10612,12 +10612,17 @@
{"\xa1\x81\x1c\x01", 4},
QCBOR_ERR_MAP_LABEL_TYPE
},
-
+ { "map with map label ",
+ QCBOR_DECODE_MODE_CDE,
+ {"\xa1\xa1\x00\x01\x02", 5},
+ QCBOR_ERR_MAP_LABEL_TYPE
+ },
{ "map with map label with non-preferred part",
QCBOR_DECODE_MODE_CDE,
{"\xa1\xa1\x19\x00\x00\x01\x02", 7},
- QCBOR_ERR_MAP_LABEL_TYPE
- }};
+ QCBOR_ERR_PREFERRED_CONFORMANCE
+ }
+};
static UsefulBufC CorrectlySorted[] = {
diff --git a/test/qcbor_encode_tests.c b/test/qcbor_encode_tests.c
index 3c758f2..b756053 100644
--- a/test/qcbor_encode_tests.c
+++ b/test/qcbor_encode_tests.c
@@ -722,7 +722,7 @@
nReturn = 0;
QCBOREncode_Init(&ECtx, UsefulBuf_FROM_BYTE_ARRAY(spBigBuf));
- QCBOREncode_Allow(&ECtx, QCBOR_ENCODE_ALLOW_ALL);
+ QCBOREncode_Config(&ECtx, QCBOR_ENCODE_CONFIG_ALLOW_NAN_PAYLOAD);
AddAll(&ECtx);
@@ -739,7 +739,7 @@
/* Also test size calculation */
QCBOREncode_Init(&ECtx, SizeCalculateUsefulBuf);
- QCBOREncode_Allow(&ECtx, QCBOR_ENCODE_ALLOW_ALL);
+ QCBOREncode_Config(&ECtx, QCBOR_ENCODE_CONFIG_ALLOW_NAN_PAYLOAD);
AddAll(&ECtx);
@@ -3122,10 +3122,10 @@
switch(pTest->eSerialization) {
case EAM_Pref:
- QCBOREncode_SerializationPreferred(pEnc);
+ QCBOREncode_Config(pEnc, QCBOR_ENCODE_CONFIG_PREFERRED );
break;
case EAM_CDE:
- QCBOREncode_SerializationCDE(pEnc);
+ QCBOREncode_Config(pEnc, QCBOR_ENCODE_CONFIG_CDE);
break;
default:
@@ -3302,7 +3302,6 @@
} else {
EAMTestSetup(pTest, &EC);
- //QCBOREncode_AddDecimalFractionBigNum(&EC, pTest->BigNumMantissa, pTest->bSign, pTest->nExponent);
QCBOREncode_AddTDecimalFractionBigMantissa(&EC, QCBOR_ENCODE_AS_TAG, pTest->BigNumMantissa, pTest->bSign, pTest->nExponent);
uErr = QCBOREncode_Finish(&EC, &EncodedExponentAndMantissa);
if(uErr) {
@@ -3969,7 +3968,8 @@
QCBOREncode_Init(&EC, UsefulBuf_FROM_BYTE_ARRAY(spBigBuf));
- QCBOREncode_SerializationCDE(&EC);
+ QCBOREncode_Config(&EC, QCBOR_ENCODE_CONFIG_CDE);
+
/* Items added to test sorting and preferred encoding of numbers and floats */
QCBOREncode_OpenMap(&EC);
@@ -4008,7 +4008,7 @@
#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
/* Next, make sure methods that encode non-CDE error out */
QCBOREncode_Init(&EC, UsefulBuf_FROM_BYTE_ARRAY(spBigBuf));
- QCBOREncode_SerializationCDE(&EC);
+ QCBOREncode_Config(&EC, QCBOR_ENCODE_CONFIG_CDE);
QCBOREncode_OpenMapIndefiniteLength(&EC);
QCBOREncode_CloseMap(&EC);
if(QCBOREncode_GetErrorState(&EC) != uExpectedErr) {
@@ -4027,8 +4027,8 @@
QCBORError uExpectedErr;
QCBOREncode_Init(&EC, UsefulBuf_FROM_BYTE_ARRAY(spBigBuf));
+ QCBOREncode_Config(&EC, QCBOR_ENCODE_CONFIG_DCBOR);
- QCBOREncode_SerializationdCBOR(&EC);
/* Items added to test sorting and preferred encoding of numbers and floats */
QCBOREncode_OpenMap(&EC);
@@ -4065,7 +4065,7 @@
#ifndef QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS
/* Indefinite-length map */
QCBOREncode_Init(&EC, UsefulBuf_FROM_BYTE_ARRAY(spBigBuf));
- QCBOREncode_SerializationdCBOR(&EC);
+ QCBOREncode_Config(&EC, QCBOR_ENCODE_CONFIG_DCBOR);
QCBOREncode_OpenMapIndefiniteLength(&EC);
QCBOREncode_CloseMap(&EC);
if(QCBOREncode_GetErrorState(&EC) != uExpectedErr) {
@@ -4074,7 +4074,7 @@
/* Indefinite-length array */
QCBOREncode_Init(&EC, UsefulBuf_FROM_BYTE_ARRAY(spBigBuf));
- QCBOREncode_SerializationdCBOR(&EC);
+ QCBOREncode_Config(&EC, QCBOR_ENCODE_CONFIG_DCBOR);
QCBOREncode_OpenArrayIndefiniteLength(&EC);
QCBOREncode_CloseMap(&EC);
if(QCBOREncode_GetErrorState(&EC) != uExpectedErr) {
@@ -4084,7 +4084,7 @@
/* The "undef" special value */
QCBOREncode_Init(&EC, UsefulBuf_FROM_BYTE_ARRAY(spBigBuf));
- QCBOREncode_SerializationdCBOR(&EC);
+ QCBOREncode_Config(&EC, QCBOR_ENCODE_CONFIG_DCBOR);
QCBOREncode_AddUndef(&EC);
QCBOREncode_CloseMap(&EC);
if(QCBOREncode_GetErrorState(&EC) != uExpectedErr) {