pax_global_header00006660000000000000000000000064151453727630014527gustar00rootroot0000000000000052 comment=6442e749ca811e24afad1551338a45c75e09808f intel-tinycbor-6442e74/000077500000000000000000000000001514537276300147525ustar00rootroot00000000000000intel-tinycbor-6442e74/.appveyor.yml000066400000000000000000000020201514537276300174120ustar00rootroot00000000000000version: build-{build} pull_requests: do_not_increment_build_number: true image: - Visual Studio 2019 - Visual Studio 2022 install: - cmd: >- if /i "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2019" (call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64) & (set QTDIR=C:\Qt\6.5\msvc2019_64) if /i "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2022" (call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat") & (set QTDIR=C:\Qt\6.8\msvc2022_64) set path=%PATH%;%QTDIR%\bin build_script: - cmd: >- cmake -S. -Bbuild -GNinja -DWITH_CBOR2JSON=OFF -DBUILD_TESTING=ON -DCMAKE_C_FLAGS="-W3 -Os -MDd" -DCMAKE_CXX_FLAGS="-W3 -O2 -MDd" ninja -C build test_script: - cmd: >- ctest --test-dir build --output-on-failure --output-junit ctest.junitxml after_test: - cmd: >- curl -F file=@build/ctest.junitxml https://ci.appveyor.com/api/testresults/junit/%APPVEYOR_JOB_ID% artifacts: #- path: build\tinycbor.lib deploy: off intel-tinycbor-6442e74/.github/000077500000000000000000000000001514537276300163125ustar00rootroot00000000000000intel-tinycbor-6442e74/.github/dependabot.yml000066400000000000000000000002031514537276300211350ustar00rootroot00000000000000version: 2 updates: - package-ecosystem: github-actions directory: "/" schedule: interval: "daily" target-branch: "main" intel-tinycbor-6442e74/.github/workflows/000077500000000000000000000000001514537276300203475ustar00rootroot00000000000000intel-tinycbor-6442e74/.github/workflows/build.yml000066400000000000000000000101701514537276300221700ustar00rootroot00000000000000name: CI permissions: read-all on: push: branches: [ main, dev ] pull_request: branches: [ main, dev ] # When a PR is updated, cancel the jobs from the previous version. Merges # do not define head_ref, so use run_id to never cancel those jobs. concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true jobs: TinyCBOR: timeout-minutes: 45 # Common environment variables env: HOMEBREW_NO_INSTALL_CLEANUP: 1 HOMEBREW_NO_ANALYTICS: 1 strategy: # Always run all jobs in the matrix, even if one fails. fail-fast: false matrix: os: [ ubuntu-latest ] build_cfg: - name: gcc-no-math cmakeflags: >- -DCMAKE_C_FLAGS="-Os -Werror" -DWITH_FLOATING_POINT=OFF -DWITH_FREESTANDING=ON - name: gcc-freestanding cmakeflags: >- -DCMAKE_C_FLAGS="-Os -Werror" -DWITH_FREESTANDING=ON - name: gcc-small cmakeflags: >- -DBUILD_TESTING=OFF -DCMAKE_C_FLAGS="-Os -Werror" - name: clang-small cmakeflags: >- -DBUILD_TESTING=OFF -DCMAKE_C_COMPILER=clang -DCMAKE_C_FLAGS="-Oz -g -Werror" - name: clang cmakeflags: >- -DBUILD_EXAMPLES=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang -DCMAKE_C_FLAGS_DEBUG="-Werror" -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS_DEBUG="-Werror" - name: linux-g++ cmakeflags: >- -DBUILD_EXAMPLES=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=gcc -DCMAKE_C_FLAGS_DEBUG="-Werror" -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS_DEBUG="-Werror" include: - os: macos-latest build_cfg: name: clang-small cmakeflags: >- -DBUILD_TESTING=OFF -DBUILD_TOOLS=OFF -DCMAKE_C_COMPILER=clang -DCMAKE_C_FLAGS="-Oz -g -Werror" -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS="-O2 -g -Werror" - os: macos-15-intel build_cfg: name: clang cmakeflags: >- -DBUILD_EXAMPLES=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang -DCMAKE_C_FLAGS_DEBUG="-Werror -fsanitize=address" -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS_DEBUG="-Werror -fsanitize=address" -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address" -DCMAKE_MODULE_LINKER_FLAGS="-fsanitize=address" # Default job name is too long to be visible in the "Checks" tab. name: ${{ matrix.os }}/${{ matrix.build_cfg.name }} # The type of runner that the job will run on runs-on: ${{ matrix.os }} steps: - name: Clone tinycbor uses: actions/checkout@v6 - name: install Linux software if: matrix.os == 'ubuntu-latest' run: | # Need a recent Valgrind, otherwise debug info cannot be read. sudo snap install valgrind --classic sudo apt-get update sudo apt-get install -y --no-install-recommends \ doxygen \ cmake \ libc6-dbg \ libcjson-dev \ libfuntools-dev \ ninja-build \ qt6-base-dev - name: install macOS software if: runner.os == 'macOS' run: | brew install -q \ cjson \ cmake \ ninja \ qt - name: Compile run: | set -x cmake -S. -Bbuild -GNinja -DBUILD_TESTING=ON \ ${{ matrix.build_cfg.cmakeflags }} ninja -C build -v if [[ -f build/libtinycbor.a ]]; then size build/libtinycbor.a | tee sizes fi - name: Execute tests run: | ctest --output-on-failure --test-dir build - name: Build docs if: matrix.build_cfg.docs run: ./scripts/update-docs.sh intel-tinycbor-6442e74/.tag000066400000000000000000000000511514537276300155220ustar00rootroot000000000000006442e749ca811e24afad1551338a45c75e09808f intel-tinycbor-6442e74/CMakeLists.txt000066400000000000000000000142361514537276300175200ustar00rootroot00000000000000# /**************************************************************************** # ** # ** Copyright (C) 2015 Intel Corporation # ** # ** Permission is hereby granted, free of charge, to any person obtaining a copy # ** of this software and associated documentation files (the "Software"), to deal # ** in the Software without restriction, including without limitation the rights # ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # ** copies of the Software, and to permit persons to whom the Software is # ** furnished to do so, subject to the following conditions: # ** # ** The above copyright notice and this permission notice shall be included in # ** all copies or substantial portions of the Software. # ** # ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # ** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # ** THE SOFTWARE. # ** # ****************************************************************************/ cmake_minimum_required(VERSION 3.10) project(tinycbor LANGUAGES C CXX VERSION 7.0) # Set path to additional cmake scripts set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) set(TARGETS_EXPORT_NAME "TinyCBOR-targets") option(WITH_FLOATING_POINT "Use floating point code in TinyCBOR" ON) option(WITH_FREESTANDING "Compile TinyCBOR in C freestanding mode" OFF) if(WITH_FLOATING_POINT AND NOT WITH_FREESTANDING) option(WITH_CBOR2JSON "Compile code to convert from CBOR to JSON" ON) option(BUILD_EXAMPLES "Compile the TinyCBOR examples" OFF) option(BUILD_TOOLS "Compile the TinyCBOR tools" ON) endif() # Include additional modules that are used unconditionally include(GNUInstallDirs) include(GenerateExportHeader) include(CheckLinkerFlag) include(CheckSymbolExists) add_library(tinycbor src/cborencoder.c src/cborencoder_close_container_checked.c src/cborerrorstrings.c src/cborparser.c src/cborpretty.c src/cborvalidation.c src/cbor.h ) if(WITH_FREESTANDING) target_compile_options(tinycbor PUBLIC $<$>:-ffreestanding> ) else() target_sources(tinycbor PRIVATE src/cborparser_dup_string.c src/cborpretty_stdio.c ) if(WITH_CBOR2JSON) target_sources(tinycbor PRIVATE src/cbortojson.c ) endif() endif() if(WITH_FLOATING_POINT) target_sources(tinycbor PRIVATE src/cborencoder_float.c src/cborparser_float.c ) if(NOT WIN32) target_link_libraries(tinycbor m) endif() else() target_compile_definitions(tinycbor PUBLIC CBOR_NO_FLOATING_POINT) endif() set_target_properties(tinycbor PROPERTIES # Force this library to link as C and compile as C99, to ensure we # don't use something of a newer language level. LINKER_LANGUAGE C C_EXTENSIONS OFF C_STANDARD 99 # Set version and output name VERSION "0.${PROJECT_VERSION}" SOVERSION "0" ) if(BUILD_SHARED_LIBS) set_target_properties(tinycbor PROPERTIES C_VISIBILITY_PRESET hidden) # Check if the linker supports "-z defs" (a.k.a "--no-undefined") check_linker_flag(C "-Wl,-z,defs" HAVE_NO_UNDEFINED) if(HAVE_NO_UNDEFINED) target_link_options(tinycbor PRIVATE "-Wl,-z,defs") endif() else() target_compile_definitions(tinycbor PUBLIC CBOR_STATIC_DEFINE) endif() # Enable warnings target_compile_options(tinycbor PRIVATE $<$:-W3> $<$>: -Wall -Wextra -Werror=format-security -Werror=incompatible-pointer-types -Werror=implicit-function-declaration -Werror=int-conversion > ) # Generate export macros generate_export_header(tinycbor BASE_NAME "cbor" EXPORT_MACRO_NAME "CBOR_API" EXPORT_FILE_NAME "tinycbor-export.h" ) # Generate version header configure_file(src/tinycbor-version.h.in tinycbor-version.h) # Generate pkgconfig file configure_file(tinycbor.pc.in tinycbor.pc @ONLY) # Check for open_memstream and store the result in HAVE_OPEN_MEMSTREAM check_symbol_exists(open_memstream stdio.h HAVE_OPEN_MEMSTREAM) check_symbol_exists(funopen stdio.h HAVE_OPEN_FUNOPEN) check_symbol_exists(fopencookie stdio.h HAVE_OPEN_FOPENCOOKIE) if(NOT HAVE_OPEN_MEMSTREAM) if (HAVE_OPEN_FUNOPEN) message(STATUS "implementing open_memstream using funopen()") target_compile_definitions(tinycbor PRIVATE HAVE_OPEN_FUNOPEN) target_sources(tinycbor PRIVATE src/open_memstream.c) elseif (HAVE_OPEN_FOPENCOOKIE) message(STATUS "implementing open_memstream using fopencookie()") target_compile_definitions(tinycbor PRIVATE HAVE_OPEN_FOPENCOOKIE) target_sources(tinycbor PRIVATE src/open_memstream.c) else() target_compile_definitions(tinycbor PRIVATE WITHOUT_OPEN_MEMSTREAM) message(WARNING "funopen and fopencookie unavailable, open_memstream can not be implemented and conversion to JSON will not work properly!") endif() endif() target_include_directories(tinycbor PUBLIC "$" PUBLIC "$" PUBLIC "$" ) install(FILES ${PROJECT_SOURCE_DIR}/src/cbor.h ${PROJECT_BINARY_DIR}/tinycbor-version.h ${PROJECT_BINARY_DIR}/tinycbor-export.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tinycbor ) install(FILES ${CMAKE_BINARY_DIR}/tinycbor.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig ) install( TARGETS tinycbor EXPORT "${TARGETS_EXPORT_NAME}" ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} # import library LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} # .so files are libraries RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} # .dll files are binaries INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} # this does not actually install anything (but used by downstream projects) ) set(PROJECT_LIBRARIES TinyCBOR) include(PackageConfig) if(BUILD_EXAMPLES) add_subdirectory(examples) endif() if(BUILD_TESTING) enable_testing() add_subdirectory(tests) endif() if(BUILD_TOOLS) add_subdirectory(tools) endif() intel-tinycbor-6442e74/Doxyfile000066400000000000000000000027411514537276300164640ustar00rootroot00000000000000PROJECT_NAME = "TinyCBOR $(VERSION) API" OUTPUT_DIRECTORY = ../doc ABBREVIATE_BRIEF = SHORT_NAMES = YES JAVADOC_AUTOBRIEF = YES QT_AUTOBRIEF = YES TAB_SIZE = 8 ALIASES = "value=\arg \c" OPTIMIZE_OUTPUT_FOR_C = YES EXTRACT_STATIC = YES EXTRACT_LOCAL_CLASSES = NO HIDE_UNDOC_MEMBERS = YES HIDE_UNDOC_CLASSES = YES GENERATE_TODOLIST = NO GENERATE_TESTLIST = NO GENERATE_BUGLIST = NO GENERATE_DEPRECATEDLIST= NO SHOW_USED_FILES = NO WARN_IF_UNDOCUMENTED = NO WARN_LOGFILE = doxygen.log INPUT = . FILE_PATTERNS = *.h \ *.c \ *.dox EXCLUDE_PATTERNS = *_p.h STRIP_CODE_COMMENTS = NO REFERENCED_BY_RELATION = YES IGNORE_PREFIX = cbor_ \ Cbor HTML_TIMESTAMP = NO GENERATE_HTMLHELP = YES GENERATE_CHI = YES BINARY_TOC = YES TOC_EXPAND = YES MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest SEARCHENGINE = NO GENERATE_LATEX = NO COMPACT_LATEX = YES MACRO_EXPANSION = YES PREDEFINED = DOXYGEN \ CBOR_INLINE_API= CLASS_DIAGRAMS = NO CLASS_GRAPH = NO COLLABORATION_GRAPH = NO GROUP_GRAPHS = NO INCLUDE_GRAPH = NO INCLUDED_BY_GRAPH = NO GRAPHICAL_HIERARCHY = NO DIRECTORY_GRAPH = NO intel-tinycbor-6442e74/LICENSE000066400000000000000000000020621514537276300157570ustar00rootroot00000000000000MIT License Copyright (c) 2017 Intel Corporation Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. intel-tinycbor-6442e74/Makefile.configure000066400000000000000000000026031514537276300203730ustar00rootroot00000000000000ALLTESTS = open_memstream funopen fopencookie gc_sections \ system-cjson cjson freestanding MAKEFILE := $(lastword $(MAKEFILE_LIST)) OUT := PROGRAM-open_memstream = extern int open_memstream(); int main() { return open_memstream(); } PROGRAM-funopen = extern int funopen(); int main() { return funopen(); } PROGRAM-fopencookie = extern int fopencookie(); int main() { return fopencookie(); } PROGRAM-gc_sections = int main() {} CCFLAGS-gc_sections = -Wl,--gc-sections PROGRAM-freestanding = \#if !defined(__STDC_HOSTED__) || __STDC_HOSTED__-0 == 1\n PROGRAM-freestanding += \#error Hosted implementation\n PROGRAM-freestanding += \#endif\n PROGRAM-freestanding += int main() {} CCFLAGS-freestanding = $(CFLAGS) PROGRAM-cjson = \#include \n PROGRAM-cjson += \#include \n PROGRAM-cjson += \#include \n PROGRAM-cjson += int main() { double d = NAN; return cJSON_False; } CCFLAGS-cjson = -I. -I$(dir $(MAKEFILE))src PROGRAM-system-cjson = $(PROGRAM-cjson) CCFLAGS-system-cjson = -I. -lcjson sink: @echo >&2 Please run from the top-level Makefile. configure: $(foreach it,$(ALLTESTS),check-$(it)) check-%: @echo $(subst check-,,$@)-tested := 1 >>$(OUT) $(if $(V),,@)if printf "$($(subst check-,PROGRAM-,$@))" | \ $(CC) -xc $($(subst check-,CCFLAGS-,$@)) -o /dev/null - $(if $(V),,>/dev/null 2>&1); \ then \ echo $(subst check-,,$@)-pass := 1 >>$(OUT); \ fi intel-tinycbor-6442e74/Makefile.nmake000066400000000000000000000025251514537276300175100ustar00rootroot00000000000000CFLAGS = -W3 TINYCBOR_HEADERS = src\cbor.h src\cborjson.h src\tinycbor-export.h TINYCBOR_SOURCES = \ src\cborerrorstrings.c \ src\cborencoder.c \ src\cborencoder_close_container_checked.c \ src\cborencoder_float.c \ src\cborparser.c \ src\cborparser_dup_string.c \ src\cborparser_float.c \ src\cborpretty.c \ src\cborpretty_stdio.c \ src\cborvalidation.c TINYCBOR_OBJS = \ src\cborerrorstrings.obj \ src\cborencoder.obj \ src\cborencoder_close_container_checked.obj \ src\cborencoder_float.obj \ src\cborparser.obj \ src\cborparser_dup_string.obj \ src\cborparser_float.obj \ src\cborpretty.obj \ src\cborpretty_stdio.obj \ src\cborvalidation.obj all: src/tinycbor-export.h lib\tinycbor.lib check: tests\Makefile lib\tinycbor.lib cd tests & $(MAKE) check silentcheck: cd tests & set TESTARGS=-silent & $(MAKE) -s check tests\Makefile: tests\tests.pro qmake -o $@ $** src\tinycbor-export.h: src\tinycbor-export.h.in copy $** $@ lib\tinycbor.lib: $(TINYCBOR_OBJS) -if not exist lib\NUL md lib lib -nologo /out:$@ $** mostlyclean: -del $(TINYCBOR_OBJS) -del src\tinycbor-export.h clean: mostlyclean -del lib\tinycbor.lib if exist tests\Makefile (cd tests & $(MAKE) clean) distclean: clean if exist tests\Makefile (cd tests & $(MAKE) distclean) tag: @perl maketag.pl {src\}.c{src\}.obj: $(CC) -nologo $(CFLAGS) -Isrc -c -Fo$@ $< intel-tinycbor-6442e74/README000066400000000000000000000004631514537276300156350ustar00rootroot00000000000000Concise Binary Object Representation (CBOR) Library --------------------------------------------------- To build TinyCBOR: make If you want to change the compiler or pass extra compiler flags: make CC=clang CFLAGS="-m32 -Oz" LDFLAGS="-m32" Documentation: https://intel.github.io/tinycbor/current/ intel-tinycbor-6442e74/SECURITY.md000066400000000000000000000006251514537276300165460ustar00rootroot00000000000000# Security Policy Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation. ## Reporting a Vulnerability Please report any security vulnerabilities in this project utilizing the guidelines [here](https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html). intel-tinycbor-6442e74/TODO000066400000000000000000000015131514537276300154420ustar00rootroot00000000000000==== To Do list for libcbor ==== === General === * API review * Benchmark * Write examples ** Simple decoder ** Decoder to JSON ** Windowed encoding/decoding (limited memory) === Encoder === * Write API docs * Add API for creating indeterminate-length arrays and maps * Add API for creating indeterminate-length strings * Add API for relaxing doubles to floats and to integers * Add length-checking of the sub-containers (#ifndef CBOR_ENCODER_NO_USER_CHECK) * Decide how to indicate number of bytes needed ** Suggestion: return negative number from the functions === Decoder === * Write functions not yet implemented * Add API for stream-decoding strings * Add API for checking known tags and simple types * (unlikely) Add API for checking the pairing of a tag and the tagged type * Write tests for error conditions * Fuzzy-test the decoder intel-tinycbor-6442e74/cmake/000077500000000000000000000000001514537276300160325ustar00rootroot00000000000000intel-tinycbor-6442e74/cmake/PackageConfig.cmake000066400000000000000000000021101514537276300215070ustar00rootroot00000000000000# This cmake code creates the configuration that is found and used by # find_package() of another cmake project # get lower and upper case project name for the configuration files # configure and install the configuration files include(CMakePackageConfigHelpers) configure_package_config_file( "${PROJECT_SOURCE_DIR}/cmake/project-config.cmake.in" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} #PATH_VARS CMAKE_INSTALL_DIR ) write_basic_package_version_file( "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMinorVersion ) install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" COMPONENT devel DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ) if (PROJECT_LIBRARIES OR PROJECT_STATIC_LIBRARIES) install( EXPORT "${TARGETS_EXPORT_NAME}" FILE ${TARGETS_EXPORT_NAME}.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ) endif () intel-tinycbor-6442e74/cmake/TinyCBORHelpers.cmake000066400000000000000000000023271514537276300217540ustar00rootroot00000000000000# Copyright (C) 2025 Intel Corporation # SPDX-License-Identifier: MIT function(tinycbor_add_executable target) add_executable(${target} ${ARGN}) target_link_libraries(${target} tinycbor) target_compile_options(${target} PRIVATE $<$:-W3> $<$>:-Wall -Wextra> ) endfunction() function(tinycbor_add_test target) tinycbor_add_executable(${target} ${ARGN}) set(memcheck_command ${CMAKE_MEMORYCHECK_COMMAND} ${CMAKE_MEMORYCHECK_COMMAND_OPTIONS}) separate_arguments(memcheck_command) add_test(NAME ${target} COMMAND ${memcheck_command} $) endfunction() function(tinycbor_add_qtest target) tinycbor_add_test(${target} ${ARGN}) target_link_libraries(${target} Qt::Core Qt::Test) endfunction() option(WITH_VALGRIND "Use Valgrind (if found) to run tests" ON) if(WITH_VALGRIND AND NOT DEFINED CMAKE_MEMORYCHECK_COMMAND) find_program(VALGRIND "valgrind") if(VALGRIND) set(CMAKE_MEMORYCHECK_COMMAND ${VALGRIND} --tool=memcheck) set(CMAKE_MEMORYCHECK_COMMAND_OPTIONS} --error-exitcode=255 --errors-for-leak-kinds=definite --leak-check=yes --num-callers=20 ) endif() else() set(VALGRIND OFF) endif() intel-tinycbor-6442e74/cmake/project-config.cmake.in000066400000000000000000000007171514537276300223570ustar00rootroot00000000000000# Config file for @PROJECT_NAME_LOWER@ # # It defines the following variables: # # @PROJECT_NAME_UPPER@_INCLUDE_DIRS - include directory # @PROJECT_NAME_UPPER@_LIBRARIES - all dynamic libraries # @PROJECT_NAME_UPPER@_STATIC_LIBRARIES - all static libraries @PACKAGE_INIT@ include(CMakeFindDependencyMacro) # Add optional dependencies here include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") check_required_components("@PROJECT_NAME@") intel-tinycbor-6442e74/examples/000077500000000000000000000000001514537276300165705ustar00rootroot00000000000000intel-tinycbor-6442e74/examples/CMakeLists.txt000066400000000000000000000002251514537276300213270ustar00rootroot00000000000000# Copyright (C) 2025 Intel Corporation # SPDX-License-Identifier: MIT include(TinyCBORHelpers) tinycbor_add_executable(simplereader simplereader.c) intel-tinycbor-6442e74/examples/simplereader.c000066400000000000000000000110711514537276300214100ustar00rootroot00000000000000#include "../src/cbor.h" #include #include #include #include #include static uint8_t *readfile(const char *fname, size_t *size) { struct stat st; FILE *f = fopen(fname, "rb"); if (!f) return NULL; if (fstat(fileno(f), &st) == -1) return NULL; uint8_t *buf = malloc(st.st_size); if (buf == NULL) return NULL; *size = fread(buf, st.st_size, 1, f) == 1 ? st.st_size : 0; fclose(f); return buf; } static void indent(int nestingLevel) { while (nestingLevel--) printf(" "); } static void dumpbytes(const uint8_t *buf, size_t len) { printf("\""); while (len--) printf("\\x%02X", *buf++); printf("\""); } static CborError dumprecursive(CborValue *it, int nestingLevel) { while (!cbor_value_at_end(it)) { CborError err; CborType type = cbor_value_get_type(it); indent(nestingLevel); switch (type) { case CborArrayType: case CborMapType: { // recursive type CborValue recursed; assert(cbor_value_is_container(it)); puts(type == CborArrayType ? "Array[" : "Map["); err = cbor_value_enter_container(it, &recursed); if (err) return err; // parse error err = dumprecursive(&recursed, nestingLevel + 1); if (err) return err; // parse error err = cbor_value_leave_container(it, &recursed); if (err) return err; // parse error indent(nestingLevel); puts("]"); continue; } case CborIntegerType: { int64_t val; cbor_value_get_int64(it, &val); // can't fail printf("%lld\n", (long long)val); break; } case CborByteStringType: { uint8_t *buf; size_t n; err = cbor_value_dup_byte_string(it, &buf, &n, it); if (err) return err; // parse error dumpbytes(buf, n); puts(""); free(buf); continue; } case CborTextStringType: { char *buf; size_t n; err = cbor_value_dup_text_string(it, &buf, &n, it); if (err) return err; // parse error printf("\"%s\"\n", buf); free(buf); continue; } case CborTagType: { CborTag tag; cbor_value_get_tag(it, &tag); // can't fail printf("Tag(%lld)\n", (long long)tag); break; } case CborSimpleType: { uint8_t type; cbor_value_get_simple_type(it, &type); // can't fail printf("simple(%u)\n", type); break; } case CborNullType: puts("null"); break; case CborUndefinedType: puts("undefined"); break; case CborBooleanType: { bool val; cbor_value_get_boolean(it, &val); // can't fail puts(val ? "true" : "false"); break; } case CborDoubleType: { double val; if (false) { float f; case CborFloatType: cbor_value_get_float(it, &f); val = f; } else { cbor_value_get_double(it, &val); } printf("%g\n", val); break; } case CborHalfFloatType: { uint16_t val; cbor_value_get_half_float(it, &val); printf("__f16(%04x)\n", val); break; } case CborInvalidType: assert(false); // can't happen break; } err = cbor_value_advance_fixed(it); if (err) return err; } return CborNoError; } int main(int argc, char **argv) { if (argc != 2) { puts("simplereader "); return 1; } size_t length; uint8_t *buf = readfile(argv[1], &length); if (!buf) { perror("readfile"); return 1; } CborParser parser; CborValue it; CborError err = cbor_parser_init(buf, length, 0, &parser, &it); if (!err) err = dumprecursive(&it, 0); if (err) { fprintf(stderr, "CBOR parsing failure at offset %ld: %s\n", cbor_value_get_next_byte(&it) - buf, cbor_error_string(err)); free(buf); return 1; } free(buf); return 0; } intel-tinycbor-6442e74/scripts/000077500000000000000000000000001514537276300164415ustar00rootroot00000000000000intel-tinycbor-6442e74/scripts/maketag.pl000066400000000000000000000046361514537276300204200ustar00rootroot00000000000000#!perl use strict; sub run(@) { open PROC, "-|", @_ or die("Cannot run $_[0]: $!"); my @out; while () { chomp; push @out, $_; } close PROC; return @out; } my @tags = run("git", "tag"); my @v = run("git", "show", "HEAD:VERSION"); my $v = $v[0]; my $tagfile = ".git/TAG_EDITMSG"; open TAGFILE, ">", $tagfile or die("Cannot create file for editing tag message: $!"); select TAGFILE; print "TinyCBOR release $v\n"; print "\n"; print "# Write something nice about this release here\n"; # Do we have a commit template? my @result = run("git", "config", "--get", "commit.template"); if (scalar @result) { open TEMPLATE, "<", $result[0]; map { print $_; }