Add GetSimple, update Simple Value documentation (#236)
Add the method QCBORDecode_GetSimple(). Update testing and documentation for simple values.
* Add GetSimple
* Finish off GetSimple and friends
* Fix tests when tags are disabled
---------
Co-authored-by: Laurence Lundblade <lgl@securitytheory.com>
diff --git a/inc/qcbor/qcbor_encode.h b/inc/qcbor/qcbor_encode.h
index daea469..83c167e 100644
--- a/inc/qcbor/qcbor_encode.h
+++ b/inc/qcbor/qcbor_encode.h
@@ -1800,15 +1800,20 @@
* @param[in] pMe The encode context.
* @param[in] uNum The simple value.
*
- * Use QCBOREncode_AddBool(), QCBOREncode_AddUndef()... instead of this.
+ * QCBOREncode_AddBool(), QCBOREncode_AddUndef() and
+ * QCBOREncode_AddNull() are preferred to this for the simple values
+ * defined in RFC 8949, but this can be used for them too.
*
- * Use this to add simple values beyond those in defined RFC
- * 8949. Simple values must be registered with IANA. There is no range
- * of values for proprietary use.
+ * The main purpose of this is to add simple values beyond those in
+ * defined RFC 8949. Note that simple values must be registered with
+ * IANA. Those in the range of 0 to 19 must be standardized. Those in
+ * the range of 32 to 255 do not require a standard, but must be
+ * publically specified. There is no range of values for proprietary
+ * use. See
* https://www.iana.org/assignments/cbor-simple-values/cbor-simple-values.xhtml
*/
static void
-QCBOREncode_AddSimple(QCBOREncodeContext *pMe, const uint64_t uNum);
+QCBOREncode_AddSimple(QCBOREncodeContext *pMe, const uint8_t uNum);
static void
QCBOREncode_AddSimpleToMap(QCBOREncodeContext *pMe,
@@ -3751,7 +3756,7 @@
static inline void
-QCBOREncode_AddSimple(QCBOREncodeContext *pMe, const uint64_t uNum)
+QCBOREncode_AddSimple(QCBOREncodeContext *pMe, const uint8_t uNum)
{
/* This check often is optimized out because uNum is known at compile time. */
#ifndef QCBOR_DISABLE_ENCODE_USAGE_GUARDS
@@ -3766,8 +3771,8 @@
static inline void
QCBOREncode_AddSimpleToMap(QCBOREncodeContext *pMe,
- const char *szLabel,
- const uint8_t uSimple)
+ const char *szLabel,
+ const uint8_t uSimple)
{
QCBOREncode_AddSZString(pMe, szLabel);
QCBOREncode_AddSimple(pMe, uSimple);
@@ -3775,8 +3780,8 @@
static inline void
QCBOREncode_AddSimpleToMapN(QCBOREncodeContext *pMe,
- const int64_t nLabel,
- const uint8_t uSimple)
+ const int64_t nLabel,
+ const uint8_t uSimple)
{
QCBOREncode_AddInt64(pMe, nLabel);
QCBOREncode_AddSimple(pMe, uSimple);