QCBOR
Loading...
Searching...
No Matches
qcbor_common.h
Go to the documentation of this file.
1/* ==========================================================================
2 * Copyright (c) 2016-2018, The Linux Foundation.
3 * Copyright (c) 2018-2026, Laurence Lundblade.
4 * Copyright (c) 2021, Arm Limited.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials provided
15 * with the distribution.
16 * * Neither the name of The Linux Foundation nor the names of its
17 * contributors, nor the name "Laurence Lundblade" may be used to
18 * endorse or promote products derived from this software without
19 * specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
31 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * ========================================================================= */
33#ifndef qcbor_common_h
34#define qcbor_common_h
35
36#ifdef __cplusplus
37extern "C" {
38#if 0
39} // Keep editor indention formatting happy
40#endif
41#endif
42
43
50
51
60#define QCBOR_VERSION_MAJOR 1
61#define QCBOR_VERSION_MINOR 6
62#define QCBOR_VERSION_PATCH 1
63
64
71#define STR1(x) #x
72#define STR(x) STR1(x)
73#define QCBOR_VERSION_STRING "libqcbor " STR(QCBOR_VERSION_MAJOR) "." \
74 STR(QCBOR_VERSION_MINOR) "." \
75 STR(QCBOR_VERSION_PATCH)
76
77
87#define QCBOR_SPIFFY_DECODE
88
89
90
91/* Standard CBOR Major type for positive integers of various lengths. */
92#define CBOR_MAJOR_TYPE_POSITIVE_INT 0
93
94/* Standard CBOR Major type for negative integer of various lengths. */
95#define CBOR_MAJOR_TYPE_NEGATIVE_INT 1
96
97/* Standard CBOR Major type for an array of arbitrary 8-bit bytes. */
98#define CBOR_MAJOR_TYPE_BYTE_STRING 2
99
100/* Standard CBOR Major type for a UTF-8 string. Note this is true 8-bit UTF8
101 * with no encoding and no NULL termination. */
102#define CBOR_MAJOR_TYPE_TEXT_STRING 3
103
104/* Standard CBOR Major type for an ordered array of other CBOR data items. */
105#define CBOR_MAJOR_TYPE_ARRAY 4
106
107/* Standard CBOR Major type for CBOR MAP. Maps an array of pairs. The
108 * first item in the pair is the "label" (key, name or identfier) and the second
109 * item is the value. */
110#define CBOR_MAJOR_TYPE_MAP 5
111
112/* Standard CBOR major type for a tag number. This creates a CBOR "tag" that
113 * is the tag number and a data item that follows as the tag content.
114 *
115 * Note that this was called an optional tag in RFC 7049, but there's
116 * not really anything optional about it. It was misleading. It is
117 * renamed in RFC 8949.
118 */
119#define CBOR_MAJOR_TYPE_TAG 6
120#define CBOR_MAJOR_TYPE_OPTIONAL 6
121
122/* Standard CBOR simple types like float, the values true, false, null... */
123#define CBOR_MAJOR_TYPE_SIMPLE 7
124
125
126
127
128/*
129 * Tags that are used with CBOR_MAJOR_TYPE_OPTIONAL. These
130 * are types defined in RFC 8949 and some additional ones
131 * in the IANA CBOR tags registry.
132 */
134#define CBOR_TAG_DATE_STRING 0
136#define CBOR_TAG_DATE_EPOCH 1
138#define CBOR_TAG_POS_BIGNUM 2
140#define CBOR_TAG_NEG_BIGNUM 3
144#define CBOR_TAG_DECIMAL_FRACTION 4
148#define CBOR_TAG_BIGFLOAT 5
153#define CBOR_TAG_COSE_ENCRYPT0 16
154#define CBOR_TAG_COSE_ENCRYPTO 16
159#define CBOR_TAG_COSE_MAC0 17
163#define CBOR_TAG_COSE_SIGN1 18
169#define CBOR_TAG_ENC_AS_B64URL 21
175#define CBOR_TAG_ENC_AS_B64 22
183#define CBOR_TAG_ENC_AS_B16 23
185#define CBOR_TAG_CBOR 24
187#define CBOR_TAG_URI 32
189#define CBOR_TAG_B64URL 33
191#define CBOR_TAG_B64 34
193#define CBOR_TAG_REGEX 35
195#define CBOR_TAG_MIME 36
197#define CBOR_TAG_BIN_UUID 37
201#define CBOR_TAG_CWT 61
205#define CBOR_TAG_CBOR_SEQUENCE 63
209#define CBOR_TAG_COSE_ENCRYPT 96
210#define CBOR_TAG_ENCRYPT 96
214#define CBOR_TAG_COSE_MAC 97
215#define CBOR_TAG_MAC 97
219#define CBOR_TAG_COSE_SIGN 98
220#define CBOR_TAG_SIGN 98
224#define CBOR_TAG_DAYS_EPOCH 100
228#define CBOR_TAG_GEO_COORD 103
230#define CBOR_TAG_BINARY_MIME 257
234#define CBOR_TAG_DAYS_STRING 1004
237#define CBOR_TAG_CBOR_MAGIC 55799
238
240#define CBOR_TAG_INVALID16 0xffff
242#define CBOR_TAG_INVALID32 0xffffffff
244#define CBOR_TAG_INVALID64 0xffffffffffffffffULL
245
246
247
248
265typedef enum {
268
272
276
281
288
292
297
302
307
311
315
316#define QCBOR_START_OF_NOT_WELL_FORMED_ERRORS 20
317
322
327
334
339
344
345#define QCBOR_START_OF_UNRECOVERABLE_DECODE_ERRORS 30
346
352
360
365
366#define QCBOR_END_OF_NOT_WELL_FORMED_ERRORS 39
367
372
380
386
394
399
405
410
416
425 QCBOR_ERR_BAD_TAG_CONTENT = 48,
426 QCBOR_ERR_BAD_OPT_TAG = 48,
427
431
436
440
441#define QCBOR_END_OF_UNRECOVERABLE_DECODE_ERRORS 59
442
450
453
456
462
467
472
476
483
487
491
495
499
503
510
513
517
524
528
535
540
545
548
549 /* This is stored in uint8_t; never add values > 255 */
550} QCBORError;
551
552
565const char *
567
568
569
570
577#define QCBOR_MAX_ARRAY_NESTING 15
578
579
584#define QCBOR_MAX_ITEMS_IN_ARRAY (UINT16_MAX-1) /* -1 is because the
585 * value UINT16_MAX is
586 * used to indicate
587 * indefinite-length.
588 */
593#define QCBOR_MAX_ITEMS_IN_MAP (QCBOR_MAX_ITEMS_IN_ARRAY/2)
594
595
596#ifdef __cplusplus
597}
598#endif
599
600#endif /* qcbor_common_h */
QCBORError
Definition qcbor_common.h:265
@ QCBOR_ERR_DATE_OVERFLOW
Definition qcbor_common.h:471
@ QCBOR_ERR_MAP_NOT_ENTERED
Definition qcbor_common.h:498
@ QCBOR_ERR_BAD_TYPE_7
Definition qcbor_common.h:321
@ QCBOR_ERR_ARRAY_NESTING_TOO_DEEP
Definition qcbor_common.h:287
@ QCBOR_ERR_ARRAY_DECODE_TOO_LONG
Definition qcbor_common.h:385
@ QCBOR_ERR_BUFFER_TOO_LARGE
Definition qcbor_common.h:280
@ QCBOR_ERR_ARRAY_TOO_LONG
Definition qcbor_common.h:296
@ QCBOR_ERR_HALF_PRECISION_DISABLED
Definition qcbor_common.h:512
@ QCBOR_ERR_STRING_TOO_LONG
Definition qcbor_common.h:393
@ QCBOR_ERR_BAD_INT
Definition qcbor_common.h:343
@ QCBOR_ERR_NUMBER_SIGN_CONVERSION
Definition qcbor_common.h:490
@ QCBOR_ERR_BAD_BREAK
Definition qcbor_common.h:364
@ QCBOR_ERR_MEM_POOL_SIZE
Definition qcbor_common.h:461
@ QCBOR_ERR_INDEF_LEN_STRINGS_DISABLED
Definition qcbor_common.h:430
@ QCBOR_ERR_CANNOT_CANCEL
Definition qcbor_common.h:314
@ QCBOR_ERR_CALLBACK_FAIL
Definition qcbor_common.h:502
@ QCBOR_ERR_CLOSE_MISMATCH
Definition qcbor_common.h:291
@ QCBOR_ERR_EXTRA_BYTES
Definition qcbor_common.h:326
@ QCBOR_ERR_ARRAY_OR_MAP_STILL_OPEN
Definition qcbor_common.h:306
@ QCBOR_ERR_OPEN_BYTE_STRING
Definition qcbor_common.h:310
@ QCBOR_ERR_UNRECOVERABLE_TAG_CONTENT
Definition qcbor_common.h:424
@ QCBOR_ERR_NO_STRING_ALLOCATOR
Definition qcbor_common.h:404
@ QCBOR_ERR_LAST_USER_DEFINED
Definition qcbor_common.h:547
@ QCBOR_ERR_NO_MORE_ITEMS
Definition qcbor_common.h:482
@ QCBOR_ERR_INDEF_LEN_ARRAYS_DISABLED
Definition qcbor_common.h:435
@ QCBOR_ERR_ALL_FLOAT_DISABLED
Definition qcbor_common.h:527
@ QCBOR_ERR_TAGS_DISABLED
Definition qcbor_common.h:439
@ QCBOR_ERR_MAP_LABEL_TYPE
Definition qcbor_common.h:415
@ QCBOR_ERR_UNSUPPORTED
Definition qcbor_common.h:333
@ QCBOR_ERR_LABEL_NOT_FOUND
Definition qcbor_common.h:486
@ QCBOR_ERR_FLOAT_EXCEPTION
Definition qcbor_common.h:523
@ QCBOR_ERR_INDEFINITE_STRING_CHUNK
Definition qcbor_common.h:351
@ QCBOR_ERR_EXIT_MISMATCH
Definition qcbor_common.h:475
@ QCBOR_ERR_HW_FLOAT_DISABLED
Definition qcbor_common.h:516
@ QCBOR_ERR_UNEXPECTED_TYPE
Definition qcbor_common.h:452
@ QCBOR_ERR_RECOVERABLE_BAD_TAG_CONTENT
Definition qcbor_common.h:534
@ QCBOR_ERR_ENCODE_UNSUPPORTED
Definition qcbor_common.h:275
@ QCBOR_ERR_INT_OVERFLOW
Definition qcbor_common.h:466
@ QCBOR_ERR_TOO_MANY_CLOSES
Definition qcbor_common.h:301
@ QCBOR_ERR_DUPLICATE_LABEL
Definition qcbor_common.h:455
@ QCBOR_ERR_STRING_ALLOCATE
Definition qcbor_common.h:409
@ QCBOR_ERR_BAD_EXP_AND_MANTISSA
Definition qcbor_common.h:398
@ QCBOR_ERR_TOO_MANY_TAGS
Definition qcbor_common.h:449
@ QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW
Definition qcbor_common.h:494
@ QCBOR_ERR_FLOAT_DATE_DISABLED
Definition qcbor_common.h:509
@ QCBOR_ERR_ARRAY_OR_MAP_UNCONSUMED
Definition qcbor_common.h:338
@ QCBOR_ERR_BUFFER_TOO_SMALL
Definition qcbor_common.h:271
@ QCBOR_ERR_CANNOT_ENTER_ALLOCATED_STRING
Definition qcbor_common.h:539
@ QCBOR_ERR_ARRAY_DECODE_NESTING_TOO_DEEP
Definition qcbor_common.h:379
@ QCBOR_ERR_FIRST_USER_DEFINED
Definition qcbor_common.h:544
@ QCBOR_SUCCESS
Definition qcbor_common.h:267
@ QCBOR_ERR_HIT_END
Definition qcbor_common.h:359
@ QCBOR_ERR_INPUT_TOO_LARGE
Definition qcbor_common.h:371
const char * qcbor_err_to_str(QCBORError uErr)
Get string describing an error code.