Skip to content

Commit 9d25a44

Browse files
committed
Rebase and make changes to match recent commits
- Rebase to match recent commits - Fix tests to work with code changes - move new includes to include directory - move enums to include/cbor_defs - resolve merge issues - replace extract_number() with new cbor_value_extract_number() - replace assert() with cbor_assert() - use it->offset instead of it->ptr to track buffer offsets - update resolve_indicator() static api paramaters to use cbor value and access offsets instead of taking pointers as input parameters - In validate_container() do a byte by byte comparison instead of memcmp since we no longer have access to teh buffer directly Also, use offets instead of pointers to validate sorted maps
1 parent 27077f2 commit 9d25a44

19 files changed

+264
-626
lines changed

include/tinycbor/assert_p.h

Lines changed: 0 additions & 29 deletions
This file was deleted.

include/tinycbor/cbor.h

Lines changed: 1 addition & 240 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include <tinycbor/cbor_buf_writer.h>
3535
#include <tinycbor/cbor_buf_reader.h>
3636
#include <tinycbor/cbor_defs.h>
37-
#include "tinycbor-version.h"
37+
#include "tinycbor/tinycbor-version.h"
3838

3939
#define TINYCBOR_VERSION ((TINYCBOR_VERSION_MAJOR << 16) | (TINYCBOR_VERSION_MINOR << 8) | TINYCBOR_VERSION_PATCH)
4040

@@ -44,175 +44,8 @@ extern "C" {
4444
#include <stdbool.h>
4545
#endif
4646

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 {
83-
CborIntegerType = 0x00,
84-
CborByteStringType = 0x40,
85-
CborTextStringType = 0x60,
86-
CborArrayType = 0x80,
87-
CborMapType = 0xa0,
88-
CborTagType = 0xc0,
89-
CborSimpleType = 0xe0,
90-
CborBooleanType = 0xf5,
91-
CborNullType = 0xf6,
92-
CborUndefinedType = 0xf7,
93-
CborHalfFloatType = 0xf9,
94-
CborFloatType = 0xfa,
95-
CborDoubleType = 0xfb,
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 {
102-
CborDateTimeStringTag = 0,
103-
CborUnixTime_tTag = 1,
104-
CborPositiveBignumTag = 2,
105-
CborNegativeBignumTag = 3,
106-
CborDecimalTag = 4,
107-
CborBigfloatTag = 5,
108-
CborCOSE_Encrypt0Tag = 16,
109-
CborCOSE_Mac0Tag = 17,
110-
CborCOSE_Sign1Tag = 18,
111-
CborExpectedBase64urlTag = 21,
112-
CborExpectedBase64Tag = 22,
113-
CborExpectedBase16Tag = 23,
114-
CborEncodedCborTag = 24,
115-
CborUrlTag = 32,
116-
CborBase64urlTag = 33,
117-
CborBase64Tag = 34,
118-
CborRegularExpressionTag = 35,
119-
CborMimeMessageTag = 36,
120-
CborCOSE_EncryptTag = 96,
121-
CborCOSE_MacTag = 97,
122-
CborCOSE_SignTag = 98,
123-
CborSignatureTag = 55799
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 {
153-
CborNoError = 0,
154-
155-
/* errors in all modes */
156-
CborUnknownError,
157-
CborErrorUnknownLength, /* request for length in array, map, or string with indeterminate length */
158-
CborErrorAdvancePastEOF,
159-
CborErrorIO,
160-
161-
/* parser errors streaming errors */
162-
CborErrorGarbageAtEnd = 256,
163-
CborErrorUnexpectedEOF,
164-
CborErrorUnexpectedBreak,
165-
CborErrorUnknownType, /* can only heppen in major type 7 */
166-
CborErrorIllegalType, /* type not allowed here */
167-
CborErrorIllegalNumber,
168-
CborErrorIllegalSimpleType, /* types of value less than 32 encoded in two bytes */
169-
170-
/* parser errors in strict mode parsing only */
171-
CborErrorUnknownSimpleType = 512,
172-
CborErrorUnknownTag,
173-
CborErrorInappropriateTagForType,
174-
CborErrorDuplicateObjectKeys,
175-
CborErrorInvalidUtf8TextString,
176-
CborErrorExcludedType,
177-
CborErrorExcludedValue,
178-
CborErrorImproperValue,
179-
CborErrorOverlongEncoding,
180-
CborErrorMapKeyNotString,
181-
CborErrorMapNotSorted,
182-
CborErrorMapKeysNotUnique,
183-
184-
/* encoder errors */
185-
CborErrorTooManyItems = 768,
186-
CborErrorTooFewItems,
187-
188-
/* internal implementation errors */
189-
CborErrorDataTooLarge = 1024,
190-
CborErrorNestingTooDeep,
191-
CborErrorUnsupportedType,
192-
193-
/* errors in converting to JSON */
194-
CborErrorJsonObjectKeyIsAggregate,
195-
CborErrorJsonObjectKeyNotString,
196-
CborErrorJsonNotImplemented,
197-
198-
CborErrorOutOfMemory = (int) (~0U / 2 + 1),
199-
CborErrorInternalError = (int) (~0U / 2) /* INT_MAX on two's complement machines */
200-
} CborError;
201-
20247
CBOR_API const char *cbor_error_string(CborError error);
20348

204-
struct cbor_encoder_writer;
205-
206-
typedef int (cbor_encoder_write)(struct cbor_encoder_writer *, const char *data, int len);
207-
208-
typedef struct cbor_encoder_writer {
209-
cbor_encoder_write *write;
210-
int bytes_written;
211-
} cbor_encoder_writer;
212-
213-
214-
=======
215-
>>>>>>> Making API backwards compatible
21649
/* Encoder API */
21750
struct CborEncoder
21851
{
@@ -263,22 +96,7 @@ CBOR_API CborError cbor_encoder_create_map(CborEncoder *encoder, CborEncoder *ma
26396
CBOR_API CborError cbor_encoder_close_container(CborEncoder *encoder, const CborEncoder *containerEncoder);
26497
CBOR_API CborError cbor_encoder_close_container_checked(CborEncoder *encoder, const CborEncoder *containerEncoder);
26598

266-
CBOR_INLINE_API uint8_t *_cbor_encoder_get_buffer_pointer(const CborEncoder *encoder)
267-
{
268-
return encoder->data.ptr;
269-
}
270-
27199
/* Parser API */
272-
273-
enum CborParserIteratorFlags
274-
{
275-
CborIteratorFlag_IntegerValueTooLarge = 0x01,
276-
CborIteratorFlag_NegativeInteger = 0x02,
277-
CborIteratorFlag_IteratingStringChunks = 0x02,
278-
CborIteratorFlag_UnknownLength = 0x04,
279-
CborIteratorFlag_ContainerIsMap = 0x20
280-
};
281-
282100
struct CborParser
283101
{
284102
#ifndef NO_DFLT_READER
@@ -540,68 +358,13 @@ CBOR_INLINE_API CborError cbor_value_get_double(const CborValue *value, double *
540358
}
541359

542360
/* Validation API */
543-
544-
enum CborValidationFlags {
545-
/* Bit mapping:
546-
* bits 0-7 (8 bits): canonical format
547-
* bits 8-11 (4 bits): canonical format & strict mode
548-
* bits 12-20 (8 bits): strict mode
549-
* bits 21-31 (10 bits): other
550-
*/
551-
552-
CborValidateShortestIntegrals = 0x0001,
553-
CborValidateShortestFloatingPoint = 0x0002,
554-
CborValidateShortestNumbers = CborValidateShortestIntegrals | CborValidateShortestFloatingPoint,
555-
CborValidateNoIndeterminateLength = 0x0100,
556-
CborValidateMapIsSorted = 0x0200 | CborValidateNoIndeterminateLength,
557-
558-
CborValidateCanonicalFormat = 0x0fff,
559-
560-
CborValidateMapKeysAreUnique = 0x1000 | CborValidateMapIsSorted,
561-
CborValidateTagUse = 0x2000,
562-
CborValidateUtf8 = 0x4000,
563-
564-
CborValidateStrictMode = 0xfff00,
565-
566-
CborValidateMapKeysAreString = 0x100000,
567-
CborValidateNoUndefined = 0x200000,
568-
CborValidateNoTags = 0x400000,
569-
CborValidateFiniteFloatingPoint = 0x800000,
570-
/* unused = 0x1000000, */
571-
/* unused = 0x2000000, */
572-
573-
CborValidateNoUnknownSimpleTypesSA = 0x4000000,
574-
CborValidateNoUnknownSimpleTypes = 0x8000000 | CborValidateNoUnknownSimpleTypesSA,
575-
CborValidateNoUnknownTagsSA = 0x10000000,
576-
CborValidateNoUnknownTagsSR = 0x20000000 | CborValidateNoUnknownTagsSA,
577-
CborValidateNoUnknownTags = 0x40000000 | CborValidateNoUnknownTagsSR,
578-
579-
CborValidateCompleteData = (int)0x80000000,
580-
581-
CborValidateStrictest = (int)~0U,
582-
CborValidateBasic = 0
583-
};
584-
585361
CBOR_API CborError cbor_value_validate(const CborValue *it, int flags);
586362

587363
/* The following API requires a hosted C implementation (uses FILE*) */
588364
#if !defined(__STDC_HOSTED__) || __STDC_HOSTED__-0 == 1
589365

590366
/* Human-readable (dump) API */
591367

592-
enum CborPrettyFlags {
593-
CborPrettyNumericEncodingIndicators = 0x01,
594-
CborPrettyTextualEncodingIndicators = 0,
595-
596-
CborPrettyIndicateIndetermineLength = 0x02,
597-
CborPrettyIndicateOverlongNumbers = 0x04,
598-
599-
CborPrettyShowStringFragments = 0x100,
600-
CborPrettyMergeStringFragments = 0,
601-
602-
CborPrettyDefaultFlags = CborPrettyIndicateIndetermineLength
603-
};
604-
605368
CBOR_API CborError cbor_value_to_pretty_advance_flags(FILE *out, CborValue *value, int flags);
606369
CBOR_API CborError cbor_value_to_pretty_advance(FILE *out, CborValue *value);
607370
CBOR_INLINE_API CborError cbor_value_to_pretty(FILE *out, const CborValue *value)
@@ -610,8 +373,6 @@ CBOR_INLINE_API CborError cbor_value_to_pretty(FILE *out, const CborValue *value
610373
return cbor_value_to_pretty_advance_flags(out, &copy, CborPrettyDefaultFlags);
611374
}
612375

613-
CBOR_API const char *cbor_error_string(CborError error);
614-
615376
#endif /* __STDC_HOSTED__ check */
616377

617378
#ifdef __cplusplus

0 commit comments

Comments
 (0)