1 // SPDX-License-Identifier: BSD-3-Clause
2 /* ==========================================================================
3  * Copyright (c) 2016-2018, The Linux Foundation.
4  * Copyright (c) 2018-2024, Laurence Lundblade.
5  * Copyright (c) 2021, Arm Limited.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above
14  *       copyright notice, this list of conditions and the following
15  *       disclaimer in the documentation and/or other materials provided
16  *       with the distribution.
17  *     * Neither the name of The Linux Foundation nor the names of its
18  *       contributors, nor the name "Laurence Lundblade" may be used to
19  *       endorse or promote products derived from this software without
20  *       specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
23  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
26  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
32  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  * ========================================================================= */
34 
35 
36 #ifndef qcbor_common_h
37 #define qcbor_common_h
38 
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #if 0
43 } // Keep editor indention formatting happy
44 #endif
45 #endif
46 
47 
48 /**
49  * @file qcbor_common.h
50  *
51  * Constant values for types, error codes and such that are common to
52  * encoding and decoding.
53  */
54 
55 
56 /**
57  * Semantic versioning for QCBOR x.y.z from 1.3.0 on
58  *
59  * Note:
60  *   - QCBOR 1.2 is indicated by the #define QCBOR_1_2
61  *   - QCBOR 1.1 is indicated by the #define QCBOR_1_1
62  *   - QCBOR 1.0 is indicated by the absence of all the above
63  */
64 #define QCBOR_VERSION_MAJOR 1
65 #define QCBOR_VERSION_MINOR 4
66 #define QCBOR_VERSION_PATCH 1
67 
68 
69 /**
70  * This define indicates a version of QCBOR that supports spiffy
71  * decode, the decode functions found in qcbor_spiffy_decode.h.
72  *
73  * Versions of QCBOR that support spiffy decode are backwards
74  * compatible with previous versions, but there are a few minor
75  * exceptions such as some aspects of tag handling that are
76  * different. This define can be used to handle these variances.
77  */
78 #define QCBOR_SPIFFY_DECODE
79 
80 
81 
82 /* Standard CBOR Major type for positive integers of various lengths. */
83 #define CBOR_MAJOR_TYPE_POSITIVE_INT 0
84 
85 /* Standard CBOR Major type for negative integer of various lengths. */
86 #define CBOR_MAJOR_TYPE_NEGATIVE_INT 1
87 
88 /* Standard CBOR Major type for an array of arbitrary 8-bit bytes. */
89 #define CBOR_MAJOR_TYPE_BYTE_STRING  2
90 
91 /* Standard CBOR Major type for a UTF-8 string. Note this is true 8-bit UTF8
92  * with no encoding and no NULL termination. */
93 #define CBOR_MAJOR_TYPE_TEXT_STRING  3
94 
95 /* Standard CBOR Major type for an ordered array of other CBOR data items. */
96 #define CBOR_MAJOR_TYPE_ARRAY        4
97 
98 /* Standard CBOR Major type for CBOR MAP. Maps an array of pairs. The
99  * first item in the pair is the "label" (key, name or identfier) and the second
100  * item is the value.  */
101 #define CBOR_MAJOR_TYPE_MAP          5
102 
103 /* Standard CBOR major type for a tag number. This creates a CBOR "tag" that
104  * is the tag number and a data item that follows as the tag content.
105  *
106  * Note that this was called an optional tag in RFC 7049, but there's
107  * not really anything optional about it. It was misleading. It is
108  * renamed in RFC 8949.
109  */
110 #define CBOR_MAJOR_TYPE_TAG          6
111 #define CBOR_MAJOR_TYPE_OPTIONAL     6
112 
113 /* Standard CBOR simple types like float, the values true, false, null... */
114 #define CBOR_MAJOR_TYPE_SIMPLE       7
115 
116 
117 
118 
119 /*
120  * Tags that are used with CBOR_MAJOR_TYPE_OPTIONAL. These
121  * are types defined in RFC 8949 and some additional ones
122  * in the IANA CBOR tags registry.
123  */
124 /** See QCBOREncode_AddDateString(). */
125 #define CBOR_TAG_DATE_STRING    0
126 /** See QCBOREncode_AddDateEpoch(). */
127 #define CBOR_TAG_DATE_EPOCH     1
128 /** See QCBOREncode_AddPositiveBignum(). */
129 #define CBOR_TAG_POS_BIGNUM     2
130 /** See QCBOREncode_AddNegativeBignum(). */
131 #define CBOR_TAG_NEG_BIGNUM     3
132 /** CBOR tag for a two-element array representing a fraction with a
133  *  mantissa and base-10 scaling factor. See
134  *  QCBOREncode_AddDecimalFraction() and @ref expAndMantissa. */
135 #define CBOR_TAG_DECIMAL_FRACTION  4
136 /** CBOR tag for a two-element array representing a fraction with a
137  *  mantissa and base-2 scaling factor. See QCBOREncode_AddBigFloat()
138  *  and @ref expAndMantissa. */
139 #define CBOR_TAG_BIGFLOAT       5
140 /** Not Decoded by QCBOR. Tag for COSE format encryption with no
141  *  recipient identification. See [RFC 8152, COSE]
142  *  (https://tools.ietf.org/html/rfc8152). No API is provided for this
143  *  tag. */
144 #define CBOR_TAG_COSE_ENCRYPT0 16
145 #define CBOR_TAG_COSE_ENCRYPTO 16
146 /** Not Decoded by QCBOR. Tag for COSE format MAC'd data with no
147  *  recipient identification. See [RFC 8152, COSE]
148  *  (https://tools.ietf.org/html/rfc8152). No API is provided for this
149  *  tag. */
150 #define CBOR_TAG_COSE_MAC0     17
151 /** Tag for COSE format single signature signing. No API is provided
152  *  for this tag. See [RFC 8152, COSE]
153  *  (https://tools.ietf.org/html/rfc8152). */
154 #define CBOR_TAG_COSE_SIGN1    18
155 /** A hint that the following byte string should be encoded in
156  *  Base64URL when converting to JSON or similar text-based
157  *  representations. Call @c
158  *  QCBOREncode_AddTag(pCtx,CBOR_TAG_ENC_AS_B64URL) before the call to
159  *  QCBOREncode_AddBytes(). */
160 #define CBOR_TAG_ENC_AS_B64URL 21
161 /** A hint that the following byte string should be encoded in Base64
162  *  when converting to JSON or similar text-based
163  *  representations. Call @c
164  *  QCBOREncode_AddTag(pCtx,CBOR_TAG_ENC_AS_B64) before the call to
165  *  QCBOREncode_AddBytes(). */
166 #define CBOR_TAG_ENC_AS_B64    22
167 /** A hint that the following byte string should be encoded in base-16
168  *  format per [RFC 4648] (https://tools.ietf.org/html/rfc4648) when
169  *  converting to JSON or similar text-based
170  *  representations. Essentially, Base-16 encoding is the standard
171  *  case- insensitive hex encoding and may be referred to as
172  *  "hex". Call @c QCBOREncode_AddTag(pCtx,CBOR_TAG_ENC_AS_B16) before
173  *  the call to QCBOREncode_AddBytes(). */
174 #define CBOR_TAG_ENC_AS_B16    23
175 /** See QCBORDecode_EnterBstrWrapped()). */
176 #define CBOR_TAG_CBOR          24
177 /** See QCBOREncode_AddURI(). */
178 #define CBOR_TAG_URI           32
179 /** See QCBOREncode_AddB64URLText(). */
180 #define CBOR_TAG_B64URL        33
181 /** See QCBOREncode_AddB64Text(). */
182 #define CBOR_TAG_B64           34
183 /** See QCBOREncode_AddRegex(). */
184 #define CBOR_TAG_REGEX         35
185 /** See QCBOREncode_AddMIMEData(). */
186 #define CBOR_TAG_MIME          36
187 /** See QCBOREncode_AddBinaryUUID(). */
188 #define CBOR_TAG_BIN_UUID      37
189 /** The data is a CBOR Web Token per [RFC 8392]
190  *  (https://tools.ietf.org/html/rfc8932). No API is provided for this
191  *  tag. */
192 #define CBOR_TAG_CWT           61
193 /** Tag for COSE format encryption. See [RFC 8152, COSE]
194  *  (https://tools.ietf.org/html/rfc8152). No API is provided for this
195  *  tag. */
196 #define CBOR_TAG_CBOR_SEQUENCE 63
197 /** Not Decoded by QCBOR. Tag for COSE format encrypt. See [RFC 8152, COSE]
198  *  (https://tools.ietf.org/html/rfc8152). No API is provided for this
199  *  tag. */
200 #define CBOR_TAG_COSE_ENCRYPT  96
201 #define CBOR_TAG_ENCRYPT       96
202 /** Not Decoded by QCBOR. Tag for COSE format MAC. See [RFC 8152, COSE]
203     (https://tools.ietf.org/html/rfc8152). No API is provided for this
204     tag. */
205 #define CBOR_TAG_COSE_MAC      97
206 #define CBOR_TAG_MAC           97
207 /** Not Decoded by QCBOR. Tag for COSE format signed data. See [RFC 8152, COSE]
208     (https://tools.ietf.org/html/rfc8152). No API is provided for this
209     tag. */
210 #define CBOR_TAG_COSE_SIGN     98
211 #define CBOR_TAG_SIGN          98
212 /** Tag for date counted by days from Jan 1 1970 per [RFC 8943]
213  *  (https://tools.ietf.org/html/rfc8943). See
214  *  QCBOREncode_AddTDaysEpoch(). */
215 #define CBOR_TAG_DAYS_EPOCH    100
216 /** Not Decoded by QCBOR. World geographic coordinates. See ISO 6709, [RFC 5870]
217  *  (https://tools.ietf.org/html/rfc5870) and WGS-84. No API is
218  *  provided for this tag. */
219 #define CBOR_TAG_GEO_COORD     103
220 /** Binary MIME.*/
221 #define CBOR_TAG_BINARY_MIME   257
222 /** Tag for date string without time or time zone per [RFC 8943]
223  *  (https://tools.ietf.org/html/rfc8943). See
224  *  QCBOREncode_AddTDaysString(). */
225 #define CBOR_TAG_DAYS_STRING   1004
226 /** The magic number, self-described CBOR. No API is provided for this
227  * tag. */
228 #define CBOR_TAG_CBOR_MAGIC    55799
229 
230 /** The 16-bit invalid tag from the CBOR tags registry */
231 #define CBOR_TAG_INVALID16 0xffff
232 /** The 32-bit invalid tag from the CBOR tags registry */
233 #define CBOR_TAG_INVALID32 0xffffffff
234 /** The 64-bit invalid tag from the CBOR tags registry */
235 #define CBOR_TAG_INVALID64 0xffffffffffffffff
236 
237 
238 
239 
240 /**
241  * Error codes returned by QCBOR Encoder-Decoder.
242  *
243  * They are grouped to keep the code size of
244  * QCBORDecode_IsNotWellFormedError() and
245  * QCBORDecode_IsUnrecoverableError() minimal.
246  *
247  *    1..19: Encode errors
248  *    20..: Decode errors
249  *    20-39: QCBORDecode_IsNotWellFormedError()
250  *    30..59: QCBORDecode_IsUnrecoverableError()
251  *    60..: Other decode errors
252  *
253  * Error renumbering may occur in the future when new error codes are
254  * added for new QCBOR features.
255  */
256 typedef enum {
257    /** The encode or decode completed correctly. */
258    QCBOR_SUCCESS = 0,
259 
260    /** The buffer provided for the encoded output when doing encoding
261     *   was too small and the encoded output will not fit. */
262    QCBOR_ERR_BUFFER_TOO_SMALL = 1,
263 
264    /** During encoding, an attempt to create simple value between 24
265     *  and 31. */
266    QCBOR_ERR_ENCODE_UNSUPPORTED = 2,
267 
268    /** During encoding, the length of the encoded CBOR exceeded
269     *  @ref QCBOR_MAX_ARRAY_OFFSET, which is slightly less than
270     *  @c UINT32_MAX. */
271    QCBOR_ERR_BUFFER_TOO_LARGE = 3,
272 
273    /** During encoding, the array or map nesting was deeper than this
274     *  implementation can handle. Note that in the interest of code
275     *  size and memory use, QCBOR has a hard limit on array
276     *  nesting. The limit is defined as the constant
277     *  @ref QCBOR_MAX_ARRAY_NESTING. */
278    QCBOR_ERR_ARRAY_NESTING_TOO_DEEP = 4,
279 
280    /** During encoding, @c QCBOREncode_CloseXxx() called for a
281     *  different type than is currently open.  */
282    QCBOR_ERR_CLOSE_MISMATCH = 5,
283 
284    /** During encoding, the array or map had too many items in it.
285     *  This limit @ref QCBOR_MAX_ITEMS_IN_ARRAY, typically 65,535. */
286    QCBOR_ERR_ARRAY_TOO_LONG = 6,
287 
288    /** During encoding, more arrays or maps were closed than
289     *  opened. This is a coding error on the part of the caller of the
290     *  encoder. */
291    QCBOR_ERR_TOO_MANY_CLOSES = 7,
292 
293    /** During encoding, the number of array or map opens was not
294     *  matched by the number of closes. Also occurs with opened byte
295     *  strings that are not closed. */
296    QCBOR_ERR_ARRAY_OR_MAP_STILL_OPEN = 8,
297 
298    /** During encoding, opening a byte string while a byte string is
299     *  open is not allowed. */
300    QCBOR_ERR_OPEN_BYTE_STRING = 9,
301 
302    /** Trying to cancel a byte string wrapping after items have been
303     *  added to it. */
304    QCBOR_ERR_CANNOT_CANCEL = 10,
305 
306 #define QCBOR_START_OF_NOT_WELL_FORMED_ERRORS 20
307 
308    /** During decoding, the CBOR is not well-formed because a simple
309     *  value between 0 and 31 is encoded in a two-byte integer rather
310     *  than one. */
311    QCBOR_ERR_BAD_TYPE_7 = 20,
312 
313    /** During decoding, returned by QCBORDecode_Finish() if all the
314     *  inputs bytes have not been consumed. This is considered not
315     *  well-formed. */
316    QCBOR_ERR_EXTRA_BYTES = 21,
317 
318    /** During decoding, some CBOR construct was encountered that this
319     *  decoder doesn't support, primarily this is the reserved
320     *  additional info values, 28 through 30. The CBOR is not
321     *  well-formed.
322     */
323    QCBOR_ERR_UNSUPPORTED = 22,
324 
325    /** During decoding, the an array or map was not fully consumed.
326     *  Returned by QCBORDecode_Finish(). The CBOR is not
327     *  well-formed. */
328    QCBOR_ERR_ARRAY_OR_MAP_UNCONSUMED = 23,
329 
330    /** During decoding, an integer type is encoded with a bad length
331     *  (that of an indefinite length string). The CBOR is not-well
332     *  formed. */
333    QCBOR_ERR_BAD_INT = 24,
334 
335 #define QCBOR_START_OF_UNRECOVERABLE_DECODE_ERRORS 30
336 
337    /** During decoding, one of the chunks in an indefinite-length
338     *  string is not of the type of the start of the string.  The CBOR
339     *  is not well-formed.  This error makes no further decoding
340     *  possible. */
341    QCBOR_ERR_INDEFINITE_STRING_CHUNK = 30,
342 
343    /** During decoding, hit the end of the given data to decode. For
344     *  example, a byte string of 100 bytes was expected, but the end
345     *  of the input was hit before finding those 100 bytes.  Corrupted
346     *  CBOR input will often result in this error. See also
347     *  @ref QCBOR_ERR_NO_MORE_ITEMS. The CBOR is not well-formed.
348     *  This error makes no further decoding possible. */
349    QCBOR_ERR_HIT_END = 31,
350 
351    /** During decoding, a break occurred outside an indefinite-length
352     *  item. The CBOR is not well-formed. This error makes no further
353     *  decoding possible. */
354    QCBOR_ERR_BAD_BREAK = 32,
355 
356 #define QCBOR_END_OF_NOT_WELL_FORMED_ERRORS 39
357 
358    /** During decoding, the input is too large. It is greater than
359     *  QCBOR_MAX_DECODE_INPUT_SIZE. This is an implementation limit.
360     *  This error makes no further decoding possible. */
361    QCBOR_ERR_INPUT_TOO_LARGE = 40,
362 
363    /** During decoding, the array or map nesting was deeper than this
364     *  implementation can handle. Note that in the interest of code
365     *  size and memory use, QCBOR has a hard limit on array
366     *  nesting. The limit is defined as the constant
367     *  @ref QCBOR_MAX_ARRAY_NESTING. This error makes no further
368     *  decoding possible. */
369    QCBOR_ERR_ARRAY_DECODE_NESTING_TOO_DEEP = 41,
370 
371    /** During decoding, the array or map had too many items in it.
372     *  This limit @ref QCBOR_MAX_ITEMS_IN_ARRAY, typically 65,534,
373     *  UINT16_MAX - 1. This error makes no further decoding
374     *  possible. */
375    QCBOR_ERR_ARRAY_DECODE_TOO_LONG = 42,
376 
377    /** When decoding, a string's size is greater than what a size_t
378     *  can hold less 4. In all but some very strange situations this
379     *  is because of corrupt input CBOR and should be treated as
380     *  such. The strange situation is a CPU with a very small size_t
381     *  (e.g., a 16-bit CPU) and a large string (e.g., > 65KB). This
382     *  error makes no further decoding possible. */
383    QCBOR_ERR_STRING_TOO_LONG = 43,
384 
385    /** Something is wrong with a decimal fraction or bigfloat such as
386     *  it not consisting of an array with two integers. This error
387     *  makes no further decoding possible. */
388    QCBOR_ERR_BAD_EXP_AND_MANTISSA = 44,
389 
390    /** Unable to decode an indefinite-length string because no string
391     *  allocator was configured. See QCBORDecode_SetMemPool() or
392     *  QCBORDecode_SetUpAllocator().  This error makes no further
393     *  decoding possible.*/
394    QCBOR_ERR_NO_STRING_ALLOCATOR = 45,
395 
396    /** Error allocating memory for a string, usually out of memory.
397     * This primarily occurs decoding indefinite-length strings. This
398     * error makes no further decoding possible. */
399    QCBOR_ERR_STRING_ALLOCATE = 46,
400 
401    /** During decoding, the type of the label for a map entry is not
402     *  one that can be handled in the current decoding mode. Typically
403     *  this is because a label is not an integer or a string. This is
404     *  an implementation limit. */
405    QCBOR_ERR_MAP_LABEL_TYPE = 47,
406 
407    /** When the built-in tag decoding encounters an unexpected type,
408     *  this error is returned. This error is unrecoverable because the
409     *  built-in tag decoding doesn't try to consume the unexpected
410     *  type. In previous versions of QCBOR this was considered a
411     *  recoverable error hence @ref QCBOR_ERR_BAD_TAG_CONTENT. Going
412     *  back further, RFC 7049 use the name "optional tags". That name
413     *  is no longer used because "optional" was causing confusion. See
414     *  also @ref QCBOR_ERR_RECOVERABLE_BAD_TAG_CONTENT. */
415    QCBOR_ERR_UNRECOVERABLE_TAG_CONTENT = 48,
416    QCBOR_ERR_BAD_TAG_CONTENT = 48,
417    QCBOR_ERR_BAD_OPT_TAG = 48,
418 
419    /** Indefinite length string handling is disabled and there is an
420     *  indefinite length string in the input CBOR. */
421    QCBOR_ERR_INDEF_LEN_STRINGS_DISABLED = 49,
422 
423    /** Indefinite length arrays and maps handling are disabled and
424     *  there is an indefinite length map or array in the input
425     *  CBOR. */
426    QCBOR_ERR_INDEF_LEN_ARRAYS_DISABLED = 50,
427 
428    /** All decoding of tags (major type 6) has been disabled and a tag
429     *  occurred in the decode input. */
430    QCBOR_ERR_TAGS_DISABLED = 51,
431 
432 #define QCBOR_END_OF_UNRECOVERABLE_DECODE_ERRORS 59
433 
434    /** More than @ref QCBOR_MAX_TAGS_PER_ITEM tags encountered for a
435     *  CBOR ITEM.  @ref QCBOR_MAX_TAGS_PER_ITEM is a limit of this
436     *  implementation.  During decoding, too many tags in the
437     *  caller-configured tag list, or not enough space in
438     *  @ref  QCBORTagListOut. This error makes no further decoding
439     *  possible.  */
440    QCBOR_ERR_TOO_MANY_TAGS = 60,
441 
442    /** When decoding for a specific type, the type was not expected.  */
443    QCBOR_ERR_UNEXPECTED_TYPE = 61,
444 
445    /** Duplicate label detected in a map. */
446    QCBOR_ERR_DUPLICATE_LABEL = 62,
447 
448    /** During decoding, the buffer given to QCBORDecode_SetMemPool()
449     *  is either too small, smaller than
450     *  @ref QCBOR_DECODE_MIN_MEM_POOL_SIZE or too large, larger than
451     *  UINT32_MAX. */
452    QCBOR_ERR_MEM_POOL_SIZE = 63,
453 
454    /** During decoding, an integer smaller than INT64_MIN was received
455     *  (CBOR can represent integers smaller than INT64_MIN, but C
456     *  cannot). */
457    QCBOR_ERR_INT_OVERFLOW = 64,
458 
459    /** During decoding, a date greater than +- 292 billion years from
460     *  Jan 1 1970 encountered during parsing. This is an
461     *  implementation limit. */
462    QCBOR_ERR_DATE_OVERFLOW = 65,
463 
464    /** During decoding, @c QCBORDecode_ExitXxx() was called for a
465     *  different type than @c QCBORDecode_EnterXxx(). */
466    QCBOR_ERR_EXIT_MISMATCH = 66,
467 
468    /** All well-formed data items have been consumed and there are no
469     *  more. If parsing a CBOR stream this indicates the non-error end
470     *  of the stream. If not parsing a CBOR stream/sequence, this
471     *  probably indicates that some data items expected are not
472     *  present.  See also @ref QCBOR_ERR_HIT_END. */
473    QCBOR_ERR_NO_MORE_ITEMS = 67,
474 
475    /** When finding an item by label, an item with the requested label
476     *  was not found. */
477    QCBOR_ERR_LABEL_NOT_FOUND = 68,
478 
479    /** Number conversion failed because of sign. For example a
480     *  negative int64_t can't be converted to a uint64_t */
481    QCBOR_ERR_NUMBER_SIGN_CONVERSION = 69,
482 
483    /** When converting a decoded number, the value is too large or too
484     *  small for the conversion target. */
485    QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW = 70,
486 
487    /** Trying to get an item by label when a map has not been
488     *  entered. */
489    QCBOR_ERR_MAP_NOT_ENTERED = 71,
490 
491    /** A callback indicates processing should not continue for some
492     *  non-CBOR reason. */
493    QCBOR_ERR_CALLBACK_FAIL = 72,
494 
495    /** This error code is deprecated. Instead,
496     *  @ref QCBOR_ERR_HALF_PRECISION_DISABLED,
497     *  @ref QCBOR_ERR_HW_FLOAT_DISABLED or @ref QCBOR_ERR_ALL_FLOAT_DISABLED
498     *  is returned depending on the specific floating-point functionality
499     *  that is disabled and the type of floating-point input. */
500    QCBOR_ERR_FLOAT_DATE_DISABLED = 73,
501 
502    /** Support for half-precision float decoding is disabled. */
503    QCBOR_ERR_HALF_PRECISION_DISABLED = 74,
504 
505    /** Use of floating-point HW is disabled. This affects all type
506     *  conversions to and from double and float types. */
507    QCBOR_ERR_HW_FLOAT_DISABLED = 75,
508 
509    /** Unable to complete operation because a floating-point value
510     *  that is a NaN (not a number), that is too large, too small,
511     *  infinity or -infinity was encountered in encoded CBOR. Usually
512     *  this because conversion of the float-point value was being
513     *  attempted. */
514    QCBOR_ERR_FLOAT_EXCEPTION = 76,
515 
516    /** Floating point support is completely turned off,
517     *  encoding/decoding floating point numbers is not possible. */
518    QCBOR_ERR_ALL_FLOAT_DISABLED = 77,
519 
520    /** Like @ref QCBOR_ERR_UNRECOVERABLE_TAG_CONTENT, but recoverable.
521     * If an implementation decodes a tag and can and does consume the
522     * whole tag contents when it is not the correct tag content, this
523     * error can be returned. None of the built-in tag decoders do this
524     * (to save object code). */
525    QCBOR_ERR_RECOVERABLE_BAD_TAG_CONTENT = 78,
526 
527    /** QCBORDecode_EnterBstrWrapped() cannot be used on
528     * indefinite-length strings because they exist in memory pool for
529     * a @ref QCBORStringAllocate. */
530    QCBOR_ERR_CANNOT_ENTER_ALLOCATED_STRING = 79,
531 
532    /** A range of error codes that can be made use of by the
533     * caller. QCBOR internally does nothing with these except notice
534     * that they are not QCBOR_SUCCESS. See QCBORDecode_SetError(). */
535    QCBOR_ERR_FIRST_USER_DEFINED = 128,
536 
537    /** See \ref QCBOR_ERR_FIRST_USER_DEFINED */
538    QCBOR_ERR_LAST_USER_DEFINED = 255
539 
540    /* This is stored in uint8_t; never add values > 255 */
541 } QCBORError;
542 
543 
544 /**
545  * @brief Get string describing an error code.
546  *
547  * @param[in] uErr   The error code.
548  *
549  * @return  NULL-terminated string describing error or "Unidentified
550  *          error" if the error is not known.
551  *
552  * This is not thread-safe because it uses a static buffer
553  * for formatting, but this is only a diagnostic and the only
554  * consequence is the wrong description.
555  */
556 const char *
557 qcbor_err_to_str(QCBORError uErr);
558 
559 
560 
561 
562 /**
563  * The maximum nesting of arrays and maps when encoding or
564  * decoding. The error @ref QCBOR_ERR_ARRAY_NESTING_TOO_DEEP will be
565  * returned on encoding or @ref QCBOR_ERR_ARRAY_DECODE_NESTING_TOO_DEEP on
566  * decoding if it is exceeded. Do not increase this over 255.
567  */
568 #define QCBOR_MAX_ARRAY_NESTING  15
569 
570 
571 /**
572  * The maximum number of items in a single array or map when encoding or
573  * decoding.
574  */
575 #define QCBOR_MAX_ITEMS_IN_ARRAY (UINT16_MAX-1) /* -1 is because the
576                                                  * value UINT16_MAX is
577                                                  * used to indicate
578                                                  * indefinite-length.
579                                                  */
580 
581 
582 #ifdef __cplusplus
583 }
584 #endif
585 
586 #endif /* qcbor_common_h */
587