зеркало из https://github.com/microsoft/CCF.git
Update `QCBOR` from `1.1` to `1.2` (#5608)
This commit is contained in:
Родитель
4265dcf959
Коммит
3143b30629
|
@ -1,19 +1,77 @@
|
|||
cmake_minimum_required(VERSION 3.10.2)
|
||||
#-------------------------------------------------------------------------------
|
||||
# Copyright (c) 2022-2023, Arm Limited. All rights reserved.
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
# See BSD-3-Clause license in README.md
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
project(qcbor
|
||||
DESCRIPTION "QCBOR"
|
||||
LANGUAGES C
|
||||
VERSION 1.0.0)
|
||||
DESCRIPTION "QCBOR"
|
||||
LANGUAGES C
|
||||
VERSION 1.1.0
|
||||
)
|
||||
|
||||
set(CMAKE_C_FLAGS "-pedantic -Wall -O3 -ffunction-sections")
|
||||
set(BUILD_QCBOR_TEST "OFF" CACHE STRING "Build QCBOR test suite [OFF, LIB, APP]")
|
||||
set(BUILD_QCBOR_WARN OFF CACHE BOOL "Compile with the warning flags used in the QCBOR release process")
|
||||
# BUILD_SHARED_LIBS is a built-in global CMake flag
|
||||
# The shared library is not made by default because of platform
|
||||
# variability For example MacOS and Linux behave differently and some
|
||||
# IoT OS's don't support them at all.
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries instead of static ones")
|
||||
|
||||
set(SOURCE
|
||||
src/ieee754.c
|
||||
src/qcbor_decode.c
|
||||
src/qcbor_encode.c
|
||||
src/qcbor_err_to_str.c
|
||||
src/UsefulBuf.c
|
||||
)
|
||||
# Configuration:
|
||||
# Floating-point support (see README.md for more information)
|
||||
set(QCBOR_OPT_DISABLE_FLOAT_HW_USE OFF CACHE BOOL "Eliminate dependency on FP hardware and FP instructions")
|
||||
set(QCBOR_OPT_DISABLE_FLOAT_PREFERRED OFF CACHE BOOL "Eliminate support for half-precision and CBOR preferred serialization")
|
||||
set(QCBOR_OPT_DISABLE_FLOAT_ALL OFF CACHE BOOL "Eliminate floating-point support completely")
|
||||
|
||||
add_library(qcbor ${SOURCE})
|
||||
if (BUILD_QCBOR_WARN)
|
||||
# Compile options applying to all targets in current directory and below
|
||||
add_compile_options(-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wcast-qual)
|
||||
endif()
|
||||
|
||||
target_include_directories(qcbor PUBLIC inc)
|
||||
add_library(qcbor)
|
||||
|
||||
target_sources(qcbor
|
||||
PRIVATE
|
||||
src/ieee754.c
|
||||
src/qcbor_decode.c
|
||||
src/qcbor_encode.c
|
||||
src/qcbor_err_to_str.c
|
||||
src/UsefulBuf.c
|
||||
)
|
||||
|
||||
target_include_directories(qcbor
|
||||
PUBLIC
|
||||
inc
|
||||
PRIVATE
|
||||
src
|
||||
)
|
||||
|
||||
target_compile_definitions(qcbor
|
||||
PRIVATE
|
||||
$<$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_HW_USE}>:QCBOR_DISABLE_FLOAT_HW_USE>
|
||||
$<$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_PREFERRED}>:QCBOR_DISABLE_PREFERRED_FLOAT>
|
||||
$<$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_ALL}>:USEFULBUF_DISABLE_ALL_FLOAT>
|
||||
)
|
||||
|
||||
if (BUILD_SHARED_LIBS)
|
||||
target_compile_options(qcbor PRIVATE -Os -fPIC)
|
||||
endif()
|
||||
|
||||
# The math library is needed for floating-point support.
|
||||
# To avoid need for it #define QCBOR_DISABLE_FLOAT_HW_USE
|
||||
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
||||
# Using GCC
|
||||
target_link_libraries(qcbor
|
||||
PRIVATE
|
||||
$<$<NOT:$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_HW_USE}>>:m>
|
||||
)
|
||||
endif()
|
||||
|
||||
if (NOT BUILD_QCBOR_TEST STREQUAL "OFF")
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
|
|
@ -19,8 +19,8 @@ LIBS=-lm
|
|||
# The $(CMD_LINE) variable allows passing in extra flags. This is
|
||||
# used on the stringent build script that is in
|
||||
# https://github.com/laurencelundblade/qdv. This script is used
|
||||
# before pushes to master (though not yet through and automated build
|
||||
# process)
|
||||
# before pushes to master (though not yet through an automated build
|
||||
# process). See "warn:" below.
|
||||
CFLAGS=$(CMD_LINE) -I inc -I test -Os -fPIC
|
||||
|
||||
|
||||
|
@ -30,7 +30,7 @@ TEST_OBJ=test/UsefulBuf_Tests.o test/qcbor_encode_tests.o \
|
|||
test/qcbor_decode_tests.o test/run_tests.o \
|
||||
test/float_tests.o test/half_to_double_from_rfc7049.o example.o ub-example.o
|
||||
|
||||
.PHONY: all so install uninstall clean
|
||||
.PHONY: all so install uninstall clean warn
|
||||
|
||||
all: qcbortest libqcbor.a
|
||||
|
||||
|
@ -42,6 +42,11 @@ qcbortest: libqcbor.a $(TEST_OBJ) cmd_line_main.o
|
|||
libqcbor.a: $(QCBOR_OBJ)
|
||||
ar -r $@ $^
|
||||
|
||||
# run "make warn" as a handy way to compile with the warning flags
|
||||
# used in the QCBOR release process. See CFLAGS above.
|
||||
warn:
|
||||
make CMD_LINE="-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wcast-qual"
|
||||
|
||||
|
||||
# The shared library is not made by default because of platform
|
||||
# variability For example MacOS and Linux behave differently and some
|
||||
|
|
|
@ -12,7 +12,7 @@ Replaced by RFC 8949.
|
|||
|
||||
## QCBOR Characteristics
|
||||
|
||||
**Implemented in C with minimal dependency** – Dependent only
|
||||
**Implemented in C with minimal dependency** – Dependent only
|
||||
on C99, <stdint.h>, <stddef.h>, <stdbool.h> and <string.h> making
|
||||
it highly portable. <math.h> and <fenv.h> are used too, but their
|
||||
use can disabled. No #ifdefs or compiler options need to be set for
|
||||
|
@ -34,7 +34,7 @@ Replaced by RFC 8949.
|
|||
encoded CBOR and encode/decode contexts so caller has full control
|
||||
of memory usage making it good for embedded implementations that
|
||||
have to run in small fixed memory.
|
||||
|
||||
|
||||
**Easy decoding of maps** – The "spiffy decode" functions allow
|
||||
fetching map items directly by label. Detection of duplicate map
|
||||
items is automatically performed. This makes decoding of complex
|
||||
|
@ -93,7 +93,7 @@ implementations as seen in the following example.
|
|||
QCBOREncode_AddInt64ToMap(&EncodeCtx, "Horsepower", pE->uHorsePower);
|
||||
QCBOREncode_CloseMap(&EncodeCtx);
|
||||
uErr = QCBOREncode_Finish(&EncodeCtx, &EncodedEngine);
|
||||
|
||||
|
||||
/* Decode */
|
||||
QCBORDecode_Init(&DecodeCtx, EncodedEngine, QCBOR_DECODE_MODE_NORMAL);
|
||||
QCBORDecode_EnterMap(&DecodeCtx);
|
||||
|
@ -172,7 +172,7 @@ The current version is v1.1, a small feature addition and bug fix
|
|||
release over QCBOR 1.0.
|
||||
|
||||
Code has been stable for over a year. The last major change was in
|
||||
fall of 2020.
|
||||
fall of 2020.
|
||||
|
||||
QCBOR was originally developed by Qualcomm. It was [open sourced
|
||||
through CAF](https://source.codeaurora.org/quic/QCBOR/QCBOR/) with a
|
||||
|
@ -181,7 +181,8 @@ permissive Linux license, September 2018 (thanks Qualcomm!).
|
|||
## Building
|
||||
|
||||
There is a simple makefile for the UNIX style command line binary that
|
||||
compiles everything to run the tests.
|
||||
compiles everything to run the tests. CMake is also available, please read
|
||||
the "Building with CMake" section for more information.
|
||||
|
||||
These eleven files, the contents of the src and inc directories, make
|
||||
up the entire implementation.
|
||||
|
@ -213,14 +214,55 @@ RunTests() to invoke them all.
|
|||
While this code will run fine without configuration, there are several
|
||||
C pre processor macros that can be #defined in order to:
|
||||
|
||||
* use a more efficient implementation
|
||||
* use a more efficient implementation
|
||||
* to reduce code size
|
||||
* to improve performance (a little)
|
||||
* remove features to reduce code size
|
||||
|
||||
See the comment sections on "Configuration" in inc/UsefulBuf.h and
|
||||
See the comment sections on "Configuration" in inc/UsefulBuf.h and
|
||||
the pre processor defines that start with QCBOR_DISABLE_XXX.
|
||||
|
||||
### Building with CMake
|
||||
|
||||
CMake can also be used to build QCBOR and the test application. Having the root
|
||||
`CMakeLists.txt` file, QCBOR can be easily integrated with your project's
|
||||
existing CMake environment. The result of the build process is a static library,
|
||||
to build a shared library instead you must add the
|
||||
`-DBUILD_SHARED_LIBS=ON` option at the CMake configuration step.
|
||||
The tests can be built into a simple command line application to run them as it
|
||||
was mentioned before; or it can be built as a library to be integrated with your
|
||||
development environment.
|
||||
The `BUILD_QCBOR_TEST` CMake option can be used for building the tests, it can
|
||||
have three values: `APP`, `LIB` or `OFF` (default, test are not included in the
|
||||
build).
|
||||
|
||||
Building the QCBOR library:
|
||||
|
||||
```bash
|
||||
cd <QCBOR_base_folder>
|
||||
# Configuring the project and generating a native build system
|
||||
cmake -S . -B <build_folder>
|
||||
# Building the project
|
||||
cmake --build <build_folder>
|
||||
```
|
||||
|
||||
Building and running the QCBOR test app:
|
||||
```bash
|
||||
cd <QCBOR_base_folder>
|
||||
# Configuring the project and generating a native build system
|
||||
cmake -S . -B <build_folder> -DBUILD_QCBOR_TEST=APP
|
||||
# Building the project
|
||||
cmake --build <build_folder>
|
||||
# Running the test app
|
||||
.<build_folder>/test/qcbortest
|
||||
```
|
||||
|
||||
To enable all the compiler warnings that are used in the QCBOR release process
|
||||
you can use the `BUILD_QCBOR_WARN` option at the CMake configuration step:
|
||||
```bash
|
||||
cmake -S . -B <build_folder> -DBUILD_QCBOR_WARN=ON
|
||||
```
|
||||
|
||||
### Floating Point Support & Configuration
|
||||
|
||||
By default, all QCBOR floating-point features are enabled:
|
||||
|
@ -238,7 +280,7 @@ used to reduce object code size and dependency.
|
|||
|
||||
See discussion in qcbor_encode.h for other details.
|
||||
|
||||
### #define QCBOR_DISABLE_FLOAT_HW_USE
|
||||
#### #define QCBOR_DISABLE_FLOAT_HW_USE
|
||||
|
||||
This removes dependency on:
|
||||
|
||||
|
@ -278,7 +320,7 @@ This saves only a small amount of object code. The primary purpose for
|
|||
defining this is to remove dependency on floating point hardware and
|
||||
libraries.
|
||||
|
||||
#### #define QCBOR_DISABLE_PREFERRED_FLOAT
|
||||
#### #define QCBOR_DISABLE_PREFERRED_FLOAT
|
||||
|
||||
This eliminates support for half-precision
|
||||
and CBOR preferred serialization by disabling
|
||||
|
@ -287,9 +329,9 @@ half-precision floating-point.
|
|||
|
||||
With this defined, single and double-precision floating-point
|
||||
numbers can still be encoded and decoded. Conversion
|
||||
of floating-point to and from integers, big numbers and
|
||||
of floating-point to and from integers, big numbers and
|
||||
such is also supported. Floating-point dates are still
|
||||
supported.
|
||||
supported.
|
||||
|
||||
The primary reason to define this is to save object code.
|
||||
Roughly 900 bytes are saved, though about half of this
|
||||
|
@ -311,49 +353,61 @@ it is usually possible to give options to the compiler to avoid all
|
|||
floating-point hardware and instructions, to use software
|
||||
and replacement libraries instead. These are usually
|
||||
bigger and slower, but these options may still be useful
|
||||
in getting QCBOR to run in some environments in
|
||||
in getting QCBOR to run in some environments in
|
||||
combination with `QCBOR_DISABLE_FLOAT_HW_USE`.
|
||||
In particular, `-mfloat-abi=soft`, disables use of
|
||||
In particular, `-mfloat-abi=soft`, disables use of
|
||||
hardware instructions for the float and double
|
||||
types in C for some architectures.
|
||||
types in C for some architectures.
|
||||
|
||||
#### CMake options
|
||||
|
||||
If you are using CMake, it can also be used to configure the floating-point
|
||||
support. These options can be enabled by adding them to the CMake configuration
|
||||
step and setting their value to 'ON' (True). The following table shows the
|
||||
available options and the associated #defines.
|
||||
|
||||
| CMake option | #define |
|
||||
|-----------------------------------|-------------------------------|
|
||||
| QCBOR_OPT_DISABLE_FLOAT_HW_USE | QCBOR_DISABLE_FLOAT_HW_USE |
|
||||
| QCBOR_OPT_DISABLE_FLOAT_PREFERRED | QCBOR_DISABLE_PREFERRED_FLOAT |
|
||||
| QCBOR_OPT_DISABLE_FLOAT_ALL | USEFULBUF_DISABLE_ALL_FLOAT |
|
||||
|
||||
## Code Size
|
||||
|
||||
These are approximate sizes on a 64-bit x86 CPU with the -Os optimization.
|
||||
|
||||
| | smallest | largest |
|
||||
| | smallest | largest |
|
||||
|---------------|----------|---------|
|
||||
| encode only | 850 | 2100 |
|
||||
| decode only | 2000 | 13300 |
|
||||
| combined | 2850 | 15500 |
|
||||
|
||||
| encode only | 900 | 2100 |
|
||||
| decode only | 1550 | 13300 |
|
||||
| combined | 2450 | 15500 |
|
||||
|
||||
From the table above, one can see that the amount of code pulled in
|
||||
from the QCBOR library varies a lot, ranging from 1KB to 15KB. The
|
||||
main factor is in this is the number of QCBOR functions called and
|
||||
which ones they are. QCBOR is constructed with less internal
|
||||
interdependency so only code necessary for the called functions is
|
||||
brought in.
|
||||
|
||||
|
||||
Encoding is simpler and smaller. An encode-only implementation may
|
||||
bring in only 1KB of code.
|
||||
|
||||
|
||||
Encoding of floating-point brings in a little more code as does
|
||||
encoding of tagged types and encoding of bstr wrapping.
|
||||
|
||||
|
||||
Basic decoding using QCBORDecode_GetNext() brings in 3KB.
|
||||
|
||||
|
||||
Use of the supplied MemPool by calling QCBORDecode_SetMemPool() to
|
||||
setup to decode indefinite-length strings adds 0.5KB.
|
||||
|
||||
|
||||
Basic use of spiffy decode to brings in about 3KB. Using more spiffy
|
||||
decode functions, such as those for tagged types bstr wrapping brings
|
||||
in more code.
|
||||
|
||||
|
||||
Finally, use of all of the integer conversion functions will bring in
|
||||
about 5KB, though you can use the simpler ones like
|
||||
QCBORDecode_GetInt64() without bringing in very much code.
|
||||
|
||||
|
||||
In addition to using fewer QCBOR functions, the following are some
|
||||
ways to make the code smaller.
|
||||
|
||||
|
@ -366,22 +420,23 @@ These are approximate sizes on a 64-bit x86 CPU with the -Os optimization.
|
|||
|
||||
If QCBOR is installed as a shared library, then of course only one
|
||||
copy of the code is in memory no matter how many applications use it.
|
||||
|
||||
|
||||
### Disabling Features
|
||||
|
||||
Here's the list of all features that can be disabled to save object
|
||||
code. The amount saved is an approximation.
|
||||
|
||||
| #define | Saves |
|
||||
| ----------------------------------------| ------|
|
||||
| QCBOR_DISABLE_ENCODE_USAGE_GUARDS | 150 |
|
||||
| QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS | 400 |
|
||||
| QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS | 200 |
|
||||
| QCBOR_DISABLE_UNCOMMON_TAGS | 100 |
|
||||
| QCBOR_DISABLE_EXP_AND_MANTISSA | 400 |
|
||||
| QCBOR_DISABLE_PREFERRED_FLOAT | 900 |
|
||||
| QCBOR_DISABLE_FLOAT_HW_USE | 50 |
|
||||
| USEFULBUF_DISABLE_ALL_FLOAT | 950 |
|
||||
| #define | Saves |
|
||||
| ----------------------------------------| ------|
|
||||
| QCBOR_DISABLE_ENCODE_USAGE_GUARDS | 150 |
|
||||
| QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS | 400 |
|
||||
| QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS | 200 |
|
||||
| QCBOR_DISABLE_UNCOMMON_TAGS | 100 |
|
||||
| QCBOR_DISABLE_EXP_AND_MANTISSA | 400 |
|
||||
| QCBOR_DISABLE_PREFERRED_FLOAT | 900 |
|
||||
| QCBOR_DISABLE_FLOAT_HW_USE | 50 |
|
||||
| QCBOR_DISABLE_TAGS | 400 |
|
||||
| USEFULBUF_DISABLE_ALL_FLOAT | 950 |
|
||||
|
||||
QCBOR_DISABLE_ENCODE_USAGE_GUARDS affects encoding only. It doesn't
|
||||
disable any encoding features, just some error checking. Disable it
|
||||
|
@ -409,20 +464,25 @@ QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS which will result in an error
|
|||
when an indefinite-length map or array arrives for decoding.
|
||||
|
||||
QCBOR_DISABLE_UNCOMMON_TAGS disables the decoding of explicit tags for
|
||||
base 64, regex, UUID and MIME data. This just disabled the automatic
|
||||
base 64, regex, UUID and MIME data. This just disables the automatic
|
||||
recognition of these from a major type 6 tag.
|
||||
|
||||
QCBOR_DISABLE_EXP_AND_MANTISSA disables the decoding of decimal
|
||||
fractions and big floats.
|
||||
|
||||
QCBOR_DISABLE_TAGS disables all decoding of CBOR tags. If the input has
|
||||
a single tag, the error is unrecoverable so it is suitable only for protocols that
|
||||
have no tags. "Borrowed" tag content formats (e.g. an epoch-based date
|
||||
without the tag number), can still be processed.
|
||||
|
||||
See the discussion above on floating-point.
|
||||
|
||||
### Size of spiffy decode
|
||||
|
||||
|
||||
When creating a decode implementation, there is a choice of whether
|
||||
or not to use spiffy decode features or to just use
|
||||
QCBORDecode_GetNext().
|
||||
|
||||
|
||||
The implementation using spiffy decode will be simpler resulting in
|
||||
the calling code being smaller, but the amount of code brought in
|
||||
from the QCBOR library will be larger. Basic use of spiffy decode
|
||||
|
@ -430,7 +490,7 @@ See the discussion above on floating-point.
|
|||
concern, then it is probably better to use spiffy decode because it
|
||||
is less work, there is less complexity and less testing to worry
|
||||
about.
|
||||
|
||||
|
||||
If code size is a concern, then use of QCBORDecode_GetNext() will
|
||||
probably result in smaller overall code size for simpler CBOR
|
||||
protocols. However, if the CBOR protocol is complex then use of
|
||||
|
@ -440,13 +500,13 @@ See the discussion above on floating-point.
|
|||
because the general purpose spiffy decode map processor is the one
|
||||
used for all the maps.
|
||||
|
||||
|
||||
|
||||
## Other Software Using QCBOR
|
||||
|
||||
* [t_cose](https://github.com/laurencelundblade/t_cose) implements enough of
|
||||
[COSE, RFC 8152](https://tools.ietf.org/html/rfc8152) to support
|
||||
[CBOR Web Token (CWT)](https://tools.ietf.org/html/rfc8392) and
|
||||
[Entity Attestation Token (EAT)](https://tools.ietf.org/html/draft-ietf-rats-eat-06).
|
||||
[Entity Attestation Token (EAT)](https://tools.ietf.org/html/draft-ietf-rats-eat-06).
|
||||
Specifically it supports signing and verification of the COSE_Sign1 message.
|
||||
|
||||
* [ctoken](https://github.com/laurencelundblade/ctoken) is an implementation of
|
||||
|
@ -504,4 +564,4 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
### Copyright for this README
|
||||
|
||||
Copyright (c) 2018-2021, Laurence Lundblade. All rights reserved.
|
||||
Copyright (c) 2021, Arm Limited. All rights reserved.
|
||||
Copyright (c) 2021-2023, Arm Limited. All rights reserved.
|
||||
|
|
|
@ -307,7 +307,7 @@ Done:
|
|||
}
|
||||
|
||||
|
||||
int32_t RunQCborExample()
|
||||
int32_t RunQCborExample(void)
|
||||
{
|
||||
CarEngine InitialEngine;
|
||||
CarEngine DecodedEngine;
|
||||
|
|
|
@ -42,6 +42,7 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
when who what, where, why
|
||||
-------- ---- --------------------------------------------------
|
||||
19/12/2022 llundblade Document that adding empty data is allowed.
|
||||
4/11/2022 llundblade Add GetOutPlace and Advance to UsefulOutBuf.
|
||||
9/21/2021 llundbla Clarify UsefulOutBuf size calculation mode
|
||||
8/8/2021 dthaler/llundbla Work with C++ without compiler extensions
|
||||
|
@ -673,15 +674,8 @@ static inline UsefulBuf UsefulBufC_Unconst(const UsefulBufC UBC)
|
|||
{
|
||||
UsefulBuf UB;
|
||||
|
||||
// See UsefulBuf_Unconst() implementation for comment on pragmas
|
||||
#ifndef _MSC_VER
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wcast-qual"
|
||||
#endif
|
||||
UB.ptr = (void *)UBC.ptr;
|
||||
#ifndef _MSC_VER
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
// See UsefulBuf_Unconst() implementation for comment
|
||||
UB.ptr = (void *)(uintptr_t)UBC.ptr;
|
||||
|
||||
UB.len = UBC.len;
|
||||
|
||||
|
@ -954,6 +948,8 @@ static inline int UsefulOutBuf_AtStart(UsefulOutBuf *pUOutBuf);
|
|||
* Overlapping buffers are OK. @c NewData can point to data in the
|
||||
* output buffer.
|
||||
*
|
||||
* NewData.len may be 0 in which case nothing will be inserted.
|
||||
*
|
||||
* If an error occurs, an error state is set in the @ref
|
||||
* UsefulOutBuf. No error is returned. All subsequent attempts to add
|
||||
* data will do nothing.
|
||||
|
@ -1759,16 +1755,9 @@ static inline UsefulBuf UsefulBuf_Unconst(const UsefulBufC UBC)
|
|||
UsefulBuf UB;
|
||||
|
||||
/* -Wcast-qual is a good warning flag to use in general. This is
|
||||
* the one place in UsefulBuf where it needs to be quieted. Since
|
||||
* clang supports GCC pragmas, this works for clang too. */
|
||||
#ifndef _MSC_VER
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wcast-qual"
|
||||
#endif
|
||||
UB.ptr = (void *)UBC.ptr;
|
||||
#ifndef _MSC_VER
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
* the one place in UsefulBuf where it needs to be quieted.
|
||||
*/
|
||||
UB.ptr = (void *)(uintptr_t)UBC.ptr;
|
||||
|
||||
UB.len = UBC.len;
|
||||
|
||||
|
|
|
@ -468,6 +468,10 @@ typedef enum {
|
|||
indefinite length map or array in the input CBOR. */
|
||||
QCBOR_ERR_INDEF_LEN_ARRAYS_DISABLED = 50,
|
||||
|
||||
/** All decoding of tags (major type 6) has been disabled and a tag
|
||||
occurred in the decode input. */
|
||||
QCBOR_ERR_TAGS_DISABLED = 51,
|
||||
|
||||
#define QCBOR_END_OF_UNRECOVERABLE_DECODE_ERRORS 59
|
||||
|
||||
/** More than @ref QCBOR_MAX_TAGS_PER_ITEM tags encountered for a
|
||||
|
|
|
@ -162,6 +162,23 @@ extern "C" {
|
|||
* item being sought, in which case the unrecoverable error will be
|
||||
* returned. Unrecoverable errors are those indicated by
|
||||
* QCBORDecode_IsUnrecoverableError().
|
||||
*
|
||||
* @anchor Disabilng-Tag-Decoding
|
||||
* # Disabilng Tag Decoding
|
||||
*
|
||||
* If QCBOR_DISABLE_TAGS is defined, all code for decoding tags will
|
||||
* be omitted reducing the core decoder, QCBORDecode_VGetNext(), by
|
||||
* about 400 bytes. If a tag number is encountered in the decoder
|
||||
* input the unrecoverable error @ref QCBOR_ERR_TAGS_DISABLED will be
|
||||
* returned. No input with tags can be decoded.
|
||||
*
|
||||
* Decode functions like QCBORDecode_GetEpochDate() and
|
||||
* QCBORDecode_GetDecimalFraction() that can decode the tag content
|
||||
* even if the tag number is absent are still available. Typically
|
||||
* they won't be linked in because of dead stripping. The
|
||||
* @c uTagRequirement parameter has no effect, but if it is
|
||||
* @ref QCBOR_TAG_REQUIREMENT_TAG, @ref QCBOR_ERR_TAGS_DISABLED
|
||||
* will be set.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -481,6 +498,7 @@ typedef struct _QCBORItem {
|
|||
uint64_t uint64;
|
||||
} label;
|
||||
|
||||
#ifndef QCBOR_DISABLE_TAGS
|
||||
/**
|
||||
* The tags numbers for which the item is the tag content. Tags
|
||||
* nest, so index 0 in the array is the tag on the data item
|
||||
|
@ -502,6 +520,7 @@ typedef struct _QCBORItem {
|
|||
* having to reference this array. Also see @ref Tags-Overview.
|
||||
*/
|
||||
uint16_t uTags[QCBOR_MAX_TAGS_PER_ITEM];
|
||||
#endif
|
||||
|
||||
} QCBORItem;
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ extern "C" {
|
|||
## Tag Usage
|
||||
|
||||
Data types beyond the basic CBOR types of numbers, strings, maps and
|
||||
arrays are called tags. The main registry of these new types is in in
|
||||
arrays are called tags. The main registry of these new types is in
|
||||
the IANA CBOR tags registry. These new types may be simple such a
|
||||
number that is to be interpreted as a date, or of moderate complexity
|
||||
such as defining a decimal fraction that is an array containing a
|
||||
|
@ -296,6 +296,12 @@ static void QCBORDecode_GetInt64ConvertInMapSZ(QCBORDecodeContext *pCtx,
|
|||
See also QCBORDecode_GetInt64ConvertAll() which does some of these
|
||||
conversions, but links in much less object code. See also
|
||||
QCBORDecode_GetUInt64ConvertAll().
|
||||
|
||||
This relies on CBOR tags to identify big numbers, decimal fractions
|
||||
and big floats. It will not attempt to decode non-tag CBOR that might
|
||||
be one of these. (If QCBOR_DISABLE_TAGS is set, this is effectively
|
||||
the same as QCBORDecode_GetInt64Convert() because all the additional
|
||||
number types this decodes are tags).
|
||||
*/
|
||||
void QCBORDecode_GetInt64ConvertAll(QCBORDecodeContext *pCtx,
|
||||
uint32_t uConvertTypes,
|
||||
|
@ -1210,6 +1216,10 @@ void QCBORDecode_GetBignumInMapSZ(QCBORDecodeContext *pCtx,
|
|||
See also @ref CBOR_TAG_DECIMAL_FRACTION,
|
||||
QCBOREncode_AddDecimalFraction(), @ref QCBOR_TYPE_DECIMAL_FRACTION
|
||||
and QCBORDecode_GetDecimalFractionBig().
|
||||
|
||||
If QCBOR_DISABLE_TAGS is set, the only input this will decode is
|
||||
an array of two integers. It will set an error if the the array is preceded
|
||||
by by a tag number or if the mantissa is a big number.
|
||||
*/
|
||||
void QCBORDecode_GetDecimalFraction(QCBORDecodeContext *pCtx,
|
||||
uint8_t uTagRequirement,
|
||||
|
@ -1297,6 +1307,10 @@ void QCBORDecode_GetDecimalFractionBigInMapSZ(QCBORDecodeContext *pCtx,
|
|||
|
||||
mantissa * ( 2 ** exponent )
|
||||
|
||||
If the mantissa is a tag that is a positive or negative big number,
|
||||
this will attempt to fit it into the int64_t that @c pnMantissa is
|
||||
and set an overflow error if it doesn't fit.
|
||||
|
||||
See also QCBORDecode_GetInt64ConvertAll(),
|
||||
QCBORDecode_GetUInt64ConvertAll() and
|
||||
QCBORDecode_GetDoubleConvertAll() which can convert big floats.
|
||||
|
@ -1979,21 +1993,28 @@ QCBORDecode_GetDoubleInMapSZ(QCBORDecodeContext *pMe,
|
|||
|
||||
|
||||
|
||||
// Semi private (this may change in the future)
|
||||
#define QCBOR_TAGSPEC_NUM_TYPES 4
|
||||
/* Improvement: Carefully understand what compilers do with this,
|
||||
particularly initialization and see if it can be optimized so
|
||||
there is less code and maybe so it can be smaller. */
|
||||
/* Semi-private data structure (which might change).
|
||||
*
|
||||
* See CheckTagRequirement() which uses this to check the type of a
|
||||
* item to be decoded as a tag or tag content.
|
||||
*
|
||||
* Improvement: Carefully understand what compilers do with this,
|
||||
* particularly initialization and see if it can be optimized so there
|
||||
* is less code and maybe so it can be smaller.
|
||||
*/
|
||||
typedef struct {
|
||||
/* One of QCBOR_TAGSPEC_MATCH_xxx */
|
||||
uint8_t uTagRequirement;
|
||||
/* The tagged type translated into QCBOR_TYPE_XXX. Used to match explicit
|
||||
tagging */
|
||||
/* The tagged type translated into QCBOR_TYPE_XXX. Used to match
|
||||
* explicit tagging */
|
||||
uint8_t uTaggedTypes[QCBOR_TAGSPEC_NUM_TYPES];
|
||||
/* The types of the content, which are used to match implicit tagging */
|
||||
/* The types of the content, which are used to match implicit
|
||||
* tagging */
|
||||
uint8_t uAllowedContentTypes[QCBOR_TAGSPEC_NUM_TYPES];
|
||||
} TagSpecification;
|
||||
|
||||
|
||||
// Semi private
|
||||
void QCBORDecode_GetTaggedStringInternal(QCBORDecodeContext *pMe,
|
||||
TagSpecification TagSpec,
|
||||
|
|
|
@ -41,7 +41,8 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
when who what, where, why
|
||||
-------- ---- ---------------------------------------------------
|
||||
4/11/2022 llundblade Add GetOutPlace and Advance to UsefulOutBuf
|
||||
19/12/2022 llundblade Don't pass NULL to memmove when adding empty data.
|
||||
4/11/2022 llundblade Add GetOutPlace and Advance to UsefulOutBuf
|
||||
3/6/2021 mcr/llundblade Fix warnings related to --Wcast-qual
|
||||
01/28/2020 llundblade Refine integer signedness to quiet static analysis.
|
||||
01/08/2020 llundblade Documentation corrections & improved code formatting.
|
||||
|
@ -254,22 +255,23 @@ void UsefulOutBuf_InsertUsefulBuf(UsefulOutBuf *pMe, UsefulBufC NewData, size_t
|
|||
}
|
||||
|
||||
/* 3. Slide existing data to the right */
|
||||
uint8_t *pSourceOfMove = ((uint8_t *)pMe->UB.ptr) + uInsertionPos; // PtrMath #1
|
||||
size_t uNumBytesToMove = pMe->data_len - uInsertionPos; // PtrMath #2
|
||||
uint8_t *pDestinationOfMove = pSourceOfMove + NewData.len; // PtrMath #3
|
||||
if (!UsefulOutBuf_IsBufferNULL(pMe)) {
|
||||
uint8_t *pSourceOfMove = ((uint8_t *)pMe->UB.ptr) + uInsertionPos; // PtrMath #1
|
||||
size_t uNumBytesToMove = pMe->data_len - uInsertionPos; // PtrMath #2
|
||||
uint8_t *pDestinationOfMove = pSourceOfMove + NewData.len; // PtrMath #3
|
||||
|
||||
if(uNumBytesToMove && pMe->UB.ptr) {
|
||||
// To know memmove won't go off end of destination, see PtrMath #4
|
||||
// Use memove because it handles overlapping buffers
|
||||
memmove(pDestinationOfMove, pSourceOfMove, uNumBytesToMove);
|
||||
|
||||
/* 4. Put the new data in */
|
||||
uint8_t *pInsertionPoint = pSourceOfMove;
|
||||
// To know memmove won't go off end of destination, see PtrMath #5
|
||||
if(NewData.ptr != NULL) {
|
||||
memmove(pInsertionPoint, NewData.ptr, NewData.len);
|
||||
}
|
||||
}
|
||||
|
||||
/* 4. Put the new data in */
|
||||
uint8_t *pInsertionPoint = ((uint8_t *)pMe->UB.ptr) + uInsertionPos; // PtrMath #5
|
||||
if(pMe->UB.ptr) {
|
||||
// To know memmove won't go off end of destination, see PtrMath #6
|
||||
memmove(pInsertionPoint, NewData.ptr, NewData.len);
|
||||
}
|
||||
pMe->data_len += NewData.len;
|
||||
}
|
||||
|
||||
|
@ -295,9 +297,7 @@ void UsefulOutBuf_InsertUsefulBuf(UsefulOutBuf *pMe, UsefulBufC NewData, size_t
|
|||
Check #3 allows Check #2 to be refactored as NewData.Len > (me->size - uInsertionPos)
|
||||
This algebraically rearranges to me->size > uInsertionPos + NewData.len
|
||||
|
||||
PtrMath #5 is exactly the same as PtrMath #1
|
||||
|
||||
PtrMath #6 will never wrap under because
|
||||
PtrMath #5 will never wrap under because
|
||||
Calculation for extent of memove is uRoomInDestination = me->UB.len - uInsertionPos;
|
||||
Check #1 makes sure me->data_len is less than me->size
|
||||
Check #3 makes sure uInsertionPos is less than me->data_len
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -658,8 +658,13 @@ void QCBOREncode_AddInt64(QCBOREncodeContext *me, int64_t nNum)
|
|||
uint64_t uValue;
|
||||
|
||||
if(nNum < 0) {
|
||||
/* In CBOR -1 encodes as 0x00 with major type negative int. */
|
||||
uValue = (uint64_t)(-nNum - 1);
|
||||
/* In CBOR -1 encodes as 0x00 with major type negative int.
|
||||
* First add one as a signed integer because that will not
|
||||
* overflow. Then change the sign as needed for encoding. (The
|
||||
* opposite order, changing the sign and subtracting, can cause
|
||||
* an overflow when encoding INT64_MIN. */
|
||||
int64_t nTmp = nNum + 1;
|
||||
uValue = (uint64_t)-nTmp;
|
||||
uMajorType = CBOR_MAJOR_TYPE_NEGATIVE_INT;
|
||||
} else {
|
||||
uValue = (uint64_t)nNum;
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
#-------------------------------------------------------------------------------
|
||||
# Copyright (c) 2022-2023, Arm Limited. All rights reserved.
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
# See BSD-3-Clause license in README.md
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
# Validate value of BUILD_QCBOR_TEST config option
|
||||
if ((NOT BUILD_QCBOR_TEST STREQUAL "LIB") AND (NOT BUILD_QCBOR_TEST STREQUAL "APP"))
|
||||
message(FATAL_ERROR "QCBOR | Invalid Config: BUILD_QCBOR_TEST=${BUILD_QCBOR_TEST}")
|
||||
endif()
|
||||
|
||||
add_library(qcbor_test STATIC)
|
||||
|
||||
target_sources(qcbor_test
|
||||
PRIVATE
|
||||
float_tests.c
|
||||
half_to_double_from_rfc7049.c
|
||||
qcbor_decode_tests.c
|
||||
qcbor_encode_tests.c
|
||||
run_tests.c
|
||||
UsefulBuf_Tests.c
|
||||
)
|
||||
|
||||
target_include_directories(qcbor_test
|
||||
PUBLIC
|
||||
.
|
||||
PRIVATE
|
||||
../inc
|
||||
)
|
||||
|
||||
target_compile_definitions(qcbor_test
|
||||
PUBLIC
|
||||
$<$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_HW_USE}>:QCBOR_DISABLE_FLOAT_HW_USE>
|
||||
$<$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_PREFERRED}>:QCBOR_DISABLE_PREFERRED_FLOAT>
|
||||
$<$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_ALL}>:USEFULBUF_DISABLE_ALL_FLOAT>
|
||||
)
|
||||
|
||||
target_link_libraries(qcbor_test
|
||||
PRIVATE
|
||||
qcbor
|
||||
# The math library is needed for floating-point support.
|
||||
# To avoid need for it #define QCBOR_DISABLE_FLOAT_HW_USE
|
||||
# Using GCC
|
||||
$<$<AND:$<STREQUAL:${CMAKE_C_COMPILER_ID},"GNU">,$<NOT:$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_HW_USE}>>>:m>
|
||||
)
|
||||
|
||||
if (BUILD_QCBOR_TEST STREQUAL "APP")
|
||||
add_executable(qcbortest)
|
||||
|
||||
target_sources(qcbortest
|
||||
PRIVATE
|
||||
../cmd_line_main.c
|
||||
../example.c
|
||||
../ub-example.c
|
||||
)
|
||||
|
||||
target_include_directories(qcbortest
|
||||
PRIVATE
|
||||
../
|
||||
)
|
||||
|
||||
target_link_libraries(qcbortest
|
||||
PRIVATE
|
||||
qcbor
|
||||
qcbor_test
|
||||
)
|
||||
endif()
|
|
@ -57,6 +57,12 @@ const char *AddStuffToUOB(UsefulOutBuf *pUOB)
|
|||
/* add a space to end */
|
||||
UsefulOutBuf_AppendByte(pUOB, ' ');
|
||||
|
||||
/* Add an empty string */
|
||||
UsefulOutBuf_AppendUsefulBuf(pUOB, NULLUsefulBufC);
|
||||
|
||||
/* Add a zero length string (valid pointer, 0 length) */
|
||||
UsefulOutBuf_AppendData(pUOB, "xxx", 0);
|
||||
|
||||
/* Add 6 bytes to the end */
|
||||
UsefulBufC UBC = {"hunny ", 6};
|
||||
UsefulOutBuf_AppendUsefulBuf(pUOB, UBC);
|
||||
|
|
|
@ -127,7 +127,7 @@ inline static bool CheckDouble(double d, uint64_t u)
|
|||
}
|
||||
|
||||
|
||||
int32_t HalfPrecisionDecodeBasicTests()
|
||||
int32_t HalfPrecisionDecodeBasicTests(void)
|
||||
{
|
||||
UsefulBufC HalfPrecision = UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spExpectedHalf);
|
||||
|
||||
|
@ -247,7 +247,7 @@ int32_t HalfPrecisionDecodeBasicTests()
|
|||
|
||||
|
||||
|
||||
int32_t HalfPrecisionAgainstRFCCodeTest()
|
||||
int32_t HalfPrecisionAgainstRFCCodeTest(void)
|
||||
{
|
||||
for(uint32_t uHalfP = 0; uHalfP < 0xffff; uHalfP += 60) {
|
||||
unsigned char x[2];
|
||||
|
@ -441,7 +441,7 @@ static const uint8_t spExpectedSmallest[] = {
|
|||
#define MAKE_DOUBLE(x) UsefulBufUtil_CopyUint64ToDouble(x)
|
||||
|
||||
|
||||
int32_t DoubleAsSmallestTest()
|
||||
int32_t DoubleAsSmallestTest(void)
|
||||
{
|
||||
UsefulBuf_MAKE_STACK_UB(EncodedHalfsMem, sizeof(spExpectedSmallest));
|
||||
|
||||
|
@ -700,7 +700,7 @@ static const uint8_t spExpectedFloatsNoHalf[] = {
|
|||
0x18, 0x6A,
|
||||
0xFA, 0x00, 0x00, 0x00, 0x00};
|
||||
|
||||
int32_t GeneralFloatEncodeTests()
|
||||
int32_t GeneralFloatEncodeTests(void)
|
||||
{
|
||||
UsefulBufC ExpectedFloats;
|
||||
#ifndef QCBOR_DISABLE_PREFERRED_FLOAT
|
||||
|
@ -774,7 +774,7 @@ static int CHECK_EXPECTED_DOUBLE(double val, double expected)
|
|||
#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
|
||||
|
||||
|
||||
int32_t GeneralFloatDecodeTests()
|
||||
int32_t GeneralFloatDecodeTests(void)
|
||||
{
|
||||
QCBORItem Item;
|
||||
QCBORError uErr;
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
#ifndef not_well_formed_cbor_h
|
||||
#define not_well_formed_cbor_h
|
||||
|
||||
#include <stdint.h> // for size_t and uint8_t
|
||||
#include <stddef.h> // for size_t
|
||||
#include <stdint.h> // for uint8_t
|
||||
|
||||
|
||||
struct someBinaryBytes {
|
||||
|
@ -50,8 +51,10 @@ static const struct someBinaryBytes paNotWellFormedCBOR[] = {
|
|||
{(uint8_t[]){0x5f, 0x80, 0xff}, 3},
|
||||
// indefinite length byte string with an map chunk
|
||||
{(uint8_t[]){0x5f, 0xa0, 0xff}, 3},
|
||||
#ifndef QCBOR_DISABLE_TAGS
|
||||
// indefinite length byte string with tagged integer chunk
|
||||
{(uint8_t[]){0x5f, 0xc0, 0x00, 0xff}, 4},
|
||||
#endif /* QCBOR_DISABLE_TAGS */
|
||||
// indefinite length byte string with an simple type chunk
|
||||
{(uint8_t[]){0x5f, 0xe0, 0xff}, 3},
|
||||
// indefinite length byte string with indefinite string inside
|
||||
|
@ -246,11 +249,12 @@ static const struct someBinaryBytes paNotWellFormedCBOR[] = {
|
|||
{(uint8_t[]){0x1f}, 1},
|
||||
// Negative integer with "argument" an indefinite length
|
||||
{(uint8_t[]){0x3f}, 1},
|
||||
#ifndef QCBOR_DISABLE_TAGS
|
||||
// CBOR tag with "argument" an indefinite length
|
||||
{(uint8_t[]){0xdf, 0x00}, 2},
|
||||
// CBOR tag with "argument" an indefinite length alternate vector
|
||||
{(uint8_t[]){0xdf}, 1},
|
||||
|
||||
#endif /* QCBOR_DISABLE_TAGS */
|
||||
|
||||
// Missing content bytes from a definite length string
|
||||
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,7 +1,7 @@
|
|||
/*==============================================================================
|
||||
Copyright (c) 2016-2018, The Linux Foundation.
|
||||
Copyright (c) 2018-2021, Laurence Lundblade.
|
||||
All rights reserved.
|
||||
Copyright (c) 2022, Arm Limited. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
|
@ -143,7 +143,7 @@ static uint8_t spBigBuf[2200];
|
|||
/*
|
||||
Some very minimal tests.
|
||||
*/
|
||||
int32_t BasicEncodeTest()
|
||||
int32_t BasicEncodeTest(void)
|
||||
{
|
||||
// Very simple CBOR, a map with one boolean that is true in it
|
||||
QCBOREncodeContext EC;
|
||||
|
@ -281,7 +281,7 @@ int32_t BasicEncodeTest()
|
|||
|
||||
|
||||
static const uint8_t spExpectedEncodedAll[] = {
|
||||
0x98, 0x22, 0x66, 0x55, 0x49, 0x4e, 0x54, 0x36, 0x32, 0xd8,
|
||||
0x98, 0x23, 0x66, 0x55, 0x49, 0x4e, 0x54, 0x36, 0x32, 0xd8,
|
||||
0x64, 0x1a, 0x05, 0x5d, 0x23, 0x15, 0x65, 0x49, 0x4e, 0x54,
|
||||
0x36, 0x34, 0xd8, 0x4c, 0x1b, 0x00, 0x00, 0x00, 0x12, 0x16,
|
||||
0xaf, 0x2b, 0x15, 0x00, 0x38, 0x2b, 0xa4, 0x63, 0x4c, 0x42,
|
||||
|
@ -296,12 +296,14 @@ static const uint8_t spExpectedEncodedAll[] = {
|
|||
0x69, 0x65, 0xc1, 0x1a, 0x53, 0x72, 0x4e, 0x00, 0x66, 0x74,
|
||||
0x69, 0x6d, 0x65, 0x28, 0x29, 0xc1, 0x1a, 0x58, 0x0d, 0x41,
|
||||
0x72, 0x39, 0x07, 0xb0, 0xc1, 0x1a, 0x58, 0x0d, 0x3f, 0x76,
|
||||
0x42, 0xff, 0x00, 0xa3, 0x66, 0x62, 0x69, 0x6e, 0x62, 0x69,
|
||||
0x6e, 0xda, 0x00, 0x01, 0x86, 0xa0, 0x41, 0x00, 0x66, 0x62,
|
||||
0x42, 0xff, 0x00, 0xa4, 0x66, 0x62, 0x69, 0x6e, 0x62, 0x69,
|
||||
0x6e, 0xda, 0x00, 0x01, 0x86, 0xa0, 0x41, 0x00,
|
||||
0x65, 0x65, 0x6D, 0x70, 0x74, 0x79, 0x40,
|
||||
0x66, 0x62,
|
||||
0x6c, 0x61, 0x62, 0x65, 0x6c, 0x43, 0x01, 0x02, 0x03, 0x00,
|
||||
0x44, 0x04, 0x02, 0x03, 0xfe, 0x6f, 0x62, 0x61, 0x72, 0x20,
|
||||
0x62, 0x61, 0x72, 0x20, 0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61,
|
||||
0x72, 0x64, 0x6f, 0x6f, 0x66, 0x0a, 0xd8, 0x20, 0x78, 0x6b,
|
||||
0x72, 0x64, 0x6f, 0x6f, 0x66, 0x0a, 0x60, 0xd8, 0x20, 0x78, 0x6b,
|
||||
0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x73, 0x74, 0x61,
|
||||
0x63, 0x6b, 0x6f, 0x76, 0x65, 0x72, 0x66, 0x6c, 0x6f, 0x77,
|
||||
0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x71, 0x75, 0x65, 0x73, 0x74,
|
||||
|
@ -553,6 +555,7 @@ static void AddAll(QCBOREncodeContext *pECtx)
|
|||
QCBOREncode_AddSZString(pECtx, "binbin");
|
||||
QCBOREncode_AddTag(pECtx, 100000);
|
||||
QCBOREncode_AddBytes(pECtx, ((UsefulBufC) {(uint8_t []){0x00}, 1}));
|
||||
QCBOREncode_AddBytesToMap(pECtx, "empty", NULLUsefulBufC); // Empty string
|
||||
QCBOREncode_AddBytesToMap(pECtx, "blabel", ((UsefulBufC) {(uint8_t []){0x01, 0x02, 0x03}, 3}));
|
||||
QCBOREncode_AddBytesToMapN(pECtx, 0, ((UsefulBufC){(uint8_t []){0x04, 0x02, 0x03, 0xfe}, 4}));
|
||||
QCBOREncode_CloseMap(pECtx);
|
||||
|
@ -560,6 +563,8 @@ static void AddAll(QCBOREncodeContext *pECtx)
|
|||
/* text blobs */
|
||||
QCBOREncode_AddText(pECtx, UsefulBuf_FROM_SZ_LITERAL("bar bar foo bar"));
|
||||
QCBOREncode_AddSZString(pECtx, "oof\n");
|
||||
QCBOREncode_AddText(pECtx, NULLUsefulBufC); // Empty string
|
||||
|
||||
const char *szURL =
|
||||
"http://stackoverflow.com/questions/28059697/how-do-i-toggle-between-debug-and-release-builds-in-xcode-6-7-8";
|
||||
QCBOREncode_AddURI(pECtx, UsefulBuf_FromSZ(szURL));
|
||||
|
@ -686,7 +691,7 @@ static void AddAll(QCBOREncodeContext *pECtx)
|
|||
}
|
||||
|
||||
|
||||
int32_t AllAddMethodsTest()
|
||||
int32_t AllAddMethodsTest(void)
|
||||
{
|
||||
/* Improvement: this test should be broken down into several so it is more
|
||||
* managable. Tags and labels could be more sensible */
|
||||
|
@ -814,7 +819,7 @@ static const uint8_t spExpectedEncodedInts[] = {
|
|||
to expected values generated from http://cbor.me.
|
||||
|
||||
*/
|
||||
int32_t IntegerValuesTest1()
|
||||
int32_t IntegerValuesTest1(void)
|
||||
{
|
||||
QCBOREncodeContext ECtx;
|
||||
int nReturn = 0;
|
||||
|
@ -899,7 +904,7 @@ int32_t IntegerValuesTest1()
|
|||
static const uint8_t spExpectedEncodedSimple[] = {
|
||||
0x85, 0xf5, 0xf4, 0xf6, 0xf7, 0xa1, 0x65, 0x55, 0x4e, 0x44, 0x65, 0x66, 0xf7};
|
||||
|
||||
int32_t SimpleValuesTest1()
|
||||
int32_t SimpleValuesTest1(void)
|
||||
{
|
||||
QCBOREncodeContext ECtx;
|
||||
int nReturn = 0;
|
||||
|
@ -946,7 +951,7 @@ int32_t SimpleValuesTest1()
|
|||
static const uint8_t spExpectedEncodedSimpleIndefiniteLength[] = {
|
||||
0x9f, 0xf5, 0xf4, 0xf6, 0xf7, 0xbf, 0x65, 0x55, 0x4e, 0x44, 0x65, 0x66, 0xf7, 0xff, 0xff};
|
||||
|
||||
int32_t SimpleValuesIndefiniteLengthTest1()
|
||||
int32_t SimpleValuesIndefiniteLengthTest1(void)
|
||||
{
|
||||
QCBOREncodeContext ECtx;
|
||||
int nReturn = 0;
|
||||
|
@ -1141,7 +1146,7 @@ static const uint8_t EncodeLengthThirtyone[] = {
|
|||
0x31
|
||||
};
|
||||
|
||||
int32_t EncodeLengthThirtyoneTest()
|
||||
int32_t EncodeLengthThirtyoneTest(void)
|
||||
{
|
||||
QCBOREncodeContext ECtx;
|
||||
int nReturn = 0;
|
||||
|
@ -1234,7 +1239,7 @@ static const uint8_t spExpectedEncodedDates[] = {
|
|||
0x30, 0x2E, 0x35, 0x32, 0x5A, 0x62, 0x53, 0x59, 0xD8, 0x64,
|
||||
0x39, 0x29, 0xB3, 0x18, 0x2D, 0x19, 0x0F, 0x9A};
|
||||
|
||||
int32_t EncodeDateTest()
|
||||
int32_t EncodeDateTest(void)
|
||||
{
|
||||
QCBOREncodeContext ECtx;
|
||||
|
||||
|
@ -1291,7 +1296,7 @@ int32_t EncodeDateTest()
|
|||
}
|
||||
|
||||
|
||||
int32_t ArrayNestingTest1()
|
||||
int32_t ArrayNestingTest1(void)
|
||||
{
|
||||
QCBOREncodeContext ECtx;
|
||||
int i;
|
||||
|
@ -1314,7 +1319,7 @@ int32_t ArrayNestingTest1()
|
|||
|
||||
|
||||
|
||||
int32_t ArrayNestingTest2()
|
||||
int32_t ArrayNestingTest2(void)
|
||||
{
|
||||
QCBOREncodeContext ECtx;
|
||||
int i;
|
||||
|
@ -1338,7 +1343,7 @@ int32_t ArrayNestingTest2()
|
|||
|
||||
|
||||
|
||||
int32_t ArrayNestingTest3()
|
||||
int32_t ArrayNestingTest3(void)
|
||||
{
|
||||
QCBOREncodeContext ECtx;
|
||||
int i;
|
||||
|
@ -1455,7 +1460,7 @@ static const uint8_t spEncodeRawExpected[] = {
|
|||
0xff, 0xff};
|
||||
|
||||
|
||||
int32_t EncodeRawTest()
|
||||
int32_t EncodeRawTest(void)
|
||||
{
|
||||
QCBOREncodeContext ECtx;
|
||||
|
||||
|
@ -1578,7 +1583,7 @@ static const uint8_t spValidMapEncoded[] = {
|
|||
0x73 } ;
|
||||
|
||||
|
||||
int32_t MapEncodeTest()
|
||||
int32_t MapEncodeTest(void)
|
||||
{
|
||||
uint8_t *pEncodedMaps;
|
||||
size_t nEncodedMapLen;
|
||||
|
@ -1734,7 +1739,7 @@ static const uint8_t spExpectedRTIC[] = {
|
|||
0xaa, 0xbb, 0x01, 0x01};
|
||||
|
||||
|
||||
int32_t RTICResultsTest()
|
||||
int32_t RTICResultsTest(void)
|
||||
{
|
||||
const UsefulBufC Encoded = FormatRTICResults(CBOR_SIMPLEV_FALSE, 1477263730,
|
||||
"recent", "0xA1eC5001",
|
||||
|
@ -1772,7 +1777,7 @@ static const uint8_t spExpectedForBstrWrapCancel[] = {0x82, 0x19, 0x01, 0xC3, 0x
|
|||
/*
|
||||
* bstr wrapping test
|
||||
*/
|
||||
int BstrWrapTest()
|
||||
int32_t BstrWrapTest(void)
|
||||
{
|
||||
QCBOREncodeContext EC;
|
||||
|
||||
|
@ -1896,7 +1901,7 @@ int BstrWrapTest()
|
|||
|
||||
|
||||
|
||||
int32_t BstrWrapErrorTest()
|
||||
int32_t BstrWrapErrorTest(void)
|
||||
{
|
||||
QCBOREncodeContext EC;
|
||||
UsefulBufC Wrapped;
|
||||
|
@ -1963,7 +1968,7 @@ int32_t BstrWrapErrorTest()
|
|||
if(uError != QCBOR_ERR_ARRAY_NESTING_TOO_DEEP) {
|
||||
return (int32_t)(300 + uError);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -2207,7 +2212,7 @@ static int32_t DecodeNextNested2(UsefulBufC Wrapped)
|
|||
}
|
||||
|
||||
|
||||
int32_t BstrWrapNestTest()
|
||||
int32_t BstrWrapNestTest(void)
|
||||
{
|
||||
QCBOREncodeContext EC;
|
||||
QCBOREncode_Init(&EC, UsefulBuf_FROM_BYTE_ARRAY(spBigBuf));
|
||||
|
@ -2350,7 +2355,7 @@ static const uint8_t pProtectedHeaders[] = {0xa1, 0x01, 0x26};
|
|||
C.2.1. This doesn't actually verify the signature (however
|
||||
the t_cose implementation does).
|
||||
*/
|
||||
int32_t CoseSign1TBSTest()
|
||||
int32_t CoseSign1TBSTest(void)
|
||||
{
|
||||
// All of this is from RFC 8152 C.2.1
|
||||
const char *szKid = "11";
|
||||
|
@ -2474,7 +2479,7 @@ int32_t CoseSign1TBSTest()
|
|||
}
|
||||
|
||||
|
||||
int32_t EncodeErrorTests()
|
||||
int32_t EncodeErrorTests(void)
|
||||
{
|
||||
QCBOREncodeContext EC;
|
||||
QCBORError uErr;
|
||||
|
@ -2767,7 +2772,7 @@ static const uint8_t spExpectedExponentAndMantissaMap[] = {
|
|||
};
|
||||
|
||||
|
||||
int32_t ExponentAndMantissaEncodeTests()
|
||||
int32_t ExponentAndMantissaEncodeTests(void)
|
||||
{
|
||||
QCBOREncodeContext EC;
|
||||
UsefulBufC EncodedExponentAndMantissa;
|
||||
|
@ -2879,7 +2884,7 @@ int32_t ExponentAndMantissaEncodeTests()
|
|||
#endif /* QCBOR_DISABLE_EXP_AND_MANTISSA */
|
||||
|
||||
|
||||
int32_t QCBORHeadTest()
|
||||
int32_t QCBORHeadTest(void)
|
||||
{
|
||||
/* This test doesn't have to be extensive, because just about every
|
||||
* other test exercises QCBOREncode_EncodeHead().
|
||||
|
|
|
@ -99,8 +99,11 @@ static test_entry s_tests[] = {
|
|||
TEST_ENTRY(BasicEncodeTest),
|
||||
TEST_ENTRY(NestedMapTest),
|
||||
TEST_ENTRY(BignumParseTest),
|
||||
#ifndef QCBOR_DISABLE_TAGS
|
||||
TEST_ENTRY(OptTagParseTest),
|
||||
TEST_ENTRY(DateParseTest),
|
||||
TEST_ENTRY(DecodeTaggedTypeTests),
|
||||
#endif /* QCBOR_DISABLE_TAGS */
|
||||
TEST_ENTRY(SpiffyDateDecodeTest),
|
||||
TEST_ENTRY(ShortBufferParseTest2),
|
||||
TEST_ENTRY(ShortBufferParseTest),
|
||||
|
@ -136,12 +139,12 @@ static test_entry s_tests[] = {
|
|||
TEST_ENTRY(EncodeLengthThirtyoneTest),
|
||||
TEST_ENTRY(CBORSequenceDecodeTests),
|
||||
TEST_ENTRY(IntToTests),
|
||||
TEST_ENTRY(DecodeTaggedTypeTests),
|
||||
TEST_ENTRY(PeekAndRewindTest),
|
||||
#ifndef QCBOR_DISABLE_EXP_AND_MANTISSA
|
||||
TEST_ENTRY(EncodeLengthThirtyoneTest),
|
||||
#ifndef QCBOR_DISABLE_EXP_AND_MANTISSA
|
||||
TEST_ENTRY(ExponentAndMantissaDecodeTests),
|
||||
#ifndef QCBOR_DISABLE_TAGS
|
||||
TEST_ENTRY(ExponentAndMantissaDecodeFailTests),
|
||||
#endif /* QCBOR_DISABLE_TAGS */
|
||||
TEST_ENTRY(ExponentAndMantissaEncodeTests),
|
||||
#endif /* QCBOR_DISABLE_EXP_AND_MANTISSA */
|
||||
TEST_ENTRY(ParseEmptyMapInMapTest),
|
||||
|
|
|
@ -214,7 +214,7 @@ ExpandxUBAdaptor(const UsefulBufC Input,
|
|||
|
||||
#define INPUT "xyz123xyz"
|
||||
|
||||
int32_t RunUsefulBufExample()
|
||||
int32_t RunUsefulBufExample(void)
|
||||
{
|
||||
/* ------------ UsefulBuf examples ------------- */
|
||||
UsefulBufC Input = UsefulBuf_FROM_SZ_LITERAL(INPUT);
|
||||
|
|
|
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|||
|
||||
[5.0.0-dev2]: https://github.com/microsoft/CCF/releases/tag/ccf-5.0.0-dev2
|
||||
|
||||
- Updated QCBOR from `1.1` to `1.2`.
|
||||
- Upgrade `nghttp2` from `1.51.0` to `1.55.1`.
|
||||
|
||||
## [5.0.0-dev1]
|
||||
|
|
|
@ -141,7 +141,7 @@
|
|||
"type": "git",
|
||||
"git": {
|
||||
"repositoryUrl": "https://github.com/laurencelundblade/QCBOR",
|
||||
"commitHash": "07653df2bbdb2d090d98d0df514fa019ac23dff3"
|
||||
"commitHash": "92d3f89030baff4af7be8396c563e6c8ef263622"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
Загрузка…
Ссылка в новой задаче