Wirepas SDK
cbor.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2017 Intel Corporation
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 **
12 ** The above copyright notice and this permission notice shall be included in
13 ** all copies or substantial portions of the Software.
14 **
15 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 ** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 ** THE SOFTWARE.
22 **
23 ****************************************************************************/
24 
25 #ifndef CBOR_H
26 #define CBOR_H
27 
28 #ifndef assert
29 #include <assert.h>
30 #endif
31 #include <limits.h>
32 #include <stddef.h>
33 #include <stdint.h>
34 #include <string.h>
35 #include <stdio.h>
36 
37 #include "tinycbor-version.h"
38 
39 #define TINYCBOR_VERSION ((TINYCBOR_VERSION_MAJOR << 16) | (TINYCBOR_VERSION_MINOR << 8) | TINYCBOR_VERSION_PATCH)
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #else
44 #include <stdbool.h>
45 #endif
46 
47 #ifndef SIZE_MAX
48 /* Some systems fail to define SIZE_MAX in <stdint.h>, even though C99 requires it...
49  * Conversion from signed to unsigned is defined in 6.3.1.3 (Signed and unsigned integers) p2,
50  * which says: "the value is converted by repeatedly adding or subtracting one more than the
51  * maximum value that can be represented in the new type until the value is in the range of the
52  * new type."
53  * So -1 gets converted to size_t by adding SIZE_MAX + 1, which results in SIZE_MAX.
54  */
55 # define SIZE_MAX ((size_t)-1)
56 #endif
57 
58 #ifndef CBOR_API
59 # define CBOR_API
60 #endif
61 #ifndef CBOR_PRIVATE_API
62 # define CBOR_PRIVATE_API
63 #endif
64 #ifndef CBOR_INLINE_API
65 # if defined(__cplusplus)
66 # define CBOR_INLINE inline
67 # define CBOR_INLINE_API inline
68 # else
69 # define CBOR_INLINE_API static CBOR_INLINE
70 # if defined(_MSC_VER)
71 # define CBOR_INLINE __inline
72 # elif defined(__GNUC__)
73 # define CBOR_INLINE __inline__
74 # elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
75 # define CBOR_INLINE inline
76 # else
77 # define CBOR_INLINE
78 # endif
79 # endif
80 #endif
81 
82 typedef enum CborType {
86  CborArrayType = 0x80,
87  CborMapType = 0xa0,
88  CborTagType = 0xc0,
91  CborNullType = 0xf6,
94  CborFloatType = 0xfa,
96 
97  CborInvalidType = 0xff /* equivalent to the break byte, so it will never be used */
98 } CborType;
99 
100 typedef uint64_t CborTag;
101 typedef enum CborKnownTags {
124 } CborKnownTags;
125 
126 /* #define the constants so we can check with #ifdef */
127 #define CborDateTimeStringTag CborDateTimeStringTag
128 #define CborUnixTime_tTag CborUnixTime_tTag
129 #define CborPositiveBignumTag CborPositiveBignumTag
130 #define CborNegativeBignumTag CborNegativeBignumTag
131 #define CborDecimalTag CborDecimalTag
132 #define CborBigfloatTag CborBigfloatTag
133 #define CborCOSE_Encrypt0Tag CborCOSE_Encrypt0Tag
134 #define CborCOSE_Mac0Tag CborCOSE_Mac0Tag
135 #define CborCOSE_Sign1Tag CborCOSE_Sign1Tag
136 #define CborExpectedBase64urlTag CborExpectedBase64urlTag
137 #define CborExpectedBase64Tag CborExpectedBase64Tag
138 #define CborExpectedBase16Tag CborExpectedBase16Tag
139 #define CborEncodedCborTag CborEncodedCborTag
140 #define CborUrlTag CborUrlTag
141 #define CborBase64urlTag CborBase64urlTag
142 #define CborBase64Tag CborBase64Tag
143 #define CborRegularExpressionTag CborRegularExpressionTag
144 #define CborMimeMessageTag CborMimeMessageTag
145 #define CborCOSE_EncryptTag CborCOSE_EncryptTag
146 #define CborCOSE_MacTag CborCOSE_MacTag
147 #define CborCOSE_SignTag CborCOSE_SignTag
148 #define CborSignatureTag CborSignatureTag
149 
150 /* Error API */
151 
152 typedef enum CborError {
154 
155  /* errors in all modes */
157  CborErrorUnknownLength, /* request for length in array, map, or string with indeterminate length */
160 
161  /* parser errors streaming errors */
165  CborErrorUnknownType, /* can only happen in major type 7 */
166  CborErrorIllegalType, /* type not allowed here */
168  CborErrorIllegalSimpleType, /* types of value less than 32 encoded in two bytes */
169 
170  /* parser errors in strict mode parsing only */
183 
184  /* encoder errors */
187 
188  /* internal implementation errors */
192 
193  /* errors in converting to JSON */
197 
198  CborErrorOutOfMemory = (int) (~0U / 2 + 1),
199  CborErrorInternalError = (int) (~0U / 2) /* INT_MAX on two's complement machines */
200 } CborError;
201 
202 CBOR_API const char *cbor_error_string(CborError error);
203 
204 /* Encoder API */
206 {
207  union {
208  uint8_t *ptr;
209  ptrdiff_t bytes_needed;
210  } data;
211  const uint8_t *end;
212  size_t remaining;
213  int flags;
214 };
215 typedef struct CborEncoder CborEncoder;
216 
217 static const size_t CborIndefiniteLength = SIZE_MAX;
218 
219 CBOR_API void cbor_encoder_init(CborEncoder *encoder, uint8_t *buffer, size_t size, int flags);
220 CBOR_API CborError cbor_encode_uint(CborEncoder *encoder, uint64_t value);
221 CBOR_API CborError cbor_encode_int(CborEncoder *encoder, int64_t value);
222 CBOR_API CborError cbor_encode_negative_int(CborEncoder *encoder, uint64_t absolute_value);
223 CBOR_API CborError cbor_encode_simple_value(CborEncoder *encoder, uint8_t value);
224 CBOR_API CborError cbor_encode_tag(CborEncoder *encoder, CborTag tag);
225 CBOR_API CborError cbor_encode_text_string(CborEncoder *encoder, const char *string, size_t length);
227 { return cbor_encode_text_string(encoder, string, strlen(string)); }
228 CBOR_API CborError cbor_encode_byte_string(CborEncoder *encoder, const uint8_t *string, size_t length);
229 CBOR_API CborError cbor_encode_floating_point(CborEncoder *encoder, CborType fpType, const void *value);
230 
232 { return cbor_encode_simple_value(encoder, (int)value - 1 + (CborBooleanType & 0x1f)); }
234 { return cbor_encode_simple_value(encoder, CborNullType & 0x1f); }
236 { return cbor_encode_simple_value(encoder, CborUndefinedType & 0x1f); }
237 
239 { return cbor_encode_floating_point(encoder, CborHalfFloatType, value); }
241 { return cbor_encode_floating_point(encoder, CborFloatType, &value); }
243 { return cbor_encode_floating_point(encoder, CborDoubleType, &value); }
244 
245 CBOR_API CborError cbor_encoder_create_array(CborEncoder *encoder, CborEncoder *arrayEncoder, size_t length);
246 CBOR_API CborError cbor_encoder_create_map(CborEncoder *encoder, CborEncoder *mapEncoder, size_t length);
247 CBOR_API CborError cbor_encoder_close_container(CborEncoder *encoder, const CborEncoder *containerEncoder);
248 CBOR_API CborError cbor_encoder_close_container_checked(CborEncoder *encoder, const CborEncoder *containerEncoder);
249 
251 {
252  return encoder->data.ptr;
253 }
254 
255 CBOR_INLINE_API size_t cbor_encoder_get_buffer_size(const CborEncoder *encoder, const uint8_t *buffer)
256 {
257  return (size_t)(encoder->data.ptr - buffer);
258 }
259 
261 {
262  return encoder->end ? 0 : (size_t)encoder->data.bytes_needed;
263 }
264 
265 /* Parser API */
266 
268 {
274 };
275 
277 {
278  const uint8_t *end;
279  uint32_t flags;
280 };
281 typedef struct CborParser CborParser;
282 
283 struct CborValue
284 {
286  const uint8_t *ptr;
287  uint32_t remaining;
288  uint16_t extra;
289  uint8_t type;
290  uint8_t flags;
291 };
292 typedef struct CborValue CborValue;
293 
294 CBOR_API CborError cbor_parser_init(const uint8_t *buffer, size_t size, uint32_t flags, CborParser *parser, CborValue *it);
295 
296 CBOR_API CborError cbor_value_validate_basic(const CborValue *it);
297 
299 { return it->remaining == 0; }
301 { return it->ptr; }
305 { return it->type == CborArrayType || it->type == CborMapType; }
306 CBOR_API CborError cbor_value_enter_container(const CborValue *it, CborValue *recursed);
307 CBOR_API CborError cbor_value_leave_container(CborValue *it, const CborValue *recursed);
308 
311 {
314 }
315 
317 { return value && value->type != CborInvalidType; }
319 { return (CborType)value->type; }
320 
321 /* Null & undefined type */
323 { return value->type == CborNullType; }
325 { return value->type == CborUndefinedType; }
326 
327 /* Booleans */
329 { return value->type == CborBooleanType; }
331 {
332  assert(cbor_value_is_boolean(value));
333  *result = !!value->extra;
334  return CborNoError;
335 }
336 
337 /* Simple types */
339 { return value->type == CborSimpleType; }
341 {
342  assert(cbor_value_is_simple_type(value));
343  *result = (uint8_t)value->extra;
344  return CborNoError;
345 }
346 
347 /* Integers */
349 { return value->type == CborIntegerType; }
351 { return cbor_value_is_integer(value) && (value->flags & CborIteratorFlag_NegativeInteger) == 0; }
353 { return cbor_value_is_integer(value) && (value->flags & CborIteratorFlag_NegativeInteger); }
354 
356 {
357  assert(cbor_value_is_integer(value));
358  *result = _cbor_value_extract_int64_helper(value);
359  return CborNoError;
360 }
361 
363 {
364  assert(cbor_value_is_unsigned_integer(value));
365  *result = _cbor_value_extract_int64_helper(value);
366  return CborNoError;
367 }
368 
370 {
371  assert(cbor_value_is_integer(value));
372  *result = (int64_t) _cbor_value_extract_int64_helper(value);
374  *result = -*result - 1;
375  return CborNoError;
376 }
377 
379 {
380  assert(cbor_value_is_integer(value));
381  *result = (int) _cbor_value_extract_int64_helper(value);
383  *result = -*result - 1;
384  return CborNoError;
385 }
386 
387 CBOR_API CborError cbor_value_get_int64_checked(const CborValue *value, int64_t *result);
388 CBOR_API CborError cbor_value_get_int_checked(const CborValue *value, int *result);
389 
391 { return (value->flags & CborIteratorFlag_UnknownLength) == 0; }
392 
393 /* Tags */
395 { return value->type == CborTagType; }
397 {
398  assert(cbor_value_is_tag(value));
399  *result = _cbor_value_extract_int64_helper(value);
400  return CborNoError;
401 }
403 
404 /* Strings */
406 { return value->type == CborByteStringType; }
408 { return value->type == CborTextStringType; }
409 
411 {
412  uint64_t v;
413  assert(cbor_value_is_byte_string(value) || cbor_value_is_text_string(value));
414  if (!cbor_value_is_length_known(value))
415  return CborErrorUnknownLength;
417  *length = (size_t)v;
418  if (*length != v)
419  return CborErrorDataTooLarge;
420  return CborNoError;
421 }
422 
424  size_t *buflen, CborValue *next);
425 CBOR_PRIVATE_API CborError _cbor_value_dup_string(const CborValue *value, void **buffer,
426  size_t *buflen, CborValue *next);
427 
428 CBOR_API CborError cbor_value_calculate_string_length(const CborValue *value, size_t *length);
429 
431  size_t *buflen, CborValue *next)
432 {
433  assert(cbor_value_is_text_string(value));
434  return _cbor_value_copy_string(value, buffer, buflen, next);
435 }
437  size_t *buflen, CborValue *next)
438 {
439  assert(cbor_value_is_byte_string(value));
440  return _cbor_value_copy_string(value, buffer, buflen, next);
441 }
442 
444  size_t *buflen, CborValue *next)
445 {
446  assert(cbor_value_is_text_string(value));
447  return _cbor_value_dup_string(value, (void **)buffer, buflen, next);
448 }
450  size_t *buflen, CborValue *next)
451 {
452  assert(cbor_value_is_byte_string(value));
453  return _cbor_value_dup_string(value, (void **)buffer, buflen, next);
454 }
455 
456 CBOR_API CborError cbor_value_text_string_equals(const CborValue *value, const char *string, bool *result);
457 
458 /* Maps and arrays */
460 { return value->type == CborArrayType; }
462 { return value->type == CborMapType; }
463 
465 {
466  uint64_t v;
467  assert(cbor_value_is_array(value));
468  if (!cbor_value_is_length_known(value))
469  return CborErrorUnknownLength;
471  *length = (size_t)v;
472  if (*length != v)
473  return CborErrorDataTooLarge;
474  return CborNoError;
475 }
476 
478 {
479  uint64_t v;
480  assert(cbor_value_is_map(value));
481  if (!cbor_value_is_length_known(value))
482  return CborErrorUnknownLength;
484  *length = (size_t)v;
485  if (*length != v)
486  return CborErrorDataTooLarge;
487  return CborNoError;
488 }
489 
490 CBOR_API CborError cbor_value_map_find_value(const CborValue *map, const char *string, CborValue *element);
491 
492 /* Floating point */
494 { return value->type == CborHalfFloatType; }
495 CBOR_API CborError cbor_value_get_half_float(const CborValue *value, void *result);
496 
498 { return value->type == CborFloatType; }
500 {
501  uint32_t data;
502  assert(cbor_value_is_float(value));
504  data = (uint32_t)_cbor_value_decode_int64_internal(value);
505  memcpy(result, &data, sizeof(*result));
506  return CborNoError;
507 }
508 
510 { return value->type == CborDoubleType; }
512 {
513  uint64_t data;
514  assert(cbor_value_is_double(value));
516  data = _cbor_value_decode_int64_internal(value);
517  memcpy(result, &data, sizeof(*result));
518  return CborNoError;
519 }
520 
521 /* Validation API */
522 
524  /* Bit mapping:
525  * bits 0-7 (8 bits): canonical format
526  * bits 8-11 (4 bits): canonical format & strict mode
527  * bits 12-20 (8 bits): strict mode
528  * bits 21-31 (10 bits): other
529  */
530 
536 
538 
542 
544 
547  CborValidateNoTags = 0x400000,
549  /* unused = 0x1000000, */
550  /* unused = 0x2000000, */
551 
557 
558  CborValidateCompleteData = (int)0x80000000,
559 
562 };
563 
564 CBOR_API CborError cbor_value_validate(const CborValue *it, uint32_t flags);
565 
566 /* Human-readable (dump) API */
567 
571 
575 
578 
580 };
581 
582 typedef CborError (*CborStreamFunction)(void *token, const char *fmt, ...)
583 #ifdef __GNUC__
584  __attribute__((__format__(printf, 2, 3)))
585 #endif
586 ;
587 
588 CBOR_API CborError cbor_value_to_pretty_stream(CborStreamFunction streamFunction, void *token, CborValue *value, int flags);
589 
590 /* The following API requires a hosted C implementation (uses FILE*) */
591 #if !defined(__STDC_HOSTED__) || __STDC_HOSTED__-0 == 1
592 CBOR_API CborError cbor_value_to_pretty_advance_flags(FILE *out, CborValue *value, int flags);
593 CBOR_API CborError cbor_value_to_pretty_advance(FILE *out, CborValue *value);
595 {
596  CborValue copy = *value;
598 }
599 #endif /* __STDC_HOSTED__ check */
600 
601 #ifdef __cplusplus
602 }
603 #endif
604 
605 #endif /* CBOR_H */
606 
CborErrorOverlongEncoding
@ CborErrorOverlongEncoding
Definition: cbor.h:179
cbor_value_get_type
static CborType cbor_value_get_type(const CborValue *value)
Definition: cbor.h:318
cbor_value_is_double
static bool cbor_value_is_double(const CborValue *value)
Definition: cbor.h:509
CborExpectedBase64urlTag
#define CborExpectedBase64urlTag
Definition: cbor.h:136
CborIntegerType
@ CborIntegerType
Definition: cbor.h:83
CborCOSE_EncryptTag
#define CborCOSE_EncryptTag
Definition: cbor.h:145
CborErrorUnknownType
@ CborErrorUnknownType
Definition: cbor.h:165
cbor_value_is_boolean
static bool cbor_value_is_boolean(const CborValue *value)
Definition: cbor.h:328
CborErrorExcludedValue
@ CborErrorExcludedValue
Definition: cbor.h:177
CborPrettyIndicateIndeterminateLength
@ CborPrettyIndicateIndeterminateLength
Definition: cbor.h:572
cbor_encode_float
static CborError cbor_encode_float(CborEncoder *encoder, float value)
Definition: cbor.h:240
CborErrorImproperValue
@ CborErrorImproperValue
Definition: cbor.h:178
CborValidateNoUnknownSimpleTypes
@ CborValidateNoUnknownSimpleTypes
Definition: cbor.h:553
CborPrettyIndicateOverlongNumbers
@ CborPrettyIndicateOverlongNumbers
Definition: cbor.h:574
cbor_value_get_array_length
static CborError cbor_value_get_array_length(const CborValue *value, size_t *length)
Definition: cbor.h:464
cbor_encode_double
static CborError cbor_encode_double(CborEncoder *encoder, double value)
Definition: cbor.h:242
CborDecimalTag
#define CborDecimalTag
Definition: cbor.h:131
CborValidateUtf8
@ CborValidateUtf8
Definition: cbor.h:541
cbor_value_is_unsigned_integer
static bool cbor_value_is_unsigned_integer(const CborValue *value)
Definition: cbor.h:350
CborIteratorFlag_UnknownLength
@ CborIteratorFlag_UnknownLength
Definition: cbor.h:272
CborErrorInappropriateTagForType
@ CborErrorInappropriateTagForType
Definition: cbor.h:173
cbor_encode_undefined
static CborError cbor_encode_undefined(CborEncoder *encoder)
Definition: cbor.h:235
CborMimeMessageTag
#define CborMimeMessageTag
Definition: cbor.h:144
CborValidateShortestIntegrals
@ CborValidateShortestIntegrals
Definition: cbor.h:531
CborErrorUnknownSimpleType
@ CborErrorUnknownSimpleType
Definition: cbor.h:171
CborCOSE_Mac0Tag
#define CborCOSE_Mac0Tag
Definition: cbor.h:134
CborValidateNoIndeterminateLength
@ CborValidateNoIndeterminateLength
Definition: cbor.h:534
CborErrorIO
@ CborErrorIO
Definition: cbor.h:159
CborEncoder::flags
int flags
Definition: cbor.h:213
cbor_encode_floating_point
CBOR_API CborError cbor_encode_floating_point(CborEncoder *encoder, CborType fpType, const void *value)
cbor_value_to_pretty
static CborError cbor_value_to_pretty(FILE *out, const CborValue *value)
Definition: cbor.h:594
CborValue
Definition: cbor.h:283
cbor_encoder_get_buffer_size
static size_t cbor_encoder_get_buffer_size(const CborEncoder *encoder, const uint8_t *buffer)
Definition: cbor.h:255
cbor_value_to_pretty_advance_flags
CBOR_API CborError cbor_value_to_pretty_advance_flags(FILE *out, CborValue *value, int flags)
CborValidateMapIsSorted
@ CborValidateMapIsSorted
Definition: cbor.h:535
cbor_value_is_simple_type
static bool cbor_value_is_simple_type(const CborValue *value)
Definition: cbor.h:338
CborTag
uint64_t CborTag
Definition: cbor.h:100
_cbor_value_decode_int64_internal
uint64_t _cbor_value_decode_int64_internal(const CborValue *value)
CborErrorMapNotSorted
@ CborErrorMapNotSorted
Definition: cbor.h:181
CborValidateMapKeysAreUnique
@ CborValidateMapKeysAreUnique
Definition: cbor.h:539
CborErrorUnknownLength
@ CborErrorUnknownLength
Definition: cbor.h:157
cbor_value_validate
CBOR_API CborError cbor_value_validate(const CborValue *it, uint32_t flags)
cbor_value_calculate_string_length
CBOR_API CborError cbor_value_calculate_string_length(const CborValue *value, size_t *length)
CborUnixTime_tTag
#define CborUnixTime_tTag
Definition: cbor.h:128
CborParser::flags
uint32_t flags
Definition: cbor.h:279
cbor_value_is_valid
static bool cbor_value_is_valid(const CborValue *value)
Definition: cbor.h:316
CborErrorDataTooLarge
@ CborErrorDataTooLarge
Definition: cbor.h:189
CborUrlTag
#define CborUrlTag
Definition: cbor.h:140
CborNoError
@ CborNoError
Definition: cbor.h:153
cbor_value_get_raw_integer
static CborError cbor_value_get_raw_integer(const CborValue *value, uint64_t *result)
Definition: cbor.h:355
CborErrorJsonNotImplemented
@ CborErrorJsonNotImplemented
Definition: cbor.h:196
cbor_value_skip_tag
CBOR_API CborError cbor_value_skip_tag(CborValue *it)
cbor_encode_byte_string
CBOR_API CborError cbor_encode_byte_string(CborEncoder *encoder, const uint8_t *string, size_t length)
CborIteratorFlag_NegativeInteger
@ CborIteratorFlag_NegativeInteger
Definition: cbor.h:270
CborPositiveBignumTag
#define CborPositiveBignumTag
Definition: cbor.h:129
CborEncoder::remaining
size_t remaining
Definition: cbor.h:212
cbor_value_get_simple_type
static CborError cbor_value_get_simple_type(const CborValue *value, uint8_t *result)
Definition: cbor.h:340
CborValidateTagUse
@ CborValidateTagUse
Definition: cbor.h:540
tinycbor-version.h
cbor_encode_half_float
static CborError cbor_encode_half_float(CborEncoder *encoder, const void *value)
Definition: cbor.h:238
cbor_encode_int
CBOR_API CborError cbor_encode_int(CborEncoder *encoder, int64_t value)
cbor_value_is_undefined
static bool cbor_value_is_undefined(const CborValue *value)
Definition: cbor.h:324
cbor_value_to_pretty_advance
CBOR_API CborError cbor_value_to_pretty_advance(FILE *out, CborValue *value)
CborValidateMapKeysAreString
@ CborValidateMapKeysAreString
Definition: cbor.h:545
_cbor_value_copy_string
CborError _cbor_value_copy_string(const CborValue *value, void *buffer, size_t *buflen, CborValue *next)
CborErrorJsonObjectKeyIsAggregate
@ CborErrorJsonObjectKeyIsAggregate
Definition: cbor.h:194
CborValidateCompleteData
@ CborValidateCompleteData
Definition: cbor.h:558
CborBigfloatTag
#define CborBigfloatTag
Definition: cbor.h:132
CborErrorInternalError
@ CborErrorInternalError
Definition: cbor.h:199
CborDateTimeStringTag
#define CborDateTimeStringTag
Definition: cbor.h:127
cbor_value_get_int64
static CborError cbor_value_get_int64(const CborValue *value, int64_t *result)
Definition: cbor.h:369
CborValidateStrictMode
@ CborValidateStrictMode
Definition: cbor.h:543
cbor_value_to_pretty_stream
CBOR_API CborError cbor_value_to_pretty_stream(CborStreamFunction streamFunction, void *token, CborValue *value, int flags)
cbor_value_get_double
static CborError cbor_value_get_double(const CborValue *value, double *result)
Definition: cbor.h:511
cbor_value_is_container
static bool cbor_value_is_container(const CborValue *it)
Definition: cbor.h:304
cbor_value_text_string_equals
CBOR_API CborError cbor_value_text_string_equals(const CborValue *value, const char *string, bool *result)
CborValidateNoUnknownTags
@ CborValidateNoUnknownTags
Definition: cbor.h:556
cbor_value_enter_container
CBOR_API CborError cbor_value_enter_container(const CborValue *it, CborValue *recursed)
CborEncodedCborTag
#define CborEncodedCborTag
Definition: cbor.h:139
CborErrorTooManyItems
@ CborErrorTooManyItems
Definition: cbor.h:185
CborPrettyMergeStringFragments
@ CborPrettyMergeStringFragments
Definition: cbor.h:577
CborArrayType
@ CborArrayType
Definition: cbor.h:86
CborPrettyIndicateIndetermineLength
@ CborPrettyIndicateIndetermineLength
Definition: cbor.h:573
CborValue::remaining
uint32_t remaining
Definition: cbor.h:287
cbor_value_copy_byte_string
static CborError cbor_value_copy_byte_string(const CborValue *value, uint8_t *buffer, size_t *buflen, CborValue *next)
Definition: cbor.h:436
cbor_value_is_map
static bool cbor_value_is_map(const CborValue *value)
Definition: cbor.h:461
cbor_value_get_map_length
static CborError cbor_value_get_map_length(const CborValue *value, size_t *length)
Definition: cbor.h:477
CborValidateNoUnknownSimpleTypesSA
@ CborValidateNoUnknownSimpleTypesSA
Definition: cbor.h:552
CborError
CborError
Definition: cbor.h:152
cbor_parser_init
CBOR_API CborError cbor_parser_init(const uint8_t *buffer, size_t size, uint32_t flags, CborParser *parser, CborValue *it)
cbor_encoder_close_container_checked
CBOR_API CborError cbor_encoder_close_container_checked(CborEncoder *encoder, const CborEncoder *containerEncoder)
SIZE_MAX
#define SIZE_MAX
Definition: cbor.h:55
CborNegativeBignumTag
#define CborNegativeBignumTag
Definition: cbor.h:130
CborSignatureTag
#define CborSignatureTag
Definition: cbor.h:148
CborErrorUnexpectedBreak
@ CborErrorUnexpectedBreak
Definition: cbor.h:164
CborErrorIllegalNumber
@ CborErrorIllegalNumber
Definition: cbor.h:167
cbor_value_advance_fixed
CBOR_API CborError cbor_value_advance_fixed(CborValue *it)
cbor_value_dup_text_string
static CborError cbor_value_dup_text_string(const CborValue *value, char **buffer, size_t *buflen, CborValue *next)
Definition: cbor.h:443
CborBooleanType
@ CborBooleanType
Definition: cbor.h:90
cbor_encoder_get_extra_bytes_needed
static size_t cbor_encoder_get_extra_bytes_needed(const CborEncoder *encoder)
Definition: cbor.h:260
CborErrorMapKeysNotUnique
@ CborErrorMapKeysNotUnique
Definition: cbor.h:182
cbor_encoder_init
CBOR_API void cbor_encoder_init(CborEncoder *encoder, uint8_t *buffer, size_t size, int flags)
cbor_value_is_array
static bool cbor_value_is_array(const CborValue *value)
Definition: cbor.h:459
cbor_value_dup_byte_string
static CborError cbor_value_dup_byte_string(const CborValue *value, uint8_t **buffer, size_t *buflen, CborValue *next)
Definition: cbor.h:449
cbor_value_get_boolean
static CborError cbor_value_get_boolean(const CborValue *value, bool *result)
Definition: cbor.h:330
CborParser
Definition: cbor.h:276
_cbor_encoder_get_buffer_pointer
static uint8_t * _cbor_encoder_get_buffer_pointer(const CborEncoder *encoder)
Definition: cbor.h:250
CborType
CborType
Definition: cbor.h:82
cbor_value_get_half_float
CBOR_API CborError cbor_value_get_half_float(const CborValue *value, void *result)
cbor_value_is_byte_string
static bool cbor_value_is_byte_string(const CborValue *value)
Definition: cbor.h:405
CborPrettyDefaultFlags
@ CborPrettyDefaultFlags
Definition: cbor.h:579
cbor_value_is_negative_integer
static bool cbor_value_is_negative_integer(const CborValue *value)
Definition: cbor.h:352
CborValidateShortestFloatingPoint
@ CborValidateShortestFloatingPoint
Definition: cbor.h:532
CborByteStringType
@ CborByteStringType
Definition: cbor.h:84
CborIteratorFlag_IteratingStringChunks
@ CborIteratorFlag_IteratingStringChunks
Definition: cbor.h:271
cbor_value_is_integer
static bool cbor_value_is_integer(const CborValue *value)
Definition: cbor.h:348
CborBase64urlTag
#define CborBase64urlTag
Definition: cbor.h:141
cbor_value_get_float
static CborError cbor_value_get_float(const CborValue *value, float *result)
Definition: cbor.h:499
CborStreamFunction
CborError(* CborStreamFunction)(void *token, const char *fmt,...)
Definition: cbor.h:582
CborValidationFlags
CborValidationFlags
Definition: cbor.h:523
CborEncoder
Definition: cbor.h:205
CborErrorNestingTooDeep
@ CborErrorNestingTooDeep
Definition: cbor.h:190
CborErrorDuplicateObjectKeys
@ CborErrorDuplicateObjectKeys
Definition: cbor.h:174
CborValue::ptr
const uint8_t * ptr
Definition: cbor.h:286
CborSimpleType
@ CborSimpleType
Definition: cbor.h:89
cbor_encode_boolean
static CborError cbor_encode_boolean(CborEncoder *encoder, bool value)
Definition: cbor.h:231
CBOR_PRIVATE_API
#define CBOR_PRIVATE_API
Definition: cbor.h:62
CborErrorTooFewItems
@ CborErrorTooFewItems
Definition: cbor.h:186
CborValidateStrictest
@ CborValidateStrictest
Definition: cbor.h:560
CborCOSE_MacTag
#define CborCOSE_MacTag
Definition: cbor.h:146
CborValue::parser
const CborParser * parser
Definition: cbor.h:285
CborErrorExcludedType
@ CborErrorExcludedType
Definition: cbor.h:176
CborErrorGarbageAtEnd
@ CborErrorGarbageAtEnd
Definition: cbor.h:162
cbor_value_get_next_byte
static const uint8_t * cbor_value_get_next_byte(const CborValue *it)
Definition: cbor.h:300
cbor_value_advance
CBOR_API CborError cbor_value_advance(CborValue *it)
CborErrorIllegalType
@ CborErrorIllegalType
Definition: cbor.h:166
CborValidateNoUnknownTagsSA
@ CborValidateNoUnknownTagsSA
Definition: cbor.h:554
cbor_encode_null
static CborError cbor_encode_null(CborEncoder *encoder)
Definition: cbor.h:233
CborIteratorFlag_ContainerIsMap
@ CborIteratorFlag_ContainerIsMap
Definition: cbor.h:273
CborPrettyTextualEncodingIndicators
@ CborPrettyTextualEncodingIndicators
Definition: cbor.h:570
_cbor_value_extract_int64_helper
static uint64_t _cbor_value_extract_int64_helper(const CborValue *value)
Definition: cbor.h:310
CborNullType
@ CborNullType
Definition: cbor.h:91
cbor_encode_simple_value
CBOR_API CborError cbor_encode_simple_value(CborEncoder *encoder, uint8_t value)
CborPrettyShowStringFragments
@ CborPrettyShowStringFragments
Definition: cbor.h:576
cbor_value_is_tag
static bool cbor_value_is_tag(const CborValue *value)
Definition: cbor.h:394
CborPrettyFlags
CborPrettyFlags
Definition: cbor.h:568
CborKnownTags
CborKnownTags
Definition: cbor.h:101
cbor_encode_uint
CBOR_API CborError cbor_encode_uint(CborEncoder *encoder, uint64_t value)
cbor_value_leave_container
CBOR_API CborError cbor_value_leave_container(CborValue *it, const CborValue *recursed)
cbor_error_string
const CBOR_API char * cbor_error_string(CborError error)
CborCOSE_SignTag
#define CborCOSE_SignTag
Definition: cbor.h:147
CborValue::flags
uint8_t flags
Definition: cbor.h:290
CBOR_INLINE_API
#define CBOR_INLINE_API
Definition: cbor.h:69
CborErrorInvalidUtf8TextString
@ CborErrorInvalidUtf8TextString
Definition: cbor.h:175
CborValidateNoUndefined
@ CborValidateNoUndefined
Definition: cbor.h:546
cbor_value_copy_text_string
static CborError cbor_value_copy_text_string(const CborValue *value, char *buffer, size_t *buflen, CborValue *next)
Definition: cbor.h:430
CborErrorJsonObjectKeyNotString
@ CborErrorJsonObjectKeyNotString
Definition: cbor.h:195
CborUnknownError
@ CborUnknownError
Definition: cbor.h:156
CborFloatType
@ CborFloatType
Definition: cbor.h:94
CborValidateShortestNumbers
@ CborValidateShortestNumbers
Definition: cbor.h:533
CborValue::type
uint8_t type
Definition: cbor.h:289
CborValidateCanonicalFormat
@ CborValidateCanonicalFormat
Definition: cbor.h:537
CborErrorIllegalSimpleType
@ CborErrorIllegalSimpleType
Definition: cbor.h:168
CborValidateNoTags
@ CborValidateNoTags
Definition: cbor.h:547
cbor_encode_tag
CBOR_API CborError cbor_encode_tag(CborEncoder *encoder, CborTag tag)
CborErrorAdvancePastEOF
@ CborErrorAdvancePastEOF
Definition: cbor.h:158
cbor_value_is_half_float
static bool cbor_value_is_half_float(const CborValue *value)
Definition: cbor.h:493
CborExpectedBase16Tag
#define CborExpectedBase16Tag
Definition: cbor.h:138
CborErrorUnknownTag
@ CborErrorUnknownTag
Definition: cbor.h:172
CborErrorMapKeyNotString
@ CborErrorMapKeyNotString
Definition: cbor.h:180
CborErrorOutOfMemory
@ CborErrorOutOfMemory
Definition: cbor.h:198
CborParserIteratorFlags
CborParserIteratorFlags
Definition: cbor.h:267
CborBase64Tag
#define CborBase64Tag
Definition: cbor.h:142
cbor_value_get_int_checked
CBOR_API CborError cbor_value_get_int_checked(const CborValue *value, int *result)
CborErrorUnexpectedEOF
@ CborErrorUnexpectedEOF
Definition: cbor.h:163
cbor_encoder_create_map
CBOR_API CborError cbor_encoder_create_map(CborEncoder *encoder, CborEncoder *mapEncoder, size_t length)
cbor_encode_negative_int
CBOR_API CborError cbor_encode_negative_int(CborEncoder *encoder, uint64_t absolute_value)
CborMapType
@ CborMapType
Definition: cbor.h:87
CborIndefiniteLength
static const size_t CborIndefiniteLength
Definition: cbor.h:217
CborExpectedBase64Tag
#define CborExpectedBase64Tag
Definition: cbor.h:137
CborHalfFloatType
@ CborHalfFloatType
Definition: cbor.h:93
cbor_value_get_int
static CborError cbor_value_get_int(const CborValue *value, int *result)
Definition: cbor.h:378
CborInvalidType
@ CborInvalidType
Definition: cbor.h:97
_cbor_value_dup_string
CborError _cbor_value_dup_string(const CborValue *value, void **buffer, size_t *buflen, CborValue *next)
CborValue::extra
uint16_t extra
Definition: cbor.h:288
cbor_value_get_uint64
static CborError cbor_value_get_uint64(const CborValue *value, uint64_t *result)
Definition: cbor.h:362
cbor_encoder_create_array
CBOR_API CborError cbor_encoder_create_array(CborEncoder *encoder, CborEncoder *arrayEncoder, size_t length)
CborValidateFiniteFloatingPoint
@ CborValidateFiniteFloatingPoint
Definition: cbor.h:548
cbor_value_at_end
static bool cbor_value_at_end(const CborValue *it)
Definition: cbor.h:298
CborEncoder::end
const uint8_t * end
Definition: cbor.h:211
CborCOSE_Sign1Tag
#define CborCOSE_Sign1Tag
Definition: cbor.h:135
cbor_value_is_length_known
static bool cbor_value_is_length_known(const CborValue *value)
Definition: cbor.h:390
cbor_encode_text_stringz
static CborError cbor_encode_text_stringz(CborEncoder *encoder, const char *string)
Definition: cbor.h:226
CborTextStringType
@ CborTextStringType
Definition: cbor.h:85
CborRegularExpressionTag
#define CborRegularExpressionTag
Definition: cbor.h:143
cbor_encoder_close_container
CBOR_API CborError cbor_encoder_close_container(CborEncoder *encoder, const CborEncoder *containerEncoder)
cbor_value_get_int64_checked
CBOR_API CborError cbor_value_get_int64_checked(const CborValue *value, int64_t *result)
CborPrettyNumericEncodingIndicators
@ CborPrettyNumericEncodingIndicators
Definition: cbor.h:569
CborTagType
@ CborTagType
Definition: cbor.h:88
cbor_encode_text_string
CBOR_API CborError cbor_encode_text_string(CborEncoder *encoder, const char *string, size_t length)
CborValidateNoUnknownTagsSR
@ CborValidateNoUnknownTagsSR
Definition: cbor.h:555
CborErrorUnsupportedType
@ CborErrorUnsupportedType
Definition: cbor.h:191
cbor_value_get_tag
static CborError cbor_value_get_tag(const CborValue *value, CborTag *result)
Definition: cbor.h:396
CborDoubleType
@ CborDoubleType
Definition: cbor.h:95
CborValidateBasic
@ CborValidateBasic
Definition: cbor.h:561
CborEncoder::data
union CborEncoder::@11 data
CborCOSE_Encrypt0Tag
#define CborCOSE_Encrypt0Tag
Definition: cbor.h:133
cbor_value_is_text_string
static bool cbor_value_is_text_string(const CborValue *value)
Definition: cbor.h:407
cbor_value_is_float
static bool cbor_value_is_float(const CborValue *value)
Definition: cbor.h:497
cbor_value_validate_basic
CBOR_API CborError cbor_value_validate_basic(const CborValue *it)
CborIteratorFlag_IntegerValueTooLarge
@ CborIteratorFlag_IntegerValueTooLarge
Definition: cbor.h:269
cbor_value_is_null
static bool cbor_value_is_null(const CborValue *value)
Definition: cbor.h:322
cbor_value_map_find_value
CBOR_API CborError cbor_value_map_find_value(const CborValue *map, const char *string, CborValue *element)
CborUndefinedType
@ CborUndefinedType
Definition: cbor.h:92
cbor_value_get_string_length
static CborError cbor_value_get_string_length(const CborValue *value, size_t *length)
Definition: cbor.h:410