QCBOR: Add xx_IsBufferNULL(); update docs; endianness options

- xx_IsBufferNULL() allows caller of QCBOREncode to know if
  encoding is just a size calculation or a real encoding.
- Large changes to improve documentation and style in the .h
  files.
- New #define config options for compiler / OS / CPU specific
  endianness conversion that can reduce code size slightly.
  No incompatible changes and as before no requirement to
  define config for endianness.

Change-Id: Iaa443e6ac39c536dd5ed3b6f1316fd18cb624832
Signed-off-by: Laurence Lundblade <lgl@securitytheory.com>
diff --git a/lib/ext/qcbor/test/UsefulBuf_Tests.c b/lib/ext/qcbor/test/UsefulBuf_Tests.c
index 388f8cf..f53693a 100644
--- a/lib/ext/qcbor/test/UsefulBuf_Tests.c
+++ b/lib/ext/qcbor/test/UsefulBuf_Tests.c
@@ -238,6 +238,11 @@
       return "lengths near max size";
    }
 
+   UsefulOutBuf_Init(&UOB, (UsefulBuf){NULL, 100});
+   if(!UsefulOutBuf_IsBufferNULL(&UOB)) {
+      return "NULL check failed";
+   }
+
    return NULL;
 }
 
diff --git a/lib/ext/qcbor/test/qcbor_decode_tests.c b/lib/ext/qcbor/test/qcbor_decode_tests.c
index e9d54fb..680c86b 100644
--- a/lib/ext/qcbor/test/qcbor_decode_tests.c
+++ b/lib/ext/qcbor/test/qcbor_decode_tests.c
@@ -1305,13 +1305,13 @@
    if(Item.uDataType != QCBOR_TYPE_UKNOWN_SIMPLE || Item.val.uSimple != 19)
       return -1;
 
-   if(QCBORDecode_GetNext(&DCtx, &Item) != QCBOR_ERR_INVALID_CBOR)
+   if(QCBORDecode_GetNext(&DCtx, &Item) != QCBOR_ERR_BAD_TYPE_7)
       return -1;
 
-   if(QCBORDecode_GetNext(&DCtx, &Item) != QCBOR_ERR_INVALID_CBOR)
+   if(QCBORDecode_GetNext(&DCtx, &Item) != QCBOR_ERR_BAD_TYPE_7)
       return -1;
 
-   if(QCBORDecode_GetNext(&DCtx, &Item) != QCBOR_ERR_INVALID_CBOR)
+   if(QCBORDecode_GetNext(&DCtx, &Item) != QCBOR_ERR_BAD_TYPE_7)
       return -1;
 
    if((nCBORError = QCBORDecode_GetNext(&DCtx, &Item)))
@@ -1352,8 +1352,8 @@
    { {(uint8_t[]){0x7c}, 1}, QCBOR_ERR_UNSUPPORTED }, // Reserved additional info = 28
    { {(uint8_t[]){0x7f}, 1}, QCBOR_ERR_UNSUPPORTED }, // Indefinite length UTF-8 string
    { {(uint8_t[]){0xff}, 1}, QCBOR_ERR_UNSUPPORTED } , // break
-   { {(uint8_t[]){0xf8, 0x00}, 2}, QCBOR_ERR_INVALID_CBOR }, // An invalid encoding of a simple type
-   { {(uint8_t[]){0xf8, 0x1f}, 2}, QCBOR_ERR_INVALID_CBOR },  // An invalid encoding of a simple type
+   { {(uint8_t[]){0xf8, 0x00}, 2}, QCBOR_ERR_BAD_TYPE_7 }, // An invalid encoding of a simple type
+   { {(uint8_t[]){0xf8, 0x1f}, 2}, QCBOR_ERR_BAD_TYPE_7 },  // An invalid encoding of a simple type
    { {(uint8_t[]){0xc0, 0x00}, 2}, QCBOR_ERR_BAD_OPT_TAG },  // Text-based date, with an integer
    { {(uint8_t[]){0xc1, 0x41, 0x33}, 3}, QCBOR_ERR_BAD_OPT_TAG },   // Epoch date, with an byte string
    { {(uint8_t[]){0xc1, 0xc0, 0x00}, 3}, QCBOR_ERR_BAD_OPT_TAG },   // tagged as both epoch and string dates
diff --git a/lib/ext/qcbor/test/qcbor_encode_tests.c b/lib/ext/qcbor/test/qcbor_encode_tests.c
index 89db5e5..458331c 100644
--- a/lib/ext/qcbor/test/qcbor_encode_tests.c
+++ b/lib/ext/qcbor/test/qcbor_encode_tests.c
@@ -1910,7 +1910,7 @@
 
    // ------ Test for QCBOR_ERR_BUFFER_TOO_LARGE ------
    // Do all of these tests with NULL buffers so no actual large allocations are neccesary
-   UsefulBuf Buffer = (UsefulBuf){NULL, UINT32_MAX};
+   const UsefulBuf Buffer = (UsefulBuf){NULL, UINT32_MAX};
 
    // First verify no error from a big buffer
    QCBOREncode_Init(&EC, Buffer);
@@ -1925,10 +1925,15 @@
    }
 
    // Second verify error from an array in encoded output too large
+   // Also test fetching the error code before finish
    QCBOREncode_Init(&EC, Buffer);
    QCBOREncode_OpenArray(&EC);
    QCBOREncode_AddBytes(&EC, (UsefulBufC){NULL, UINT32_MAX-6});
    QCBOREncode_OpenArray(&EC); // Where QCBOR internally encounters and records error
+   if(QCBOREncode_GetErrorState(&EC) != QCBOR_ERR_BUFFER_TOO_LARGE) {
+      // Error fetch failed.
+      return -12;
+   }
    QCBOREncode_CloseArray(&EC);
    QCBOREncode_CloseArray(&EC);
    if(QCBOREncode_FinishGetSize(&EC, &xx) != QCBOR_ERR_BUFFER_TOO_LARGE) {
@@ -1950,7 +1955,7 @@
    // ----- QCBOR_ERR_BUFFER_TOO_SMALL --------------
    // Work close to the 4GB size limit for a better test
    const uint32_t uLargeSize =  UINT32_MAX - 1024;
-   UsefulBuf Large = (UsefulBuf){NULL,uLargeSize};
+   const UsefulBuf Large = (UsefulBuf){NULL,uLargeSize};
 
    QCBOREncode_Init(&EC, Large);
    QCBOREncode_OpenArray(&EC);
@@ -2038,6 +2043,13 @@
    /* QCBOR_ERR_ARRAY_TOO_LONG is not tested here as
     it would require a 64KB of RAM to test */
 
+
+   // ----- Test the check for NULL buffer ------
+   QCBOREncode_Init(&EC, Buffer);
+   if(QCBOREncode_IsBufferNULL(&EC) == 0) {
+      return -11;
+   }
+
    return 0;
 }