Skip to content

Commit 24cd62a

Browse files
laurencelundbladeLaurence Lundblade
andauthored
Small big number documentation fixes (#269)
Co-authored-by: Laurence Lundblade <[email protected]>
1 parent 0c37773 commit 24cd62a

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

inc/qcbor/qcbor_common.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,9 @@ typedef enum {
405405
* this error is returned. This error is unrecoverable because the
406406
* built-in tag decoding doesn't try to consume the unexpected
407407
* type. In previous versions of QCBOR this was considered a
408-
* recoverable error hence @ref QCBOR_ERR_BAD_TAG_CONTENT. Going
408+
* recoverable error hence QCBOR_ERR_BAD_TAG_CONTENT. Going
409409
* back further, RFC 7049 use the name "optional tags". That name
410-
* is no longer used because "optional" was causing confusion. See
411-
* also @ref QCBOR_ERR_RECOVERABLE_BAD_TAG_CONTENT. */
410+
* is no longer used because "optional" was causing confusion. */
412411
QCBOR_ERR_UNRECOVERABLE_TAG_CONTENT = 48,
413412
QCBOR_ERR_BAD_TAG_CONTENT = 48,
414413
QCBOR_ERR_BAD_OPT_TAG = 48,

inc/qcbor/qcbor_encode.h

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ extern "C" {
369369
* - The maximum tag nesting is @c QCBOR_MAX_TAGS_PER_ITEM (typically 4).
370370
* - Works only on 32- and 64-bit CPUs.
371371
* - QCBORDecode_EnterBstrWrapped() doesn't work on indefinite-length strings.
372+
* - Numeric reduction of big numbers to integers for preferred
373+
* serialization is not performed.
372374
*
373375
* The public interface uses @c size_t for all lengths. Internally the
374376
* implementation uses 32-bit lengths by design to use less memory and
@@ -987,9 +989,9 @@ QCBOREncode_AddTBinaryUUIDToMapN(QCBOREncodeContext *pCtx,
987989
* (https://www.rfc-editor.org/rfc/rfc8949.html#section-3.4.3). No
988990
* processing, such as removal of leading zeros, is perfomed.
989991
*
990-
* Sometimes big numbers are used to represent parts of cryptographic
991-
* keys, however, COSE which defines representations for keys does,
992-
* not use this particular type.
992+
* RFC 8949 preferred serialization requires big numbers that
993+
* will fit in integers be encoded as integers. That is NOT
994+
* performed.
993995
*/
994996
static void
995997
QCBOREncode_AddTPositiveBignum(QCBOREncodeContext *pCtx,
@@ -1026,6 +1028,10 @@ QCBOREncode_AddTPositiveBignumToMapN(QCBOREncodeContext *pCtx,
10261028
* (https://www.rfc-editor.org/rfc/rfc8949.html#section-3.4.3). No
10271029
* processing, such as removal of leading zeros or the required offset
10281030
* of 1 for negative values, is perfomed.
1031+
*
1032+
* RFC 8949 preferred serialization requires big numbers that
1033+
* will fit in integers be encoded as integers. That is NOT
1034+
* performed.
10291035
*/
10301036
static void
10311037
QCBOREncode_AddTNegativeBignum(QCBOREncodeContext *pCtx,
@@ -1055,7 +1061,7 @@ QCBOREncode_AddTNegativeBignumToMapN(QCBOREncodeContext *pCtx,
10551061
* @param[in] nMantissa The mantissa.
10561062
* @param[in] nBase10Exponent The exponent.
10571063
*
1058-
* The value is nMantissa * 10 ^ nBase10Exponent.
1064+
* The value is @c nMantissa * 10 ^ @c nBase10Exponent.
10591065
*
10601066
* A decimal fraction is good for exact representation of some values
10611067
* that can't be represented exactly with standard C (IEEE 754)
@@ -1074,8 +1080,8 @@ QCBOREncode_AddTNegativeBignumToMapN(QCBOREncodeContext *pCtx,
10741080
* support this range to reduce code size and interface complexity a
10751081
* little).
10761082
*
1077-
* CBOR Preferred serialization of the integers is used, thus they
1078-
* will be encoded in the smallest number of bytes possible.
1083+
* Preferred serialization is used when the mantissa or exponent are
1084+
* integers, thus they will be encoded in the smallest number of bytes.
10791085
*
10801086
* See also QCBOREncode_AddTDecimalFractionBigNum() for a decimal
10811087
* fraction with arbitrarily large precision and
@@ -1121,6 +1127,10 @@ QCBOREncode_AddTDecimalFractionToMapN(QCBOREncodeContext *pCtx,
11211127
* mantissa is a big number (See QCBOREncode_AddTPositiveBignum())
11221128
* allowing for arbitrarily large precision.
11231129
*
1130+
* RFC 8949 preferred serialization requires reduction of big numbers
1131+
* that can fit into integers be encoded as integers, not big numbers.
1132+
* This implementation does NOT do that.
1133+
*
11241134
* See @ref expAndMantissa for decoded representation.
11251135
*/
11261136
static void
@@ -1155,7 +1165,7 @@ QCBOREncode_AddTDecimalFractionBigNumToMapN(QCBOREncodeContext *pCtx,
11551165
* @param[in] nMantissa The mantissa.
11561166
* @param[in] nBase2Exponent The exponent.
11571167
*
1158-
* The value is nMantissa * 2 ^ nBase2Exponent.
1168+
* The value is @c nMantissa * 2 ^ @c nBase2Exponent.
11591169
*
11601170
* "Bigfloats", as CBOR terms them, are similar to IEEE floating-point
11611171
* numbers in having a mantissa and base-2 exponent, but they are not
@@ -1175,8 +1185,8 @@ QCBOREncode_AddTDecimalFractionBigNumToMapN(QCBOREncodeContext *pCtx,
11751185
* support this range to reduce code size and interface complexity a
11761186
* little).
11771187
*
1178-
* CBOR preferred serialization of the integers is used, thus they will
1179-
* be encoded in the smallest number of bytes possible.
1188+
* Preferred serialization is used when the mantissa or exponent are
1189+
* integers, thus they will be encoded in the smallest number of bytes.
11801190
*
11811191
* This can also be used to represent floating-point numbers in
11821192
* environments that don't support IEEE 754.
@@ -1219,6 +1229,10 @@ QCBOREncode_AddTBigFloatToMapN(QCBOREncodeContext *pCtx,
12191229
* is a big number (See QCBOREncode_AddTPositiveBignum()) allowing for
12201230
* arbitrary precision.
12211231
*
1232+
* RFC 8949 preferred serialization requires reduction of big numbers
1233+
* that can fit into integers be encoded as integers, not big numbers.
1234+
* This implementation does NOT do that.
1235+
*
12221236
* See @ref expAndMantissa for decoded representation.
12231237
*/
12241238
static void

inc/qcbor/qcbor_spiffy_decode.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,12 @@ QCBORDecode_GetEpochDaysInMapSZ(QCBORDecodeContext *pCtx,
14211421
* leaves it up to the caller to apply this computation for negative
14221422
* big numbers.
14231423
*
1424+
* RFC 8949 preferred serialization requires that big numbers
1425+
* that fit into integers be encoded as integers. This function
1426+
* will error if the input CBOR is a type 0 or 1 integers. A
1427+
* future version of QCBOR fixes this, but in the mean time
1428+
* the application must handle this manually.
1429+
*
14241430
* See @ref Tag-Usage for discussion on tag requirements.
14251431
*
14261432
* Determination of the sign of the big number depends on the tag
@@ -1438,7 +1444,6 @@ QCBORDecode_GetEpochDaysInMapSZ(QCBORDecodeContext *pCtx,
14381444
* QCBOREncode_AddTPositiveBignum(), QCBOREncode_AddTNegativeBignum(),
14391445
* @ref QCBOR_TYPE_POSBIGNUM and @ref QCBOR_TYPE_NEGBIGNUM.
14401446
*/
1441-
// Improvement: Add function that converts integers and other to big nums
14421447
void
14431448
QCBORDecode_GetBignum(QCBORDecodeContext *pCtx,
14441449
uint8_t uTagRequirement,
@@ -1558,7 +1563,7 @@ QCBORDecode_GetDecimalFractionInMapSZ(QCBORDecodeContext *pMe,
15581563
* For QCBOR before v1.5, this function had a bug where
15591564
* by the negative mantissa sometimes had the offset of
15601565
* one applied, making this function somewhat usless for
1561-
* negative mantissas. Specifically if the to-be-decode CBOR
1566+
* negative mantissas. Specifically if the to-be-decoded CBOR
15621567
* was a type 1 integer the offset was applied and when it
15631568
* was a tag 3, the offset was not applied. It is possible
15641569
* that a tag 3 could contain a value in the range of a type 1

0 commit comments

Comments
 (0)