edhoc 1.0.5 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +170 -0
- package/binding.gyp +13 -11
- package/dist/crypto.d.ts +9 -2
- package/dist/crypto.d.ts.map +1 -1
- package/dist/crypto.js +112 -84
- package/dist/edhoc.d.ts +31 -9
- package/dist/edhoc.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/x509credentials.d.ts +20 -0
- package/dist/x509credentials.d.ts.map +1 -0
- package/dist/x509credentials.js +140 -0
- package/external/libedhoc/backends/cbor/include/backend_cbor_bstr_type_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_bstr_type_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_bstr_type_types.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_ead_decode.h +2 -2
- package/external/libedhoc/backends/cbor/include/backend_cbor_ead_encode.h +2 -2
- package/external/libedhoc/backends/cbor/include/backend_cbor_edhoc_types.h +48 -43
- package/external/libedhoc/backends/cbor/include/backend_cbor_enc_structure_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_enc_structure_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_enc_structure_types.h +3 -3
- package/external/libedhoc/backends/cbor/include/backend_cbor_id_cred_x_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_id_cred_x_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_info_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_info_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_int_type_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_int_type_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_int_type_types.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_1_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_1_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_2_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_2_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_3_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_3_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_4_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_4_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_error_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_error_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_2_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_2_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_3_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_3_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_4_decode.h +3 -3
- package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_4_encode.h +3 -3
- package/external/libedhoc/backends/cbor/include/backend_cbor_sig_structure_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_sig_structure_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_sig_structure_types.h +4 -4
- package/external/libedhoc/backends/cbor/include/backend_cbor_x509_types.h +93 -83
- package/external/libedhoc/backends/cbor/src/backend_cbor_bstr_type_decode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_bstr_type_encode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_ead_decode.c +27 -32
- package/external/libedhoc/backends/cbor/src/backend_cbor_ead_encode.c +27 -32
- package/external/libedhoc/backends/cbor/src/backend_cbor_enc_structure_decode.c +14 -23
- package/external/libedhoc/backends/cbor/src/backend_cbor_enc_structure_encode.c +14 -23
- package/external/libedhoc/backends/cbor/src/backend_cbor_id_cred_x_decode.c +63 -52
- package/external/libedhoc/backends/cbor/src/backend_cbor_id_cred_x_encode.c +62 -51
- package/external/libedhoc/backends/cbor/src/backend_cbor_info_decode.c +14 -23
- package/external/libedhoc/backends/cbor/src/backend_cbor_info_encode.c +14 -23
- package/external/libedhoc/backends/cbor/src/backend_cbor_int_type_decode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_int_type_encode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_1_decode.c +54 -51
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_1_encode.c +54 -51
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_2_decode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_2_encode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_3_decode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_3_encode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_4_decode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_4_encode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_error_decode.c +36 -37
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_error_encode.c +36 -37
- package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_2_decode.c +103 -80
- package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_2_encode.c +102 -79
- package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_3_decode.c +99 -76
- package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_3_encode.c +98 -75
- package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_4_decode.c +40 -41
- package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_4_encode.c +40 -41
- package/external/libedhoc/backends/cbor/src/backend_cbor_sig_structure_decode.c +15 -24
- package/external/libedhoc/backends/cbor/src/backend_cbor_sig_structure_encode.c +15 -24
- package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode.c +31 -0
- package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode.h +10 -0
- package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode2.c +18 -0
- package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode2.h +9 -0
- package/external/libedhoc/externals/Unity/examples/example_1/test/TestProductionCode.c +69 -0
- package/external/libedhoc/externals/Unity/examples/example_1/test/TestProductionCode2.c +38 -0
- package/external/libedhoc/externals/Unity/examples/example_1/test/test_runners/TestProductionCode2_Runner.c +53 -0
- package/external/libedhoc/externals/Unity/examples/example_1/test/test_runners/TestProductionCode_Runner.c +57 -0
- package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode.c +31 -0
- package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode.h +10 -0
- package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode2.c +18 -0
- package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode2.h +9 -0
- package/external/libedhoc/externals/Unity/examples/example_2/test/TestProductionCode.c +71 -0
- package/external/libedhoc/externals/Unity/examples/example_2/test/TestProductionCode2.c +40 -0
- package/external/libedhoc/externals/Unity/examples/example_2/test/test_runners/TestProductionCode2_Runner.c +16 -0
- package/external/libedhoc/externals/Unity/examples/example_2/test/test_runners/TestProductionCode_Runner.c +18 -0
- package/external/libedhoc/externals/Unity/examples/example_2/test/test_runners/all_tests.c +19 -0
- package/external/libedhoc/externals/Unity/examples/example_3/helper/UnityHelper.c +17 -0
- package/external/libedhoc/externals/Unity/examples/example_3/helper/UnityHelper.h +19 -0
- package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode.c +31 -0
- package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode.h +10 -0
- package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode2.c +18 -0
- package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode2.h +9 -0
- package/external/libedhoc/externals/Unity/examples/example_3/test/TestProductionCode.c +69 -0
- package/external/libedhoc/externals/Unity/examples/example_3/test/TestProductionCode2.c +38 -0
- package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode.c +31 -0
- package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode.h +10 -0
- package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode2.c +18 -0
- package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode2.h +9 -0
- package/external/libedhoc/externals/Unity/examples/example_4/test/TestProductionCode.c +70 -0
- package/external/libedhoc/externals/Unity/examples/example_4/test/TestProductionCode2.c +42 -0
- package/external/libedhoc/externals/Unity/examples/example_4/test/test_runners/TestProductionCode2_Runner.c +53 -0
- package/external/libedhoc/externals/Unity/examples/example_4/test/test_runners/TestProductionCode_Runner.c +57 -0
- package/external/libedhoc/externals/Unity/examples/unity_config.h +251 -0
- package/external/libedhoc/externals/Unity/extras/bdd/src/unity_bdd.h +44 -0
- package/external/libedhoc/externals/Unity/extras/bdd/test/test_bdd.c +129 -0
- package/external/libedhoc/externals/Unity/extras/fixture/src/unity_fixture.c +310 -0
- package/external/libedhoc/externals/Unity/extras/fixture/src/unity_fixture.h +95 -0
- package/external/libedhoc/externals/Unity/extras/fixture/src/unity_fixture_internals.h +51 -0
- package/external/libedhoc/externals/Unity/extras/fixture/test/main/AllTests.c +20 -0
- package/external/libedhoc/externals/Unity/extras/fixture/test/template_fixture_tests.c +40 -0
- package/external/libedhoc/externals/Unity/extras/fixture/test/unity_fixture_Test.c +246 -0
- package/external/libedhoc/externals/Unity/extras/fixture/test/unity_fixture_TestRunner.c +33 -0
- package/external/libedhoc/externals/Unity/extras/memory/src/unity_memory.c +203 -0
- package/external/libedhoc/externals/Unity/extras/memory/src/unity_memory.h +61 -0
- package/external/libedhoc/externals/Unity/extras/memory/test/unity_memory_Test.c +326 -0
- package/external/libedhoc/externals/Unity/extras/memory/test/unity_memory_TestRunner.c +50 -0
- package/external/libedhoc/externals/Unity/extras/memory/test/unity_output_Spy.c +57 -0
- package/external/libedhoc/externals/Unity/extras/memory/test/unity_output_Spy.h +17 -0
- package/external/libedhoc/externals/Unity/src/unity.c +2501 -0
- package/external/libedhoc/externals/Unity/src/unity.h +698 -0
- package/external/libedhoc/externals/Unity/src/unity_internals.h +1183 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_cmd.c +61 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_def.c +57 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_head1.c +55 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_head1.h +15 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_cmd.c +80 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_def.c +76 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_head1.c +75 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_head1.h +13 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_new1.c +89 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_new2.c +89 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_param.c +77 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_run1.c +89 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_run2.c +89 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_yaml.c +90 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_new1.c +67 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_new2.c +70 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_param.c +58 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_run1.c +67 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_run2.c +70 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_yaml.c +71 -0
- package/external/libedhoc/externals/Unity/test/testdata/CException.h +18 -0
- package/external/libedhoc/externals/Unity/test/testdata/Defs.h +16 -0
- package/external/libedhoc/externals/Unity/test/testdata/cmock.h +21 -0
- package/external/libedhoc/externals/Unity/test/testdata/mockMock.h +20 -0
- package/external/libedhoc/externals/Unity/test/testdata/testRunnerGenerator.c +204 -0
- package/external/libedhoc/externals/Unity/test/testdata/testRunnerGeneratorSmall.c +73 -0
- package/external/libedhoc/externals/Unity/test/testdata/testRunnerGeneratorWithMocks.c +200 -0
- package/external/libedhoc/externals/Unity/test/tests/self_assessment_utils.h +151 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_arrays.c +2941 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_core.c +375 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_doubles.c +1285 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_floats.c +1395 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_integers.c +2863 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_integers_64.c +783 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_memory.c +82 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_parameterized.c +309 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_parameterizedDemo.c +28 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_strings.c +330 -0
- package/external/libedhoc/externals/Unity/test/tests/types_for_test.h +21 -0
- package/external/libedhoc/externals/zcbor/include/zcbor_common.h +147 -60
- package/external/libedhoc/externals/zcbor/include/zcbor_decode.h +291 -202
- package/external/libedhoc/externals/zcbor/include/zcbor_encode.h +100 -156
- package/external/libedhoc/externals/zcbor/include/zcbor_print.h +165 -0
- package/external/libedhoc/externals/zcbor/samples/hello_world/src/main.c +1 -1
- package/external/libedhoc/externals/zcbor/samples/pet/include/pet_decode.h +1 -1
- package/external/libedhoc/externals/zcbor/samples/pet/include/pet_encode.h +1 -1
- package/external/libedhoc/externals/zcbor/samples/pet/include/pet_types.h +4 -4
- package/external/libedhoc/externals/zcbor/samples/pet/src/main.c +4 -4
- package/external/libedhoc/externals/zcbor/samples/pet/src/pet_decode.c +15 -24
- package/external/libedhoc/externals/zcbor/samples/pet/src/pet_encode.c +14 -23
- package/external/libedhoc/externals/zcbor/src/zcbor_common.c +202 -29
- package/external/libedhoc/externals/zcbor/src/zcbor_decode.c +633 -173
- package/external/libedhoc/externals/zcbor/src/zcbor_encode.c +71 -184
- package/external/libedhoc/externals/zcbor/tests/decode/test1_suit_old_formats/src/main.c +152 -153
- package/external/libedhoc/externals/zcbor/tests/decode/test2_suit/src/main.c +64 -64
- package/external/libedhoc/externals/zcbor/tests/decode/test3_simple/src/main.c +15 -16
- package/external/libedhoc/externals/zcbor/tests/decode/test5_corner_cases/src/main.c +228 -84
- package/external/libedhoc/externals/zcbor/tests/decode/test7_suit9_simple/src/main.c +9 -9
- package/external/libedhoc/externals/zcbor/tests/decode/test8_suit12/src/main.c +0 -1
- package/external/libedhoc/externals/zcbor/tests/decode/test9_manifest14/src/main.c +172 -173
- package/external/libedhoc/externals/zcbor/tests/encode/test1_suit/src/main.c +73 -73
- package/external/libedhoc/externals/zcbor/tests/encode/test2_simple/src/main.c +1 -2
- package/external/libedhoc/externals/zcbor/tests/encode/test3_corner_cases/src/main.c +83 -56
- package/external/libedhoc/externals/zcbor/tests/encode/test4_senml/src/main.c +15 -16
- package/external/libedhoc/externals/zcbor/tests/fuzz/fuzz_everything.c +12 -0
- package/external/libedhoc/externals/zcbor/tests/fuzz/fuzz_manifest12.c +69 -69
- package/external/libedhoc/externals/zcbor/tests/unit/test1_unit_tests/src/main.c +448 -55
- package/external/libedhoc/externals/zcbor/tests/unit/test3_float16/src/main.c +49 -48
- package/external/libedhoc/include/edhoc.h +348 -54
- package/external/libedhoc/include/edhoc_common.h +289 -0
- package/external/libedhoc/include/edhoc_context.h +60 -35
- package/external/libedhoc/include/edhoc_credentials.h +55 -7
- package/external/libedhoc/include/edhoc_crypto.h +10 -10
- package/external/libedhoc/include/edhoc_ead.h +13 -10
- package/external/libedhoc/include/edhoc_macros.h +20 -11
- package/external/libedhoc/include/edhoc_values.h +2 -2
- package/external/libedhoc/library/edhoc.c +70 -36
- package/external/libedhoc/library/edhoc_common.c +1314 -0
- package/external/libedhoc/library/edhoc_exporter.c +45 -46
- package/external/libedhoc/library/edhoc_message_1.c +107 -72
- package/external/libedhoc/library/edhoc_message_2.c +396 -1693
- package/external/libedhoc/library/edhoc_message_3.c +465 -1656
- package/external/libedhoc/library/edhoc_message_4.c +93 -91
- package/external/libedhoc/library/edhoc_message_error.c +41 -41
- package/external/libedhoc/tests/include/{cipher_suites/cipher_suite_0.h → cipher_suite_0.h} +131 -134
- package/external/libedhoc/tests/include/{cipher_suites/cipher_suite_2.h → cipher_suite_2.h} +139 -140
- package/external/libedhoc/tests/include/{edhoc_trace_1/test_vector_1.h → test_vector_rfc9529_chapter_2.h} +786 -738
- package/external/libedhoc/tests/include/{edhoc_trace_2/test_vector_2.h → test_vector_rfc9529_chapter_3.h} +14 -10
- package/external/libedhoc/tests/include/{x509_chain_cs_0/test_vector_x5chain_cs_0.h → test_vector_x5chain_sign_keys_suite_0.h} +137 -140
- package/external/libedhoc/tests/include/{x509_chain_cs_2/test_vector_x5chain_cs_2.h → test_vector_x5chain_sign_keys_suite_2.h} +7 -8
- package/external/libedhoc/tests/include/{x509_chain_cs_2_static_dh/test_vector_x5chain_cs_2_static_dh.h → test_vector_x5chain_static_dh_keys_suite_2.h} +7 -8
- package/external/libedhoc/tests/include/{x509_hash_cs_2/test_vector_x5t_cs_2.h → test_vector_x5t_sign_keys_suite_2.h} +6 -7
- package/external/libedhoc/tests/src/{cipher_suites/cipher_suite_0.c → cipher_suite_0.c} +445 -447
- package/external/libedhoc/tests/src/{cipher_suites/cipher_suite_2.c → cipher_suite_2.c} +600 -600
- package/external/libedhoc/tests/src/module_test_api.c +430 -0
- package/external/libedhoc/tests/src/module_test_cipher_suite_0.c +395 -0
- package/external/libedhoc/tests/src/module_test_cipher_suite_2.c +392 -0
- package/external/libedhoc/tests/src/{error_message/test_edhoc_error_message.c → module_test_error_message.c} +94 -69
- package/external/libedhoc/tests/src/module_test_main.c +49 -0
- package/external/libedhoc/tests/src/{cipher_suite_negotiation/test_edhoc_cipher_suite_negotiation.c → module_test_rfc9528_suites_negotiation.c} +224 -227
- package/external/libedhoc/tests/src/module_test_rfc9529_chapter_2.c +2681 -0
- package/external/libedhoc/tests/src/module_test_rfc9529_chapter_3.c +1635 -0
- package/external/libedhoc/tests/src/module_test_x5chain_sign_keys_suite_0.c +1135 -0
- package/external/libedhoc/tests/src/module_test_x5chain_sign_keys_suite_2.c +1249 -0
- package/external/libedhoc/tests/src/module_test_x5chain_static_dh_keys_suite_2.c +798 -0
- package/external/libedhoc/tests/src/module_test_x5t_sign_keys_suite_2.c +956 -0
- package/include/EdhocComposeAsyncWorker.h +8 -6
- package/include/EdhocCredentialManager.h +16 -11
- package/include/EdhocCryptoManager.h +28 -21
- package/include/EdhocEadManager.h +3 -6
- package/include/{EdhocExportAsyncWorker.h → EdhocExportOscoreAsyncWorker.h} +20 -17
- package/include/EdhocKeyExporterAsyncWorker.h +76 -0
- package/include/EdhocKeyUpdateAsyncWorker.h +72 -0
- package/include/EdhocProcessAsyncWorker.h +14 -10
- package/include/LibEDHOC.h +44 -20
- package/include/UserContext.h +7 -9
- package/include/Utils.h +31 -27
- package/package.json +14 -3
- package/prebuilds/android-arm/edhoc.armv7.node +0 -0
- package/prebuilds/android-arm64/edhoc.armv8.node +0 -0
- package/prebuilds/darwin-arm64/edhoc.node +0 -0
- package/prebuilds/darwin-x64/edhoc.node +0 -0
- package/prebuilds/linux-arm/edhoc.armv6.node +0 -0
- package/prebuilds/linux-arm/edhoc.armv7.node +0 -0
- package/prebuilds/linux-arm64/edhoc.armv8.node +0 -0
- package/prebuilds/linux-x64/edhoc.glibc.node +0 -0
- package/prebuilds/linux-x64/edhoc.musl.node +0 -0
- package/prebuilds/win32-ia32/edhoc.node +0 -0
- package/prebuilds/win32-x64/edhoc.node +0 -0
- package/src/EdhocComposeAsyncWorker.cpp +18 -35
- package/src/EdhocCredentialManager.cpp +160 -187
- package/src/EdhocCryptoManager.cpp +386 -586
- package/src/EdhocEadManager.cpp +10 -18
- package/src/EdhocExportOscoreAsyncWorker.cpp +77 -0
- package/src/EdhocKeyExporterAsyncWorker.cpp +49 -0
- package/src/EdhocKeyUpdateAsyncWorker.cpp +41 -0
- package/src/EdhocProcessAsyncWorker.cpp +72 -19
- package/src/LibEDHOC.cpp +213 -174
- package/src/Suites.cpp +39 -72
- package/src/Utils.cpp +32 -56
- package/test/basic.test.ts +64 -0
- package/test/vectors.test.ts +111 -0
- package/dist/credentials.d.ts +0 -16
- package/dist/credentials.d.ts.map +0 -1
- package/dist/credentials.js +0 -84
- package/external/libedhoc/externals/zcbor/include/zcbor_debug.h +0 -69
- package/external/libedhoc/tests/include/cipher_suite_negotiation/test_edhoc_cipher_suite_negotiation.h +0 -37
- package/external/libedhoc/tests/include/cipher_suites/test_cipher_suite_0.h +0 -48
- package/external/libedhoc/tests/include/cipher_suites/test_cipher_suite_2.h +0 -48
- package/external/libedhoc/tests/include/edhoc_trace_1/authentication_credentials_1.h +0 -60
- package/external/libedhoc/tests/include/edhoc_trace_1/test_edhoc_handshake_1.h +0 -208
- package/external/libedhoc/tests/include/edhoc_trace_1/test_edhoc_handshake_ead_1.h +0 -59
- package/external/libedhoc/tests/include/edhoc_trace_2/authentication_credentials_2.h +0 -60
- package/external/libedhoc/tests/include/edhoc_trace_2/test_edhoc_handshake_2.h +0 -199
- package/external/libedhoc/tests/include/error_message/test_edhoc_error_message.h +0 -48
- package/external/libedhoc/tests/include/x509_chain_cs_0/authentication_credentials_x5chain_cs_0.h +0 -92
- package/external/libedhoc/tests/include/x509_chain_cs_0/test_edhoc_handshake_x5chain_cs_0.h +0 -96
- package/external/libedhoc/tests/include/x509_chain_cs_2/authentication_credentials_x5chain_cs_2.h +0 -58
- package/external/libedhoc/tests/include/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2.h +0 -56
- package/external/libedhoc/tests/include/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2_ead.h +0 -57
- package/external/libedhoc/tests/include/x509_chain_cs_2_static_dh/authentication_credentials_x5chain_cs_2_static_dh.h +0 -59
- package/external/libedhoc/tests/include/x509_chain_cs_2_static_dh/test_edhoc_handshake_x5chain_cs_2_static_dh_ead.h +0 -57
- package/external/libedhoc/tests/include/x509_hash_cs_2/authentication_credentials_x5t_cs_2.h +0 -60
- package/external/libedhoc/tests/include/x509_hash_cs_2/test_edhoc_handshake_x5t_cs_2_ead.h +0 -57
- package/external/libedhoc/tests/src/cipher_suites/test_cipher_suite_0.c +0 -475
- package/external/libedhoc/tests/src/cipher_suites/test_cipher_suite_2.c +0 -473
- package/external/libedhoc/tests/src/edhoc_trace_1/authentication_credentials_1.c +0 -252
- package/external/libedhoc/tests/src/edhoc_trace_1/test_edhoc_handshake_1.c +0 -1829
- package/external/libedhoc/tests/src/edhoc_trace_1/test_edhoc_handshake_ead_1.c +0 -1247
- package/external/libedhoc/tests/src/edhoc_trace_2/authentication_credentials_2.c +0 -170
- package/external/libedhoc/tests/src/edhoc_trace_2/test_edhoc_handshake_2.c +0 -1783
- package/external/libedhoc/tests/src/tests.c +0 -228
- package/external/libedhoc/tests/src/x509_chain_cs_0/authentication_credentials_x5chain_cs_0.c +0 -332
- package/external/libedhoc/tests/src/x509_chain_cs_0/test_edhoc_handshake_x5chain_cs_0.c +0 -936
- package/external/libedhoc/tests/src/x509_chain_cs_2/authentication_credentials_x5chain_cs_2.c +0 -166
- package/external/libedhoc/tests/src/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2.c +0 -587
- package/external/libedhoc/tests/src/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2_ead.c +0 -917
- package/external/libedhoc/tests/src/x509_chain_cs_2_static_dh/authentication_credentials_x5chain_cs_2_static_dh.c +0 -186
- package/external/libedhoc/tests/src/x509_chain_cs_2_static_dh/test_edhoc_handshake_x5chain_cs_2_static_dh_ead.c +0 -743
- package/external/libedhoc/tests/src/x509_hash_cs_2/authentication_credentials_x5t_cs_2.c +0 -261
- package/external/libedhoc/tests/src/x509_hash_cs_2/test_edhoc_handshake_x5t_cs_2_ead.c +0 -854
- package/src/EdhocExportAsyncWorker.cpp +0 -82
|
@@ -8,15 +8,19 @@
|
|
|
8
8
|
#include <stdbool.h>
|
|
9
9
|
#include <stddef.h>
|
|
10
10
|
#include <string.h>
|
|
11
|
+
#include <inttypes.h>
|
|
11
12
|
#include "zcbor_decode.h"
|
|
12
13
|
#include "zcbor_common.h"
|
|
14
|
+
#include "zcbor_print.h"
|
|
13
15
|
|
|
14
16
|
|
|
15
17
|
/** Return value length from additional value.
|
|
16
18
|
*/
|
|
17
19
|
static size_t additional_len(uint8_t additional)
|
|
18
20
|
{
|
|
19
|
-
if (
|
|
21
|
+
if (additional <= ZCBOR_VALUE_IN_HEADER) {
|
|
22
|
+
return 0;
|
|
23
|
+
} else if (ZCBOR_VALUE_IS_1_BYTE <= additional && additional <= ZCBOR_VALUE_IS_8_BYTES) {
|
|
20
24
|
/* 24 => 1
|
|
21
25
|
* 25 => 2
|
|
22
26
|
* 26 => 4
|
|
@@ -24,24 +28,9 @@ static size_t additional_len(uint8_t additional)
|
|
|
24
28
|
*/
|
|
25
29
|
return 1U << (additional - ZCBOR_VALUE_IS_1_BYTE);
|
|
26
30
|
}
|
|
27
|
-
return
|
|
31
|
+
return 0xF;
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
/** Extract the major type, i.e. the first 3 bits of the header byte. */
|
|
31
|
-
#define MAJOR_TYPE(header_byte) ((zcbor_major_type_t)(((header_byte) >> 5) & 0x7))
|
|
32
|
-
|
|
33
|
-
/** Extract the additional info, i.e. the last 5 bits of the header byte. */
|
|
34
|
-
#define ADDITIONAL(header_byte) ((header_byte) & 0x1F)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
#define FAIL_AND_DECR_IF(expr, err) \
|
|
38
|
-
do {\
|
|
39
|
-
if (expr) { \
|
|
40
|
-
(state->payload)--; \
|
|
41
|
-
ZCBOR_ERR(err); \
|
|
42
|
-
} \
|
|
43
|
-
} while(0)
|
|
44
|
-
|
|
45
34
|
|
|
46
35
|
static bool initial_checks(zcbor_state_t *state)
|
|
47
36
|
{
|
|
@@ -56,7 +45,7 @@ static bool type_check(zcbor_state_t *state, zcbor_major_type_t exp_major_type)
|
|
|
56
45
|
if (!initial_checks(state)) {
|
|
57
46
|
ZCBOR_FAIL();
|
|
58
47
|
}
|
|
59
|
-
zcbor_major_type_t major_type =
|
|
48
|
+
zcbor_major_type_t major_type = ZCBOR_MAJOR_TYPE(*state->payload);
|
|
60
49
|
|
|
61
50
|
if (major_type != exp_major_type) {
|
|
62
51
|
ZCBOR_ERR(ZCBOR_ERR_WRONG_TYPE);
|
|
@@ -99,6 +88,20 @@ do { \
|
|
|
99
88
|
ZCBOR_FAIL(); \
|
|
100
89
|
} while(0)
|
|
101
90
|
|
|
91
|
+
#define PRINT_FUNC() zcbor_log("%s ", __func__);
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
static void endian_copy(uint8_t *dst, const uint8_t *src, size_t src_len)
|
|
95
|
+
{
|
|
96
|
+
#ifdef ZCBOR_BIG_ENDIAN
|
|
97
|
+
memcpy(dst, src, src_len);
|
|
98
|
+
#else
|
|
99
|
+
for (size_t i = 0; i < src_len; i++) {
|
|
100
|
+
dst[i] = src[src_len - 1 - i];
|
|
101
|
+
}
|
|
102
|
+
#endif /* ZCBOR_BIG_ENDIAN */
|
|
103
|
+
}
|
|
104
|
+
|
|
102
105
|
|
|
103
106
|
/** Get a single value.
|
|
104
107
|
*
|
|
@@ -116,61 +119,55 @@ do { \
|
|
|
116
119
|
* succeeds. If not, they are left unchanged.
|
|
117
120
|
*
|
|
118
121
|
* CBOR values are always big-endian, so this function converts from
|
|
119
|
-
* big to little-endian if necessary (@ref
|
|
122
|
+
* big to little-endian if necessary (@ref ZCBOR_BIG_ENDIAN).
|
|
120
123
|
*/
|
|
121
124
|
static bool value_extract(zcbor_state_t *state,
|
|
122
125
|
void *const result, size_t result_len)
|
|
123
126
|
{
|
|
124
|
-
zcbor_trace();
|
|
127
|
+
zcbor_trace(state, "value_extract");
|
|
125
128
|
zcbor_assert_state(result_len != 0, "0-length result not supported.\r\n");
|
|
126
|
-
zcbor_assert_state(
|
|
129
|
+
zcbor_assert_state(result_len <= 8, "result sizes above 8 bytes not supported.\r\n");
|
|
130
|
+
zcbor_assert_state(result != NULL, "result cannot be NULL.\r\n");
|
|
127
131
|
|
|
128
132
|
INITIAL_CHECKS();
|
|
129
133
|
ZCBOR_ERR_IF((state->elem_count == 0), ZCBOR_ERR_LOW_ELEM_COUNT);
|
|
130
134
|
|
|
131
|
-
uint8_t
|
|
132
|
-
|
|
135
|
+
uint8_t additional = ZCBOR_ADDITIONAL(*state->payload);
|
|
136
|
+
size_t len = additional_len(additional);
|
|
137
|
+
uint8_t *result_offs = (uint8_t *)result + ZCBOR_ECPY_OFFS(result_len, MAX(1, len));
|
|
133
138
|
|
|
134
|
-
|
|
135
|
-
(
|
|
139
|
+
ZCBOR_ERR_IF(additional > ZCBOR_VALUE_IS_8_BYTES, ZCBOR_ERR_ADDITIONAL_INVAL);
|
|
140
|
+
ZCBOR_ERR_IF(len > result_len, ZCBOR_ERR_INT_SIZE);
|
|
141
|
+
ZCBOR_ERR_IF((state->payload + len + 1) > state->payload_end,
|
|
142
|
+
ZCBOR_ERR_NO_PAYLOAD);
|
|
136
143
|
|
|
137
144
|
memset(result, 0, result_len);
|
|
138
|
-
if (additional <= ZCBOR_VALUE_IN_HEADER) {
|
|
139
|
-
#ifdef CONFIG_BIG_ENDIAN
|
|
140
|
-
u8_result[result_len - 1] = additional;
|
|
141
|
-
#else
|
|
142
|
-
u8_result[0] = additional;
|
|
143
|
-
#endif /* CONFIG_BIG_ENDIAN */
|
|
144
|
-
} else {
|
|
145
|
-
size_t len = additional_len(additional);
|
|
146
145
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
#ifdef CONFIG_BIG_ENDIAN
|
|
153
|
-
memcpy(&u8_result[result_len - len], state->payload, len);
|
|
154
|
-
#else
|
|
155
|
-
for (size_t i = 0; i < len; i++) {
|
|
156
|
-
u8_result[i] = (state->payload)[len - i - 1];
|
|
157
|
-
}
|
|
158
|
-
#endif /* CONFIG_BIG_ENDIAN */
|
|
146
|
+
if (len == 0) {
|
|
147
|
+
*result_offs = additional;
|
|
148
|
+
} else {
|
|
149
|
+
endian_copy(result_offs, state->payload + 1, len);
|
|
159
150
|
|
|
160
|
-
|
|
151
|
+
#ifdef ZCBOR_CANONICAL
|
|
152
|
+
ZCBOR_ERR_IF((zcbor_header_len_ptr(result, result_len) != (len + 1)),
|
|
153
|
+
ZCBOR_ERR_INVALID_VALUE_ENCODING);
|
|
154
|
+
#endif
|
|
161
155
|
}
|
|
162
156
|
|
|
157
|
+
state->payload_bak = state->payload;
|
|
158
|
+
(state->payload) += len + 1;
|
|
163
159
|
(state->elem_count)--;
|
|
164
160
|
return true;
|
|
165
161
|
}
|
|
166
162
|
|
|
167
163
|
|
|
168
|
-
bool zcbor_int_decode(zcbor_state_t *state, void *
|
|
164
|
+
bool zcbor_int_decode(zcbor_state_t *state, void *result, size_t result_size)
|
|
169
165
|
{
|
|
166
|
+
PRINT_FUNC();
|
|
170
167
|
INITIAL_CHECKS();
|
|
171
|
-
zcbor_major_type_t major_type =
|
|
172
|
-
uint8_t *result_uint8 = (uint8_t *)
|
|
173
|
-
int8_t *result_int8 = (int8_t *)
|
|
168
|
+
zcbor_major_type_t major_type = ZCBOR_MAJOR_TYPE(*state->payload);
|
|
169
|
+
uint8_t *result_uint8 = (uint8_t *)result;
|
|
170
|
+
int8_t *result_int8 = (int8_t *)result;
|
|
174
171
|
|
|
175
172
|
if (major_type != ZCBOR_MAJOR_TYPE_PINT
|
|
176
173
|
&& major_type != ZCBOR_MAJOR_TYPE_NINT) {
|
|
@@ -178,14 +175,14 @@ bool zcbor_int_decode(zcbor_state_t *state, void *result_int, size_t int_size)
|
|
|
178
175
|
ZCBOR_ERR(ZCBOR_ERR_WRONG_TYPE);
|
|
179
176
|
}
|
|
180
177
|
|
|
181
|
-
if (!value_extract(state,
|
|
178
|
+
if (!value_extract(state, result, result_size)) {
|
|
182
179
|
ZCBOR_FAIL();
|
|
183
180
|
}
|
|
184
181
|
|
|
185
|
-
#ifdef
|
|
182
|
+
#ifdef ZCBOR_BIG_ENDIAN
|
|
186
183
|
if (result_int8[0] < 0) {
|
|
187
184
|
#else
|
|
188
|
-
if (result_int8[
|
|
185
|
+
if (result_int8[result_size - 1] < 0) {
|
|
189
186
|
#endif
|
|
190
187
|
/* Value is too large to fit in a signed integer. */
|
|
191
188
|
ERR_RESTORE(ZCBOR_ERR_INT_SIZE);
|
|
@@ -193,7 +190,7 @@ bool zcbor_int_decode(zcbor_state_t *state, void *result_int, size_t int_size)
|
|
|
193
190
|
|
|
194
191
|
if (major_type == ZCBOR_MAJOR_TYPE_NINT) {
|
|
195
192
|
/* Convert from CBOR's representation by flipping all bits. */
|
|
196
|
-
for (unsigned int i = 0; i <
|
|
193
|
+
for (unsigned int i = 0; i < result_size; i++) {
|
|
197
194
|
result_uint8[i] = (uint8_t)~result_uint8[i];
|
|
198
195
|
}
|
|
199
196
|
}
|
|
@@ -204,22 +201,25 @@ bool zcbor_int_decode(zcbor_state_t *state, void *result_int, size_t int_size)
|
|
|
204
201
|
|
|
205
202
|
bool zcbor_int32_decode(zcbor_state_t *state, int32_t *result)
|
|
206
203
|
{
|
|
204
|
+
PRINT_FUNC();
|
|
207
205
|
return zcbor_int_decode(state, result, sizeof(*result));
|
|
208
206
|
}
|
|
209
207
|
|
|
210
208
|
|
|
211
209
|
bool zcbor_int64_decode(zcbor_state_t *state, int64_t *result)
|
|
212
210
|
{
|
|
211
|
+
PRINT_FUNC();
|
|
213
212
|
return zcbor_int_decode(state, result, sizeof(*result));
|
|
214
213
|
}
|
|
215
214
|
|
|
216
215
|
|
|
217
|
-
bool zcbor_uint_decode(zcbor_state_t *state, void *
|
|
216
|
+
bool zcbor_uint_decode(zcbor_state_t *state, void *result, size_t result_size)
|
|
218
217
|
{
|
|
218
|
+
PRINT_FUNC();
|
|
219
219
|
INITIAL_CHECKS_WITH_TYPE(ZCBOR_MAJOR_TYPE_PINT);
|
|
220
220
|
|
|
221
|
-
if (!value_extract(state,
|
|
222
|
-
|
|
221
|
+
if (!value_extract(state, result, result_size)) {
|
|
222
|
+
zcbor_log("uint with size %zu failed.\r\n", result_size);
|
|
223
223
|
ZCBOR_FAIL();
|
|
224
224
|
}
|
|
225
225
|
return true;
|
|
@@ -228,12 +228,14 @@ bool zcbor_uint_decode(zcbor_state_t *state, void *result_uint, size_t uint_size
|
|
|
228
228
|
|
|
229
229
|
bool zcbor_uint32_decode(zcbor_state_t *state, uint32_t *result)
|
|
230
230
|
{
|
|
231
|
+
PRINT_FUNC();
|
|
231
232
|
return zcbor_uint_decode(state, result, sizeof(*result));
|
|
232
233
|
}
|
|
233
234
|
|
|
234
235
|
|
|
235
236
|
bool zcbor_int32_expect_union(zcbor_state_t *state, int32_t result)
|
|
236
237
|
{
|
|
238
|
+
PRINT_FUNC();
|
|
237
239
|
if (!zcbor_union_elem_code(state)) {
|
|
238
240
|
ZCBOR_FAIL();
|
|
239
241
|
}
|
|
@@ -243,6 +245,7 @@ bool zcbor_int32_expect_union(zcbor_state_t *state, int32_t result)
|
|
|
243
245
|
|
|
244
246
|
bool zcbor_int64_expect_union(zcbor_state_t *state, int64_t result)
|
|
245
247
|
{
|
|
248
|
+
PRINT_FUNC();
|
|
246
249
|
if (!zcbor_union_elem_code(state)) {
|
|
247
250
|
ZCBOR_FAIL();
|
|
248
251
|
}
|
|
@@ -252,6 +255,7 @@ bool zcbor_int64_expect_union(zcbor_state_t *state, int64_t result)
|
|
|
252
255
|
|
|
253
256
|
bool zcbor_uint32_expect_union(zcbor_state_t *state, uint32_t result)
|
|
254
257
|
{
|
|
258
|
+
PRINT_FUNC();
|
|
255
259
|
if (!zcbor_union_elem_code(state)) {
|
|
256
260
|
ZCBOR_FAIL();
|
|
257
261
|
}
|
|
@@ -261,6 +265,7 @@ bool zcbor_uint32_expect_union(zcbor_state_t *state, uint32_t result)
|
|
|
261
265
|
|
|
262
266
|
bool zcbor_uint64_expect_union(zcbor_state_t *state, uint64_t result)
|
|
263
267
|
{
|
|
268
|
+
PRINT_FUNC();
|
|
264
269
|
if (!zcbor_union_elem_code(state)) {
|
|
265
270
|
ZCBOR_FAIL();
|
|
266
271
|
}
|
|
@@ -268,30 +273,47 @@ bool zcbor_uint64_expect_union(zcbor_state_t *state, uint64_t result)
|
|
|
268
273
|
}
|
|
269
274
|
|
|
270
275
|
|
|
271
|
-
bool zcbor_int32_expect(zcbor_state_t *state, int32_t
|
|
276
|
+
bool zcbor_int32_expect(zcbor_state_t *state, int32_t expected)
|
|
272
277
|
{
|
|
273
|
-
|
|
278
|
+
PRINT_FUNC();
|
|
279
|
+
return zcbor_int64_expect(state, expected);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
bool zcbor_int32_pexpect(zcbor_state_t *state, int32_t *expected)
|
|
284
|
+
{
|
|
285
|
+
PRINT_FUNC();
|
|
286
|
+
return zcbor_int32_expect(state, *expected);
|
|
274
287
|
}
|
|
275
288
|
|
|
276
289
|
|
|
277
|
-
bool zcbor_int64_expect(zcbor_state_t *state, int64_t
|
|
290
|
+
bool zcbor_int64_expect(zcbor_state_t *state, int64_t expected)
|
|
278
291
|
{
|
|
279
|
-
|
|
292
|
+
PRINT_FUNC();
|
|
293
|
+
int64_t actual;
|
|
280
294
|
|
|
281
|
-
if (!zcbor_int64_decode(state, &
|
|
295
|
+
if (!zcbor_int64_decode(state, &actual)) {
|
|
282
296
|
ZCBOR_FAIL();
|
|
283
297
|
}
|
|
284
298
|
|
|
285
|
-
if (
|
|
286
|
-
|
|
299
|
+
if (actual != expected) {
|
|
300
|
+
zcbor_log("%" PRIi64 " != %" PRIi64 "\r\n", actual, expected);
|
|
287
301
|
ERR_RESTORE(ZCBOR_ERR_WRONG_VALUE);
|
|
288
302
|
}
|
|
289
303
|
return true;
|
|
290
304
|
}
|
|
291
305
|
|
|
292
306
|
|
|
307
|
+
bool zcbor_int64_pexpect(zcbor_state_t *state, int64_t *expected)
|
|
308
|
+
{
|
|
309
|
+
PRINT_FUNC();
|
|
310
|
+
return zcbor_int64_expect(state, *expected);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
|
|
293
314
|
bool zcbor_uint64_decode(zcbor_state_t *state, uint64_t *result)
|
|
294
315
|
{
|
|
316
|
+
PRINT_FUNC();
|
|
295
317
|
return zcbor_uint_decode(state, result, sizeof(*result));
|
|
296
318
|
}
|
|
297
319
|
|
|
@@ -299,36 +321,61 @@ bool zcbor_uint64_decode(zcbor_state_t *state, uint64_t *result)
|
|
|
299
321
|
#ifdef ZCBOR_SUPPORTS_SIZE_T
|
|
300
322
|
bool zcbor_size_decode(zcbor_state_t *state, size_t *result)
|
|
301
323
|
{
|
|
324
|
+
PRINT_FUNC();
|
|
302
325
|
return zcbor_uint_decode(state, result, sizeof(*result));
|
|
303
326
|
}
|
|
304
327
|
#endif
|
|
305
328
|
|
|
306
329
|
|
|
307
|
-
bool zcbor_uint32_expect(zcbor_state_t *state, uint32_t
|
|
330
|
+
bool zcbor_uint32_expect(zcbor_state_t *state, uint32_t expected)
|
|
308
331
|
{
|
|
309
|
-
|
|
332
|
+
PRINT_FUNC();
|
|
333
|
+
return zcbor_uint64_expect(state, expected);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
bool zcbor_uint32_pexpect(zcbor_state_t *state, uint32_t *expected)
|
|
338
|
+
{
|
|
339
|
+
PRINT_FUNC();
|
|
340
|
+
return zcbor_uint32_expect(state, *expected);
|
|
310
341
|
}
|
|
311
342
|
|
|
312
343
|
|
|
313
|
-
bool zcbor_uint64_expect(zcbor_state_t *state, uint64_t
|
|
344
|
+
bool zcbor_uint64_expect(zcbor_state_t *state, uint64_t expected)
|
|
314
345
|
{
|
|
315
|
-
|
|
346
|
+
PRINT_FUNC();
|
|
347
|
+
uint64_t actual;
|
|
316
348
|
|
|
317
|
-
if (!zcbor_uint64_decode(state, &
|
|
349
|
+
if (!zcbor_uint64_decode(state, &actual)) {
|
|
318
350
|
ZCBOR_FAIL();
|
|
319
351
|
}
|
|
320
|
-
if (
|
|
321
|
-
|
|
352
|
+
if (actual != expected) {
|
|
353
|
+
zcbor_log("%" PRIu64 " != %" PRIu64 "\r\n", actual, expected);
|
|
322
354
|
ERR_RESTORE(ZCBOR_ERR_WRONG_VALUE);
|
|
323
355
|
}
|
|
324
356
|
return true;
|
|
325
357
|
}
|
|
326
358
|
|
|
327
359
|
|
|
360
|
+
bool zcbor_uint64_pexpect(zcbor_state_t *state, uint64_t *expected)
|
|
361
|
+
{
|
|
362
|
+
PRINT_FUNC();
|
|
363
|
+
return zcbor_uint64_expect(state, *expected);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
|
|
328
367
|
#ifdef ZCBOR_SUPPORTS_SIZE_T
|
|
329
|
-
bool zcbor_size_expect(zcbor_state_t *state, size_t
|
|
368
|
+
bool zcbor_size_expect(zcbor_state_t *state, size_t expected)
|
|
330
369
|
{
|
|
331
|
-
|
|
370
|
+
PRINT_FUNC();
|
|
371
|
+
return zcbor_uint64_expect(state, expected);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
bool zcbor_size_pexpect(zcbor_state_t *state, size_t *expected)
|
|
376
|
+
{
|
|
377
|
+
PRINT_FUNC();
|
|
378
|
+
return zcbor_size_expect(state, *expected);
|
|
332
379
|
}
|
|
333
380
|
#endif
|
|
334
381
|
|
|
@@ -358,7 +405,7 @@ static bool str_start_decode_with_overflow_check(zcbor_state_t *state,
|
|
|
358
405
|
/* Casting to size_t is safe since str_start_decode() checks that
|
|
359
406
|
* payload_end is bigger that payload. */
|
|
360
407
|
if (result->len > (size_t)(state->payload_end - state->payload)) {
|
|
361
|
-
|
|
408
|
+
zcbor_log("error: 0x%zu > 0x%zu\r\n",
|
|
362
409
|
result->len,
|
|
363
410
|
(state->payload_end - state->payload));
|
|
364
411
|
ERR_RESTORE(ZCBOR_ERR_NO_PAYLOAD);
|
|
@@ -370,6 +417,7 @@ static bool str_start_decode_with_overflow_check(zcbor_state_t *state,
|
|
|
370
417
|
|
|
371
418
|
bool zcbor_bstr_start_decode(zcbor_state_t *state, struct zcbor_string *result)
|
|
372
419
|
{
|
|
420
|
+
PRINT_FUNC();
|
|
373
421
|
struct zcbor_string dummy;
|
|
374
422
|
if (result == NULL) {
|
|
375
423
|
result = &dummy;
|
|
@@ -393,7 +441,7 @@ bool zcbor_bstr_end_decode(zcbor_state_t *state)
|
|
|
393
441
|
ZCBOR_ERR_IF(state->payload != state->payload_end, ZCBOR_ERR_PAYLOAD_NOT_CONSUMED);
|
|
394
442
|
|
|
395
443
|
if (!zcbor_process_backup(state,
|
|
396
|
-
ZCBOR_FLAG_RESTORE | ZCBOR_FLAG_CONSUME |
|
|
444
|
+
ZCBOR_FLAG_RESTORE | ZCBOR_FLAG_CONSUME | ZCBOR_FLAG_KEEP_PAYLOAD,
|
|
397
445
|
ZCBOR_MAX_ELEM_COUNT)) {
|
|
398
446
|
ZCBOR_FAIL();
|
|
399
447
|
}
|
|
@@ -414,6 +462,7 @@ static bool start_decode_fragment(zcbor_state_t *state,
|
|
|
414
462
|
struct zcbor_string_fragment *result,
|
|
415
463
|
zcbor_major_type_t exp_major_type)
|
|
416
464
|
{
|
|
465
|
+
PRINT_FUNC();
|
|
417
466
|
if(!str_start_decode(state, &result->fragment, exp_major_type)) {
|
|
418
467
|
ZCBOR_FAIL();
|
|
419
468
|
}
|
|
@@ -429,6 +478,7 @@ static bool start_decode_fragment(zcbor_state_t *state,
|
|
|
429
478
|
bool zcbor_bstr_start_decode_fragment(zcbor_state_t *state,
|
|
430
479
|
struct zcbor_string_fragment *result)
|
|
431
480
|
{
|
|
481
|
+
PRINT_FUNC();
|
|
432
482
|
if (!start_decode_fragment(state, result, ZCBOR_MAJOR_TYPE_BSTR)) {
|
|
433
483
|
ZCBOR_FAIL();
|
|
434
484
|
}
|
|
@@ -449,7 +499,7 @@ void zcbor_next_fragment(zcbor_state_t *state,
|
|
|
449
499
|
result->fragment.len = result->total_len - result->offset;
|
|
450
500
|
|
|
451
501
|
partition_fragment(state, result);
|
|
452
|
-
|
|
502
|
+
zcbor_log("New fragment length %zu\r\n", result->fragment.len);
|
|
453
503
|
|
|
454
504
|
state->payload += result->fragment.len;
|
|
455
505
|
}
|
|
@@ -465,7 +515,7 @@ void zcbor_bstr_next_fragment(zcbor_state_t *state,
|
|
|
465
515
|
result->fragment.len = result->total_len - result->offset;
|
|
466
516
|
|
|
467
517
|
partition_fragment(state, result);
|
|
468
|
-
|
|
518
|
+
zcbor_log("fragment length %zu\r\n", result->fragment.len);
|
|
469
519
|
state->payload_end = state->payload + result->fragment.len;
|
|
470
520
|
}
|
|
471
521
|
|
|
@@ -517,37 +567,75 @@ static bool str_expect(zcbor_state_t *state, struct zcbor_string *result,
|
|
|
517
567
|
|
|
518
568
|
bool zcbor_bstr_decode(zcbor_state_t *state, struct zcbor_string *result)
|
|
519
569
|
{
|
|
570
|
+
PRINT_FUNC();
|
|
520
571
|
return str_decode(state, result, ZCBOR_MAJOR_TYPE_BSTR);
|
|
521
572
|
}
|
|
522
573
|
|
|
523
574
|
|
|
524
575
|
bool zcbor_bstr_decode_fragment(zcbor_state_t *state, struct zcbor_string_fragment *result)
|
|
525
576
|
{
|
|
577
|
+
PRINT_FUNC();
|
|
526
578
|
return str_decode_fragment(state, result, ZCBOR_MAJOR_TYPE_BSTR);
|
|
527
579
|
}
|
|
528
580
|
|
|
529
581
|
|
|
530
|
-
bool zcbor_bstr_expect(zcbor_state_t *state, struct zcbor_string *
|
|
582
|
+
bool zcbor_bstr_expect(zcbor_state_t *state, struct zcbor_string *expected)
|
|
531
583
|
{
|
|
532
|
-
|
|
584
|
+
PRINT_FUNC();
|
|
585
|
+
return str_expect(state, expected, ZCBOR_MAJOR_TYPE_BSTR);
|
|
533
586
|
}
|
|
534
587
|
|
|
535
588
|
|
|
536
589
|
bool zcbor_tstr_decode(zcbor_state_t *state, struct zcbor_string *result)
|
|
537
590
|
{
|
|
591
|
+
PRINT_FUNC();
|
|
538
592
|
return str_decode(state, result, ZCBOR_MAJOR_TYPE_TSTR);
|
|
539
593
|
}
|
|
540
594
|
|
|
541
595
|
|
|
542
596
|
bool zcbor_tstr_decode_fragment(zcbor_state_t *state, struct zcbor_string_fragment *result)
|
|
543
597
|
{
|
|
598
|
+
PRINT_FUNC();
|
|
544
599
|
return str_decode_fragment(state, result, ZCBOR_MAJOR_TYPE_TSTR);
|
|
545
600
|
}
|
|
546
601
|
|
|
547
602
|
|
|
548
|
-
bool zcbor_tstr_expect(zcbor_state_t *state, struct zcbor_string *
|
|
603
|
+
bool zcbor_tstr_expect(zcbor_state_t *state, struct zcbor_string *expected)
|
|
604
|
+
{
|
|
605
|
+
PRINT_FUNC();
|
|
606
|
+
return str_expect(state, expected, ZCBOR_MAJOR_TYPE_TSTR);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
bool zcbor_bstr_expect_ptr(zcbor_state_t *state, char const *ptr, size_t len)
|
|
611
|
+
{
|
|
612
|
+
PRINT_FUNC();
|
|
613
|
+
struct zcbor_string zs = { .value = (const uint8_t *)ptr, .len = len };
|
|
614
|
+
|
|
615
|
+
return zcbor_bstr_expect(state, &zs);
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
bool zcbor_tstr_expect_ptr(zcbor_state_t *state, char const *ptr, size_t len)
|
|
549
620
|
{
|
|
550
|
-
|
|
621
|
+
PRINT_FUNC();
|
|
622
|
+
struct zcbor_string zs = { .value = (const uint8_t *)ptr, .len = len };
|
|
623
|
+
|
|
624
|
+
return zcbor_tstr_expect(state, &zs);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
bool zcbor_bstr_expect_term(zcbor_state_t *state, char const *string, size_t maxlen)
|
|
629
|
+
{
|
|
630
|
+
PRINT_FUNC();
|
|
631
|
+
return zcbor_bstr_expect_ptr(state, string, strnlen(string, maxlen));
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
bool zcbor_tstr_expect_term(zcbor_state_t *state, char const *string, size_t maxlen)
|
|
636
|
+
{
|
|
637
|
+
PRINT_FUNC();
|
|
638
|
+
return zcbor_tstr_expect_ptr(state, string, strnlen(string, maxlen));
|
|
551
639
|
}
|
|
552
640
|
|
|
553
641
|
|
|
@@ -559,14 +647,17 @@ static bool list_map_start_decode(zcbor_state_t *state,
|
|
|
559
647
|
|
|
560
648
|
INITIAL_CHECKS_WITH_TYPE(exp_major_type);
|
|
561
649
|
|
|
562
|
-
|
|
650
|
+
#ifndef ZCBOR_CANONICAL
|
|
651
|
+
if (ZCBOR_ADDITIONAL(*state->payload) == ZCBOR_VALUE_IS_INDEFINITE_LENGTH) {
|
|
563
652
|
/* Indefinite length array. */
|
|
564
653
|
new_elem_count = ZCBOR_LARGE_ELEM_COUNT;
|
|
565
654
|
ZCBOR_ERR_IF(state->elem_count == 0, ZCBOR_ERR_LOW_ELEM_COUNT);
|
|
566
655
|
indefinite_length_array = true;
|
|
567
|
-
state->payload++;
|
|
656
|
+
state->payload_bak = state->payload++;
|
|
568
657
|
state->elem_count--;
|
|
569
|
-
} else
|
|
658
|
+
} else
|
|
659
|
+
#endif
|
|
660
|
+
{
|
|
570
661
|
if (!value_extract(state, &new_elem_count, sizeof(new_elem_count))) {
|
|
571
662
|
ZCBOR_FAIL();
|
|
572
663
|
}
|
|
@@ -576,7 +667,7 @@ static bool list_map_start_decode(zcbor_state_t *state,
|
|
|
576
667
|
FAIL_RESTORE();
|
|
577
668
|
}
|
|
578
669
|
|
|
579
|
-
state->indefinite_length_array = indefinite_length_array;
|
|
670
|
+
state->decode_state.indefinite_length_array = indefinite_length_array;
|
|
580
671
|
|
|
581
672
|
return true;
|
|
582
673
|
}
|
|
@@ -584,15 +675,17 @@ static bool list_map_start_decode(zcbor_state_t *state,
|
|
|
584
675
|
|
|
585
676
|
bool zcbor_list_start_decode(zcbor_state_t *state)
|
|
586
677
|
{
|
|
678
|
+
PRINT_FUNC();
|
|
587
679
|
return list_map_start_decode(state, ZCBOR_MAJOR_TYPE_LIST);
|
|
588
680
|
}
|
|
589
681
|
|
|
590
682
|
|
|
591
683
|
bool zcbor_map_start_decode(zcbor_state_t *state)
|
|
592
684
|
{
|
|
685
|
+
PRINT_FUNC();
|
|
593
686
|
bool ret = list_map_start_decode(state, ZCBOR_MAJOR_TYPE_MAP);
|
|
594
687
|
|
|
595
|
-
if (ret && !state->indefinite_length_array) {
|
|
688
|
+
if (ret && !state->decode_state.indefinite_length_array) {
|
|
596
689
|
if (state->elem_count >= (ZCBOR_MAX_ELEM_COUNT / 2)) {
|
|
597
690
|
/* The new elem_count is too large. */
|
|
598
691
|
ERR_RESTORE(ZCBOR_ERR_INT_SIZE);
|
|
@@ -603,6 +696,272 @@ bool zcbor_map_start_decode(zcbor_state_t *state)
|
|
|
603
696
|
}
|
|
604
697
|
|
|
605
698
|
|
|
699
|
+
bool zcbor_array_at_end(zcbor_state_t *state)
|
|
700
|
+
{
|
|
701
|
+
#ifdef ZCBOR_CANONICAL
|
|
702
|
+
const bool indefinite_length_array = false;
|
|
703
|
+
#else
|
|
704
|
+
const bool indefinite_length_array = state->decode_state.indefinite_length_array;
|
|
705
|
+
#endif
|
|
706
|
+
return ((!indefinite_length_array && (state->elem_count == 0))
|
|
707
|
+
|| (indefinite_length_array
|
|
708
|
+
&& (state->payload < state->payload_end)
|
|
709
|
+
&& (*state->payload == 0xFF)));
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
static size_t update_map_elem_count(zcbor_state_t *state, size_t elem_count);
|
|
714
|
+
#ifdef ZCBOR_MAP_SMART_SEARCH
|
|
715
|
+
static bool allocate_map_flags(zcbor_state_t *state, size_t elem_count);
|
|
716
|
+
#endif
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
bool zcbor_unordered_map_start_decode(zcbor_state_t *state)
|
|
720
|
+
{
|
|
721
|
+
PRINT_FUNC();
|
|
722
|
+
ZCBOR_FAIL_IF(!zcbor_map_start_decode(state));
|
|
723
|
+
|
|
724
|
+
#ifdef ZCBOR_MAP_SMART_SEARCH
|
|
725
|
+
state->decode_state.map_search_elem_state
|
|
726
|
+
+= zcbor_flags_to_bytes(state->decode_state.map_elem_count);
|
|
727
|
+
#else
|
|
728
|
+
state->decode_state.map_elems_processed = 0;
|
|
729
|
+
#endif
|
|
730
|
+
state->decode_state.map_elem_count = 0;
|
|
731
|
+
state->decode_state.counting_map_elems = state->decode_state.indefinite_length_array;
|
|
732
|
+
|
|
733
|
+
if (!state->decode_state.counting_map_elems) {
|
|
734
|
+
size_t old_flags = update_map_elem_count(state, state->elem_count);
|
|
735
|
+
#ifdef ZCBOR_MAP_SMART_SEARCH
|
|
736
|
+
ZCBOR_FAIL_IF(!allocate_map_flags(state, old_flags));
|
|
737
|
+
#endif
|
|
738
|
+
(void)old_flags;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
return true;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
/** Return the max (starting) elem_count of the current container.
|
|
746
|
+
*
|
|
747
|
+
* Should only be used for unordered maps (started with @ref zcbor_unordered_map_start_decode)
|
|
748
|
+
*/
|
|
749
|
+
static size_t zcbor_current_max_elem_count(zcbor_state_t *state)
|
|
750
|
+
{
|
|
751
|
+
return (state->decode_state.indefinite_length_array ? \
|
|
752
|
+
ZCBOR_LARGE_ELEM_COUNT : state->decode_state.map_elem_count * 2);
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
static bool map_restart(zcbor_state_t *state)
|
|
757
|
+
{
|
|
758
|
+
if (!zcbor_process_backup(state, ZCBOR_FLAG_RESTORE | ZCBOR_FLAG_KEEP_DECODE_STATE,
|
|
759
|
+
ZCBOR_MAX_ELEM_COUNT)) {
|
|
760
|
+
ZCBOR_FAIL();
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
state->elem_count = zcbor_current_max_elem_count(state);
|
|
764
|
+
return true;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
__attribute__((used))
|
|
769
|
+
static size_t get_current_index(zcbor_state_t *state, uint32_t index_offset)
|
|
770
|
+
{
|
|
771
|
+
/* Subtract mode because for GET, you want the index you are pointing to, while for SET,
|
|
772
|
+
* you want the one you just processed. This only comes into play when elem_count is even. */
|
|
773
|
+
return ((zcbor_current_max_elem_count(state) - state->elem_count - index_offset) / 2);
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
#ifdef ZCBOR_MAP_SMART_SEARCH
|
|
778
|
+
#define FLAG_MODE_GET_CURRENT 0
|
|
779
|
+
#define FLAG_MODE_CLEAR_CURRENT 1
|
|
780
|
+
#define FLAG_MODE_CLEAR_UNUSED 2
|
|
781
|
+
|
|
782
|
+
static bool manipulate_flags(zcbor_state_t *state, uint32_t mode)
|
|
783
|
+
{
|
|
784
|
+
const size_t last_index = (state->decode_state.map_elem_count - 1);
|
|
785
|
+
size_t index = (mode == FLAG_MODE_CLEAR_UNUSED) ? last_index : get_current_index(state, mode);
|
|
786
|
+
|
|
787
|
+
ZCBOR_ERR_IF((index >= state->decode_state.map_elem_count),
|
|
788
|
+
ZCBOR_ERR_MAP_FLAGS_NOT_AVAILABLE);
|
|
789
|
+
uint8_t *flag_byte = &state->decode_state.map_search_elem_state[index >> 3];
|
|
790
|
+
uint8_t flag_mask = (uint8_t)(1 << (index & 7));
|
|
791
|
+
|
|
792
|
+
switch(mode) {
|
|
793
|
+
case FLAG_MODE_GET_CURRENT:
|
|
794
|
+
return (!!(*flag_byte & flag_mask));
|
|
795
|
+
case FLAG_MODE_CLEAR_CURRENT:
|
|
796
|
+
*flag_byte &= ~flag_mask;
|
|
797
|
+
return true;
|
|
798
|
+
case FLAG_MODE_CLEAR_UNUSED:
|
|
799
|
+
*flag_byte &= (uint8_t)((flag_mask << 1) - 1);
|
|
800
|
+
return true;
|
|
801
|
+
}
|
|
802
|
+
return false;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
static bool should_try_key(zcbor_state_t *state)
|
|
807
|
+
{
|
|
808
|
+
return manipulate_flags(state, FLAG_MODE_GET_CURRENT);
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
bool zcbor_elem_processed(zcbor_state_t *state)
|
|
813
|
+
{
|
|
814
|
+
return manipulate_flags(state, FLAG_MODE_CLEAR_CURRENT);
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
static bool allocate_map_flags(zcbor_state_t *state, size_t old_flags)
|
|
819
|
+
{
|
|
820
|
+
size_t new_bytes = zcbor_flags_to_bytes(state->decode_state.map_elem_count);
|
|
821
|
+
size_t old_bytes = zcbor_flags_to_bytes(old_flags);
|
|
822
|
+
size_t extra_bytes = new_bytes - old_bytes;
|
|
823
|
+
const uint8_t *flags_end = state->constant_state->map_search_elem_state_end;
|
|
824
|
+
|
|
825
|
+
if (extra_bytes) {
|
|
826
|
+
if ((state->decode_state.map_search_elem_state + new_bytes) > flags_end) {
|
|
827
|
+
state->decode_state.map_elem_count
|
|
828
|
+
= 8 * (size_t)(flags_end - state->decode_state.map_search_elem_state);
|
|
829
|
+
ZCBOR_ERR(ZCBOR_ERR_MAP_FLAGS_NOT_AVAILABLE);
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
memset(&state->decode_state.map_search_elem_state[new_bytes - extra_bytes], 0xFF, extra_bytes);
|
|
833
|
+
}
|
|
834
|
+
return true;
|
|
835
|
+
}
|
|
836
|
+
#else
|
|
837
|
+
|
|
838
|
+
static bool should_try_key(zcbor_state_t *state)
|
|
839
|
+
{
|
|
840
|
+
return (state->decode_state.map_elems_processed < state->decode_state.map_elem_count);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
bool zcbor_elem_processed(zcbor_state_t *state)
|
|
845
|
+
{
|
|
846
|
+
if (should_try_key(state)) {
|
|
847
|
+
state->decode_state.map_elems_processed++;
|
|
848
|
+
}
|
|
849
|
+
return true;
|
|
850
|
+
}
|
|
851
|
+
#endif
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
static size_t update_map_elem_count(zcbor_state_t *state, size_t elem_count)
|
|
855
|
+
{
|
|
856
|
+
size_t old_map_elem_count = state->decode_state.map_elem_count;
|
|
857
|
+
|
|
858
|
+
state->decode_state.map_elem_count = MAX(old_map_elem_count, elem_count / 2);
|
|
859
|
+
return old_map_elem_count;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
static bool handle_map_end(zcbor_state_t *state)
|
|
864
|
+
{
|
|
865
|
+
state->decode_state.counting_map_elems = false;
|
|
866
|
+
return map_restart(state);
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
static bool try_key(zcbor_state_t *state, void *key_result, zcbor_decoder_t key_decoder)
|
|
871
|
+
{
|
|
872
|
+
uint8_t const *payload_bak2 = state->payload;
|
|
873
|
+
size_t elem_count_bak = state->elem_count;
|
|
874
|
+
|
|
875
|
+
if (!key_decoder(state, (uint8_t *)key_result)) {
|
|
876
|
+
state->payload = payload_bak2;
|
|
877
|
+
state->elem_count = elem_count_bak;
|
|
878
|
+
return false;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
zcbor_log("Found element at index %zu.\n", get_current_index(state, 1));
|
|
882
|
+
return true;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
bool zcbor_unordered_map_search(zcbor_decoder_t key_decoder, zcbor_state_t *state, void *key_result)
|
|
887
|
+
{
|
|
888
|
+
PRINT_FUNC();
|
|
889
|
+
/* elem_count cannot be odd since the map consists of key-value-pairs.
|
|
890
|
+
* This might mean that this function was called while pointing at a value (instead
|
|
891
|
+
* of a key). */
|
|
892
|
+
ZCBOR_ERR_IF(state->elem_count & 1, ZCBOR_ERR_MAP_MISALIGNED);
|
|
893
|
+
|
|
894
|
+
uint8_t const *payload_bak = state->payload;
|
|
895
|
+
size_t elem_count = state->elem_count;
|
|
896
|
+
|
|
897
|
+
/* Loop once through all the elements of the map. */
|
|
898
|
+
do {
|
|
899
|
+
if (zcbor_array_at_end(state)) {
|
|
900
|
+
if (!handle_map_end(state)) {
|
|
901
|
+
goto error;
|
|
902
|
+
}
|
|
903
|
+
continue; /* This continue is needed so the loop stops both if elem_count is
|
|
904
|
+
* at the very start or the very end of the map. */
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
if (state->decode_state.counting_map_elems) {
|
|
908
|
+
size_t m_elem_count = ZCBOR_LARGE_ELEM_COUNT - state->elem_count + 2;
|
|
909
|
+
size_t old_flags = update_map_elem_count(state, m_elem_count);
|
|
910
|
+
#ifdef ZCBOR_MAP_SMART_SEARCH
|
|
911
|
+
ZCBOR_FAIL_IF(!allocate_map_flags(state, old_flags));
|
|
912
|
+
#endif
|
|
913
|
+
(void)old_flags;
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
if (should_try_key(state) && try_key(state, key_result, key_decoder)) {
|
|
917
|
+
if (!state->constant_state->manually_process_elem) {
|
|
918
|
+
ZCBOR_FAIL_IF(!zcbor_elem_processed(state));
|
|
919
|
+
}
|
|
920
|
+
return true;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
/* Skip over both the key and the value. */
|
|
924
|
+
if (!zcbor_any_skip(state, NULL) || !zcbor_any_skip(state, NULL)) {
|
|
925
|
+
goto error;
|
|
926
|
+
}
|
|
927
|
+
} while (state->elem_count != elem_count);
|
|
928
|
+
|
|
929
|
+
zcbor_error(state, ZCBOR_ERR_ELEM_NOT_FOUND);
|
|
930
|
+
error:
|
|
931
|
+
state->payload = payload_bak;
|
|
932
|
+
state->elem_count = elem_count;
|
|
933
|
+
ZCBOR_FAIL();
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
bool zcbor_search_key_bstr_ptr(zcbor_state_t *state, char const *ptr, size_t len)
|
|
938
|
+
{
|
|
939
|
+
struct zcbor_string zs = { .value = (const uint8_t *)ptr, .len = len };
|
|
940
|
+
|
|
941
|
+
return zcbor_unordered_map_search((zcbor_decoder_t *)zcbor_bstr_expect, state, &zs);
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
|
|
945
|
+
bool zcbor_search_key_tstr_ptr(zcbor_state_t *state, char const *ptr, size_t len)
|
|
946
|
+
{
|
|
947
|
+
struct zcbor_string zs = { .value = (const uint8_t *)ptr, .len = len };
|
|
948
|
+
|
|
949
|
+
return zcbor_unordered_map_search((zcbor_decoder_t *)zcbor_tstr_expect, state, &zs);
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
|
|
953
|
+
bool zcbor_search_key_bstr_term(zcbor_state_t *state, char const *str, size_t maxlen)
|
|
954
|
+
{
|
|
955
|
+
return zcbor_search_key_bstr_ptr(state, str, strnlen(str, maxlen));
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
bool zcbor_search_key_tstr_term(zcbor_state_t *state, char const *str, size_t maxlen)
|
|
960
|
+
{
|
|
961
|
+
return zcbor_search_key_tstr_ptr(state, str, strnlen(str, maxlen));
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
|
|
606
965
|
static bool array_end_expect(zcbor_state_t *state)
|
|
607
966
|
{
|
|
608
967
|
INITIAL_CHECKS();
|
|
@@ -617,15 +976,17 @@ static bool list_map_end_decode(zcbor_state_t *state)
|
|
|
617
976
|
{
|
|
618
977
|
size_t max_elem_count = 0;
|
|
619
978
|
|
|
620
|
-
|
|
979
|
+
#ifndef ZCBOR_CANONICAL
|
|
980
|
+
if (state->decode_state.indefinite_length_array) {
|
|
621
981
|
if (!array_end_expect(state)) {
|
|
622
982
|
ZCBOR_FAIL();
|
|
623
983
|
}
|
|
624
984
|
max_elem_count = ZCBOR_MAX_ELEM_COUNT;
|
|
625
|
-
state->indefinite_length_array = false;
|
|
985
|
+
state->decode_state.indefinite_length_array = false;
|
|
626
986
|
}
|
|
987
|
+
#endif
|
|
627
988
|
if (!zcbor_process_backup(state,
|
|
628
|
-
ZCBOR_FLAG_RESTORE | ZCBOR_FLAG_CONSUME |
|
|
989
|
+
ZCBOR_FLAG_RESTORE | ZCBOR_FLAG_CONSUME | ZCBOR_FLAG_KEEP_PAYLOAD,
|
|
629
990
|
max_elem_count)) {
|
|
630
991
|
ZCBOR_FAIL();
|
|
631
992
|
}
|
|
@@ -636,20 +997,51 @@ static bool list_map_end_decode(zcbor_state_t *state)
|
|
|
636
997
|
|
|
637
998
|
bool zcbor_list_end_decode(zcbor_state_t *state)
|
|
638
999
|
{
|
|
1000
|
+
PRINT_FUNC();
|
|
639
1001
|
return list_map_end_decode(state);
|
|
640
1002
|
}
|
|
641
1003
|
|
|
642
1004
|
|
|
643
1005
|
bool zcbor_map_end_decode(zcbor_state_t *state)
|
|
644
1006
|
{
|
|
1007
|
+
PRINT_FUNC();
|
|
645
1008
|
return list_map_end_decode(state);
|
|
646
1009
|
}
|
|
647
1010
|
|
|
648
1011
|
|
|
1012
|
+
bool zcbor_unordered_map_end_decode(zcbor_state_t *state)
|
|
1013
|
+
{
|
|
1014
|
+
/* Checking zcbor_array_at_end() ensures that check is valid.
|
|
1015
|
+
* In case the map is at the end, but state->decode_state.counting_map_elems isn't updated.*/
|
|
1016
|
+
ZCBOR_ERR_IF(!zcbor_array_at_end(state) && state->decode_state.counting_map_elems,
|
|
1017
|
+
ZCBOR_ERR_ELEMS_NOT_PROCESSED);
|
|
1018
|
+
|
|
1019
|
+
if (state->decode_state.map_elem_count > 0) {
|
|
1020
|
+
#ifdef ZCBOR_MAP_SMART_SEARCH
|
|
1021
|
+
manipulate_flags(state, FLAG_MODE_CLEAR_UNUSED);
|
|
1022
|
+
|
|
1023
|
+
for (size_t i = 0; i < zcbor_flags_to_bytes(state->decode_state.map_elem_count); i++) {
|
|
1024
|
+
if (state->decode_state.map_search_elem_state[i] != 0) {
|
|
1025
|
+
zcbor_log("unprocessed element(s) in map: [%zu] = 0x%02x\n",
|
|
1026
|
+
i, state->decode_state.map_search_elem_state[i]);
|
|
1027
|
+
ZCBOR_ERR(ZCBOR_ERR_ELEMS_NOT_PROCESSED);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
#else
|
|
1031
|
+
ZCBOR_ERR_IF(should_try_key(state), ZCBOR_ERR_ELEMS_NOT_PROCESSED);
|
|
1032
|
+
#endif
|
|
1033
|
+
}
|
|
1034
|
+
while (!zcbor_array_at_end(state)) {
|
|
1035
|
+
zcbor_any_skip(state, NULL);
|
|
1036
|
+
}
|
|
1037
|
+
return zcbor_map_end_decode(state);
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
|
|
649
1041
|
bool zcbor_list_map_end_force_decode(zcbor_state_t *state)
|
|
650
1042
|
{
|
|
651
1043
|
if (!zcbor_process_backup(state,
|
|
652
|
-
ZCBOR_FLAG_RESTORE | ZCBOR_FLAG_CONSUME |
|
|
1044
|
+
ZCBOR_FLAG_RESTORE | ZCBOR_FLAG_CONSUME | ZCBOR_FLAG_KEEP_PAYLOAD,
|
|
653
1045
|
ZCBOR_MAX_ELEM_COUNT)) {
|
|
654
1046
|
ZCBOR_FAIL();
|
|
655
1047
|
}
|
|
@@ -660,11 +1052,13 @@ bool zcbor_list_map_end_force_decode(zcbor_state_t *state)
|
|
|
660
1052
|
|
|
661
1053
|
bool zcbor_simple_decode(zcbor_state_t *state, uint8_t *result)
|
|
662
1054
|
{
|
|
1055
|
+
PRINT_FUNC();
|
|
1056
|
+
PRINT_FUNC();
|
|
663
1057
|
INITIAL_CHECKS_WITH_TYPE(ZCBOR_MAJOR_TYPE_SIMPLE);
|
|
664
1058
|
|
|
665
1059
|
/* Simple values must be 0-23 (additional is 0-23) or 24-255 (additional is 24).
|
|
666
1060
|
* Other additional values are not considered simple values. */
|
|
667
|
-
ZCBOR_ERR_IF(
|
|
1061
|
+
ZCBOR_ERR_IF(ZCBOR_ADDITIONAL(*state->payload) > 24, ZCBOR_ERR_WRONG_TYPE);
|
|
668
1062
|
|
|
669
1063
|
if (!value_extract(state, result, sizeof(*result))) {
|
|
670
1064
|
ZCBOR_FAIL();
|
|
@@ -673,16 +1067,17 @@ bool zcbor_simple_decode(zcbor_state_t *state, uint8_t *result)
|
|
|
673
1067
|
}
|
|
674
1068
|
|
|
675
1069
|
|
|
676
|
-
bool zcbor_simple_expect(zcbor_state_t *state, uint8_t
|
|
1070
|
+
bool zcbor_simple_expect(zcbor_state_t *state, uint8_t expected)
|
|
677
1071
|
{
|
|
678
|
-
|
|
1072
|
+
PRINT_FUNC();
|
|
1073
|
+
uint8_t actual;
|
|
679
1074
|
|
|
680
|
-
if (!zcbor_simple_decode(state, &
|
|
1075
|
+
if (!zcbor_simple_decode(state, &actual)) {
|
|
681
1076
|
ZCBOR_FAIL();
|
|
682
1077
|
}
|
|
683
1078
|
|
|
684
|
-
if (
|
|
685
|
-
|
|
1079
|
+
if (actual != expected) {
|
|
1080
|
+
zcbor_log("simple value %u != %u\r\n", actual, expected);
|
|
686
1081
|
ERR_RESTORE(ZCBOR_ERR_WRONG_VALUE);
|
|
687
1082
|
}
|
|
688
1083
|
|
|
@@ -690,8 +1085,16 @@ bool zcbor_simple_expect(zcbor_state_t *state, uint8_t result)
|
|
|
690
1085
|
}
|
|
691
1086
|
|
|
692
1087
|
|
|
1088
|
+
bool zcbor_simple_pexpect(zcbor_state_t *state, uint8_t *expected)
|
|
1089
|
+
{
|
|
1090
|
+
PRINT_FUNC();
|
|
1091
|
+
return zcbor_simple_expect(state, *expected);
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
|
|
693
1095
|
bool zcbor_nil_expect(zcbor_state_t *state, void *unused)
|
|
694
1096
|
{
|
|
1097
|
+
PRINT_FUNC();
|
|
695
1098
|
(void)unused;
|
|
696
1099
|
return zcbor_simple_expect(state, 22);
|
|
697
1100
|
}
|
|
@@ -699,6 +1102,7 @@ bool zcbor_nil_expect(zcbor_state_t *state, void *unused)
|
|
|
699
1102
|
|
|
700
1103
|
bool zcbor_undefined_expect(zcbor_state_t *state, void *unused)
|
|
701
1104
|
{
|
|
1105
|
+
PRINT_FUNC();
|
|
702
1106
|
(void)unused;
|
|
703
1107
|
return zcbor_simple_expect(state, 23);
|
|
704
1108
|
}
|
|
@@ -706,6 +1110,7 @@ bool zcbor_undefined_expect(zcbor_state_t *state, void *unused)
|
|
|
706
1110
|
|
|
707
1111
|
bool zcbor_bool_decode(zcbor_state_t *state, bool *result)
|
|
708
1112
|
{
|
|
1113
|
+
PRINT_FUNC();
|
|
709
1114
|
uint8_t value;
|
|
710
1115
|
|
|
711
1116
|
if (!zcbor_simple_decode(state, &value)) {
|
|
@@ -717,28 +1122,36 @@ bool zcbor_bool_decode(zcbor_state_t *state, bool *result)
|
|
|
717
1122
|
}
|
|
718
1123
|
*result = value;
|
|
719
1124
|
|
|
720
|
-
|
|
1125
|
+
zcbor_log("boolval: %u\r\n", *result);
|
|
721
1126
|
return true;
|
|
722
1127
|
}
|
|
723
1128
|
|
|
724
1129
|
|
|
725
|
-
bool zcbor_bool_expect(zcbor_state_t *state, bool
|
|
1130
|
+
bool zcbor_bool_expect(zcbor_state_t *state, bool expected)
|
|
1131
|
+
{
|
|
1132
|
+
PRINT_FUNC();
|
|
1133
|
+
return zcbor_simple_expect(state, (uint8_t)(!!expected) + ZCBOR_BOOL_TO_SIMPLE);
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
|
|
1137
|
+
bool zcbor_bool_pexpect(zcbor_state_t *state, bool *expected)
|
|
726
1138
|
{
|
|
727
|
-
|
|
1139
|
+
PRINT_FUNC();
|
|
1140
|
+
return zcbor_bool_expect(state, *expected);
|
|
728
1141
|
}
|
|
729
1142
|
|
|
730
1143
|
|
|
731
1144
|
static bool float_check(zcbor_state_t *state, uint8_t additional_val)
|
|
732
1145
|
{
|
|
733
1146
|
INITIAL_CHECKS_WITH_TYPE(ZCBOR_MAJOR_TYPE_SIMPLE);
|
|
734
|
-
ZCBOR_ERR_IF(
|
|
1147
|
+
ZCBOR_ERR_IF(ZCBOR_ADDITIONAL(*state->payload) != additional_val, ZCBOR_ERR_FLOAT_SIZE);
|
|
735
1148
|
return true;
|
|
736
1149
|
}
|
|
737
1150
|
|
|
738
1151
|
|
|
739
1152
|
bool zcbor_float16_bytes_decode(zcbor_state_t *state, uint16_t *result)
|
|
740
1153
|
{
|
|
741
|
-
|
|
1154
|
+
PRINT_FUNC();
|
|
742
1155
|
ZCBOR_FAIL_IF(!float_check(state, ZCBOR_VALUE_IS_2_BYTES));
|
|
743
1156
|
|
|
744
1157
|
if (!value_extract(state, result, sizeof(*result))) {
|
|
@@ -749,81 +1162,67 @@ bool zcbor_float16_bytes_decode(zcbor_state_t *state, uint16_t *result)
|
|
|
749
1162
|
}
|
|
750
1163
|
|
|
751
1164
|
|
|
752
|
-
bool zcbor_float16_bytes_expect(zcbor_state_t *state, uint16_t
|
|
1165
|
+
bool zcbor_float16_bytes_expect(zcbor_state_t *state, uint16_t expected)
|
|
753
1166
|
{
|
|
754
|
-
|
|
1167
|
+
PRINT_FUNC();
|
|
1168
|
+
uint16_t actual;
|
|
755
1169
|
|
|
756
|
-
if (!zcbor_float16_bytes_decode(state, &
|
|
1170
|
+
if (!zcbor_float16_bytes_decode(state, &actual)) {
|
|
757
1171
|
ZCBOR_FAIL();
|
|
758
1172
|
}
|
|
759
|
-
if (
|
|
1173
|
+
if (actual != expected) {
|
|
760
1174
|
ERR_RESTORE(ZCBOR_ERR_WRONG_VALUE);
|
|
761
1175
|
}
|
|
762
1176
|
return true;
|
|
763
1177
|
}
|
|
764
1178
|
|
|
765
1179
|
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
#define F16_MIN_EXPO 24 /* Negative exponent of the non-zero float16 value closest to 0 (2^-24) */
|
|
772
|
-
#define F16_MIN (1.0 / (1 << F16_MIN_EXPO)) /* The non-zero float16 value closest to 0 (2^-24) */
|
|
773
|
-
#define F16_BIAS 15 /* The exponent bias of normalized float16 values. */
|
|
774
|
-
|
|
775
|
-
/* Float32: */
|
|
776
|
-
#define F32_SIGN_OFFS 31 /* Bit offset of the sign bit. */
|
|
777
|
-
#define F32_EXPO_OFFS 23 /* Bit offset of the exponent. */
|
|
778
|
-
#define F32_EXPO_MSK 0xFF /* Bitmask for the exponent (right shifted by F32_EXPO_OFFS). */
|
|
779
|
-
#define F32_BIAS 127 /* The exponent bias of normalized float32 values. */
|
|
1180
|
+
bool zcbor_float16_bytes_pexpect(zcbor_state_t *state, uint16_t *expected)
|
|
1181
|
+
{
|
|
1182
|
+
PRINT_FUNC();
|
|
1183
|
+
return zcbor_float16_bytes_expect(state, *expected);
|
|
1184
|
+
}
|
|
780
1185
|
|
|
781
1186
|
|
|
782
1187
|
bool zcbor_float16_decode(zcbor_state_t *state, float *result)
|
|
783
1188
|
{
|
|
1189
|
+
PRINT_FUNC();
|
|
784
1190
|
uint16_t value16;
|
|
785
1191
|
|
|
786
1192
|
if (!zcbor_float16_bytes_decode(state, &value16)) {
|
|
787
1193
|
ZCBOR_FAIL();
|
|
788
1194
|
}
|
|
789
1195
|
|
|
790
|
-
|
|
791
|
-
uint32_t expo = (value16 >> F16_EXPO_OFFS) & F16_EXPO_MSK;
|
|
792
|
-
uint32_t mantissa = value16 & F16_MANTISSA_MSK;
|
|
793
|
-
|
|
794
|
-
if ((expo == 0) && (mantissa != 0)) {
|
|
795
|
-
/* Subnormal float16 - convert to normalized float32 */
|
|
796
|
-
*result = ((float)mantissa * (float)F16_MIN) * (sign ? -1 : 1);
|
|
797
|
-
} else {
|
|
798
|
-
/* Normalized / zero / Infinity / NaN */
|
|
799
|
-
uint32_t new_expo = (expo == 0 /* zero */) ? 0
|
|
800
|
-
: (expo == F16_EXPO_MSK /* inf/NaN */) ? F32_EXPO_MSK
|
|
801
|
-
: (expo + (F32_BIAS - F16_BIAS));
|
|
802
|
-
uint32_t value32 = (sign << F32_SIGN_OFFS) | (new_expo << F32_EXPO_OFFS)
|
|
803
|
-
| (mantissa << (F32_EXPO_OFFS - F16_EXPO_OFFS));
|
|
804
|
-
memcpy(result, &value32, sizeof(*result));
|
|
805
|
-
}
|
|
806
|
-
|
|
1196
|
+
*result = zcbor_float16_to_32(value16);
|
|
807
1197
|
return true;
|
|
808
1198
|
}
|
|
809
1199
|
|
|
810
1200
|
|
|
811
|
-
bool zcbor_float16_expect(zcbor_state_t *state, float
|
|
1201
|
+
bool zcbor_float16_expect(zcbor_state_t *state, float expected)
|
|
812
1202
|
{
|
|
813
|
-
|
|
1203
|
+
PRINT_FUNC();
|
|
1204
|
+
float actual;
|
|
814
1205
|
|
|
815
|
-
if (!zcbor_float16_decode(state, &
|
|
1206
|
+
if (!zcbor_float16_decode(state, &actual)) {
|
|
816
1207
|
ZCBOR_FAIL();
|
|
817
1208
|
}
|
|
818
|
-
if (
|
|
1209
|
+
if (actual != expected) {
|
|
819
1210
|
ERR_RESTORE(ZCBOR_ERR_WRONG_VALUE);
|
|
820
1211
|
}
|
|
821
1212
|
return true;
|
|
822
1213
|
}
|
|
823
1214
|
|
|
824
1215
|
|
|
1216
|
+
bool zcbor_float16_pexpect(zcbor_state_t *state, float *expected)
|
|
1217
|
+
{
|
|
1218
|
+
PRINT_FUNC();
|
|
1219
|
+
return zcbor_float16_expect(state, *expected);
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
|
|
825
1223
|
bool zcbor_float32_decode(zcbor_state_t *state, float *result)
|
|
826
1224
|
{
|
|
1225
|
+
PRINT_FUNC();
|
|
827
1226
|
ZCBOR_FAIL_IF(!float_check(state, ZCBOR_VALUE_IS_4_BYTES));
|
|
828
1227
|
|
|
829
1228
|
if (!value_extract(state, result, sizeof(*result))) {
|
|
@@ -834,22 +1233,31 @@ bool zcbor_float32_decode(zcbor_state_t *state, float *result)
|
|
|
834
1233
|
}
|
|
835
1234
|
|
|
836
1235
|
|
|
837
|
-
bool zcbor_float32_expect(zcbor_state_t *state, float
|
|
1236
|
+
bool zcbor_float32_expect(zcbor_state_t *state, float expected)
|
|
838
1237
|
{
|
|
839
|
-
|
|
1238
|
+
PRINT_FUNC();
|
|
1239
|
+
float actual;
|
|
840
1240
|
|
|
841
|
-
if (!zcbor_float32_decode(state, &
|
|
1241
|
+
if (!zcbor_float32_decode(state, &actual)) {
|
|
842
1242
|
ZCBOR_FAIL();
|
|
843
1243
|
}
|
|
844
|
-
if (
|
|
1244
|
+
if (actual != expected) {
|
|
845
1245
|
ERR_RESTORE(ZCBOR_ERR_WRONG_VALUE);
|
|
846
1246
|
}
|
|
847
1247
|
return true;
|
|
848
1248
|
}
|
|
849
1249
|
|
|
850
1250
|
|
|
1251
|
+
bool zcbor_float32_pexpect(zcbor_state_t *state, float *expected)
|
|
1252
|
+
{
|
|
1253
|
+
PRINT_FUNC();
|
|
1254
|
+
return zcbor_float32_expect(state, *expected);
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
|
|
851
1258
|
bool zcbor_float16_32_decode(zcbor_state_t *state, float *result)
|
|
852
1259
|
{
|
|
1260
|
+
PRINT_FUNC();
|
|
853
1261
|
if (zcbor_float16_decode(state, result)) {
|
|
854
1262
|
/* Do nothing */
|
|
855
1263
|
} else if (!zcbor_float32_decode(state, result)) {
|
|
@@ -860,11 +1268,12 @@ bool zcbor_float16_32_decode(zcbor_state_t *state, float *result)
|
|
|
860
1268
|
}
|
|
861
1269
|
|
|
862
1270
|
|
|
863
|
-
bool zcbor_float16_32_expect(zcbor_state_t *state, float
|
|
1271
|
+
bool zcbor_float16_32_expect(zcbor_state_t *state, float expected)
|
|
864
1272
|
{
|
|
865
|
-
|
|
1273
|
+
PRINT_FUNC();
|
|
1274
|
+
if (zcbor_float16_expect(state, expected)) {
|
|
866
1275
|
/* Do nothing */
|
|
867
|
-
} else if (!zcbor_float32_expect(state,
|
|
1276
|
+
} else if (!zcbor_float32_expect(state, expected)) {
|
|
868
1277
|
ZCBOR_FAIL();
|
|
869
1278
|
}
|
|
870
1279
|
|
|
@@ -872,8 +1281,16 @@ bool zcbor_float16_32_expect(zcbor_state_t *state, float result)
|
|
|
872
1281
|
}
|
|
873
1282
|
|
|
874
1283
|
|
|
1284
|
+
bool zcbor_float16_32_pexpect(zcbor_state_t *state, float *expected)
|
|
1285
|
+
{
|
|
1286
|
+
PRINT_FUNC();
|
|
1287
|
+
return zcbor_float16_32_expect(state, *expected);
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
|
|
875
1291
|
bool zcbor_float64_decode(zcbor_state_t *state, double *result)
|
|
876
1292
|
{
|
|
1293
|
+
PRINT_FUNC();
|
|
877
1294
|
ZCBOR_FAIL_IF(!float_check(state, ZCBOR_VALUE_IS_8_BYTES));
|
|
878
1295
|
|
|
879
1296
|
if (!value_extract(state, result, sizeof(*result))) {
|
|
@@ -884,22 +1301,31 @@ bool zcbor_float64_decode(zcbor_state_t *state, double *result)
|
|
|
884
1301
|
}
|
|
885
1302
|
|
|
886
1303
|
|
|
887
|
-
bool zcbor_float64_expect(zcbor_state_t *state, double
|
|
1304
|
+
bool zcbor_float64_expect(zcbor_state_t *state, double expected)
|
|
888
1305
|
{
|
|
889
|
-
|
|
1306
|
+
PRINT_FUNC();
|
|
1307
|
+
double actual;
|
|
890
1308
|
|
|
891
|
-
if (!zcbor_float64_decode(state, &
|
|
1309
|
+
if (!zcbor_float64_decode(state, &actual)) {
|
|
892
1310
|
ZCBOR_FAIL();
|
|
893
1311
|
}
|
|
894
|
-
if (
|
|
1312
|
+
if (actual != expected) {
|
|
895
1313
|
ERR_RESTORE(ZCBOR_ERR_WRONG_VALUE);
|
|
896
1314
|
}
|
|
897
1315
|
return true;
|
|
898
1316
|
}
|
|
899
1317
|
|
|
900
1318
|
|
|
1319
|
+
bool zcbor_float64_pexpect(zcbor_state_t *state, double *expected)
|
|
1320
|
+
{
|
|
1321
|
+
PRINT_FUNC();
|
|
1322
|
+
return zcbor_float64_expect(state, *expected);
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
|
|
901
1326
|
bool zcbor_float32_64_decode(zcbor_state_t *state, double *result)
|
|
902
1327
|
{
|
|
1328
|
+
PRINT_FUNC();
|
|
903
1329
|
float float_result;
|
|
904
1330
|
|
|
905
1331
|
if (zcbor_float32_decode(state, &float_result)) {
|
|
@@ -912,11 +1338,12 @@ bool zcbor_float32_64_decode(zcbor_state_t *state, double *result)
|
|
|
912
1338
|
}
|
|
913
1339
|
|
|
914
1340
|
|
|
915
|
-
bool zcbor_float32_64_expect(zcbor_state_t *state, double
|
|
1341
|
+
bool zcbor_float32_64_expect(zcbor_state_t *state, double expected)
|
|
916
1342
|
{
|
|
917
|
-
|
|
1343
|
+
PRINT_FUNC();
|
|
1344
|
+
if (zcbor_float64_expect(state, expected)) {
|
|
918
1345
|
/* Do nothing */
|
|
919
|
-
} else if (!zcbor_float32_expect(state, (float)
|
|
1346
|
+
} else if (!zcbor_float32_expect(state, (float)expected)) {
|
|
920
1347
|
ZCBOR_FAIL();
|
|
921
1348
|
}
|
|
922
1349
|
|
|
@@ -924,8 +1351,16 @@ bool zcbor_float32_64_expect(zcbor_state_t *state, double result)
|
|
|
924
1351
|
}
|
|
925
1352
|
|
|
926
1353
|
|
|
1354
|
+
bool zcbor_float32_64_pexpect(zcbor_state_t *state, double *expected)
|
|
1355
|
+
{
|
|
1356
|
+
PRINT_FUNC();
|
|
1357
|
+
return zcbor_float32_64_expect(state, *expected);
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
|
|
927
1361
|
bool zcbor_float_decode(zcbor_state_t *state, double *result)
|
|
928
1362
|
{
|
|
1363
|
+
PRINT_FUNC();
|
|
929
1364
|
float float_result;
|
|
930
1365
|
|
|
931
1366
|
if (zcbor_float16_decode(state, &float_result)) {
|
|
@@ -940,13 +1375,14 @@ bool zcbor_float_decode(zcbor_state_t *state, double *result)
|
|
|
940
1375
|
}
|
|
941
1376
|
|
|
942
1377
|
|
|
943
|
-
bool zcbor_float_expect(zcbor_state_t *state, double
|
|
1378
|
+
bool zcbor_float_expect(zcbor_state_t *state, double expected)
|
|
944
1379
|
{
|
|
945
|
-
|
|
1380
|
+
PRINT_FUNC();
|
|
1381
|
+
if (zcbor_float16_expect(state, (float)expected)) {
|
|
946
1382
|
/* Do nothing */
|
|
947
|
-
} else if (zcbor_float32_expect(state, (float)
|
|
1383
|
+
} else if (zcbor_float32_expect(state, (float)expected)) {
|
|
948
1384
|
/* Do nothing */
|
|
949
|
-
} else if (!zcbor_float64_expect(state,
|
|
1385
|
+
} else if (!zcbor_float64_expect(state, expected)) {
|
|
950
1386
|
ZCBOR_FAIL();
|
|
951
1387
|
}
|
|
952
1388
|
|
|
@@ -954,15 +1390,23 @@ bool zcbor_float_expect(zcbor_state_t *state, double result)
|
|
|
954
1390
|
}
|
|
955
1391
|
|
|
956
1392
|
|
|
1393
|
+
bool zcbor_float_pexpect(zcbor_state_t *state, double *expected)
|
|
1394
|
+
{
|
|
1395
|
+
PRINT_FUNC();
|
|
1396
|
+
return zcbor_float_expect(state, *expected);
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
|
|
957
1400
|
bool zcbor_any_skip(zcbor_state_t *state, void *result)
|
|
958
1401
|
{
|
|
1402
|
+
PRINT_FUNC();
|
|
959
1403
|
zcbor_assert_state(result == NULL,
|
|
960
1404
|
"'any' type cannot be returned, only skipped.\r\n");
|
|
961
1405
|
(void)result;
|
|
962
1406
|
|
|
963
1407
|
INITIAL_CHECKS();
|
|
964
|
-
zcbor_major_type_t major_type =
|
|
965
|
-
uint8_t additional =
|
|
1408
|
+
zcbor_major_type_t major_type = ZCBOR_MAJOR_TYPE(*state->payload);
|
|
1409
|
+
uint8_t additional = ZCBOR_ADDITIONAL(*state->payload);
|
|
966
1410
|
uint64_t value = 0; /* In case of indefinite_length_array. */
|
|
967
1411
|
zcbor_state_t state_copy;
|
|
968
1412
|
|
|
@@ -975,12 +1419,16 @@ bool zcbor_any_skip(zcbor_state_t *state, void *result)
|
|
|
975
1419
|
ZCBOR_FAIL();
|
|
976
1420
|
}
|
|
977
1421
|
ZCBOR_ERR_IF(state_copy.payload >= state_copy.payload_end, ZCBOR_ERR_NO_PAYLOAD);
|
|
978
|
-
major_type =
|
|
979
|
-
additional =
|
|
1422
|
+
major_type = ZCBOR_MAJOR_TYPE(*state_copy.payload);
|
|
1423
|
+
additional = ZCBOR_ADDITIONAL(*state_copy.payload);
|
|
980
1424
|
}
|
|
981
1425
|
|
|
1426
|
+
#ifdef ZCBOR_CANONICAL
|
|
1427
|
+
const bool indefinite_length_array = false;
|
|
1428
|
+
#else
|
|
982
1429
|
const bool indefinite_length_array = ((additional == ZCBOR_VALUE_IS_INDEFINITE_LENGTH)
|
|
983
1430
|
&& ((major_type == ZCBOR_MAJOR_TYPE_LIST) || (major_type == ZCBOR_MAJOR_TYPE_MAP)));
|
|
1431
|
+
#endif
|
|
984
1432
|
|
|
985
1433
|
if (!indefinite_length_array && !value_extract(&state_copy, &value, sizeof(value))) {
|
|
986
1434
|
/* Can happen because of elem_count (or payload_end) */
|
|
@@ -991,7 +1439,7 @@ bool zcbor_any_skip(zcbor_state_t *state, void *result)
|
|
|
991
1439
|
case ZCBOR_MAJOR_TYPE_BSTR:
|
|
992
1440
|
case ZCBOR_MAJOR_TYPE_TSTR:
|
|
993
1441
|
/* 'value' is the length of the BSTR or TSTR.
|
|
994
|
-
* The
|
|
1442
|
+
* The subtraction is safe because value_extract() above
|
|
995
1443
|
* checks that payload_end is greater than payload. */
|
|
996
1444
|
ZCBOR_ERR_IF(
|
|
997
1445
|
value > (uint64_t)(state_copy.payload_end - state_copy.payload),
|
|
@@ -1008,7 +1456,7 @@ bool zcbor_any_skip(zcbor_state_t *state, void *result)
|
|
|
1008
1456
|
value = ZCBOR_LARGE_ELEM_COUNT;
|
|
1009
1457
|
}
|
|
1010
1458
|
state_copy.elem_count = (size_t)value;
|
|
1011
|
-
state_copy.indefinite_length_array = indefinite_length_array;
|
|
1459
|
+
state_copy.decode_state.indefinite_length_array = indefinite_length_array;
|
|
1012
1460
|
while (!zcbor_array_at_end(&state_copy)) {
|
|
1013
1461
|
if (!zcbor_any_skip(&state_copy, NULL)) {
|
|
1014
1462
|
ZCBOR_FAIL();
|
|
@@ -1032,6 +1480,7 @@ bool zcbor_any_skip(zcbor_state_t *state, void *result)
|
|
|
1032
1480
|
|
|
1033
1481
|
bool zcbor_tag_decode(zcbor_state_t *state, uint32_t *result)
|
|
1034
1482
|
{
|
|
1483
|
+
PRINT_FUNC();
|
|
1035
1484
|
INITIAL_CHECKS_WITH_TYPE(ZCBOR_MAJOR_TYPE_TAG);
|
|
1036
1485
|
|
|
1037
1486
|
if (!value_extract(state, result, sizeof(*result))) {
|
|
@@ -1042,20 +1491,28 @@ bool zcbor_tag_decode(zcbor_state_t *state, uint32_t *result)
|
|
|
1042
1491
|
}
|
|
1043
1492
|
|
|
1044
1493
|
|
|
1045
|
-
bool zcbor_tag_expect(zcbor_state_t *state, uint32_t
|
|
1494
|
+
bool zcbor_tag_expect(zcbor_state_t *state, uint32_t expected)
|
|
1046
1495
|
{
|
|
1047
|
-
|
|
1496
|
+
PRINT_FUNC();
|
|
1497
|
+
uint32_t actual;
|
|
1048
1498
|
|
|
1049
|
-
if (!zcbor_tag_decode(state, &
|
|
1499
|
+
if (!zcbor_tag_decode(state, &actual)) {
|
|
1050
1500
|
ZCBOR_FAIL();
|
|
1051
1501
|
}
|
|
1052
|
-
if (
|
|
1502
|
+
if (actual != expected) {
|
|
1053
1503
|
ERR_RESTORE(ZCBOR_ERR_WRONG_VALUE);
|
|
1054
1504
|
}
|
|
1055
1505
|
return true;
|
|
1056
1506
|
}
|
|
1057
1507
|
|
|
1058
1508
|
|
|
1509
|
+
bool zcbor_tag_pexpect(zcbor_state_t *state, uint32_t *expected)
|
|
1510
|
+
{
|
|
1511
|
+
PRINT_FUNC();
|
|
1512
|
+
return zcbor_tag_expect(state, *expected);
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
|
|
1059
1516
|
bool zcbor_multi_decode(size_t min_decode,
|
|
1060
1517
|
size_t max_decode,
|
|
1061
1518
|
size_t *num_decode,
|
|
@@ -1064,6 +1521,7 @@ bool zcbor_multi_decode(size_t min_decode,
|
|
|
1064
1521
|
void *result,
|
|
1065
1522
|
size_t result_len)
|
|
1066
1523
|
{
|
|
1524
|
+
PRINT_FUNC();
|
|
1067
1525
|
ZCBOR_CHECK_ERROR();
|
|
1068
1526
|
for (size_t i = 0; i < max_decode; i++) {
|
|
1069
1527
|
uint8_t const *payload_bak = state->payload;
|
|
@@ -1075,11 +1533,11 @@ bool zcbor_multi_decode(size_t min_decode,
|
|
|
1075
1533
|
state->payload = payload_bak;
|
|
1076
1534
|
state->elem_count = elem_count_bak;
|
|
1077
1535
|
ZCBOR_ERR_IF(i < min_decode, ZCBOR_ERR_ITERATIONS);
|
|
1078
|
-
|
|
1536
|
+
zcbor_log("Found %zu elements.\r\n", i);
|
|
1079
1537
|
return true;
|
|
1080
1538
|
}
|
|
1081
1539
|
}
|
|
1082
|
-
|
|
1540
|
+
zcbor_log("Found %zu elements.\r\n", max_decode);
|
|
1083
1541
|
*num_decode = max_decode;
|
|
1084
1542
|
return true;
|
|
1085
1543
|
}
|
|
@@ -1090,7 +1548,8 @@ bool zcbor_present_decode(bool *present,
|
|
|
1090
1548
|
zcbor_state_t *state,
|
|
1091
1549
|
void *result)
|
|
1092
1550
|
{
|
|
1093
|
-
|
|
1551
|
+
PRINT_FUNC();
|
|
1552
|
+
size_t num_decode = 0;
|
|
1094
1553
|
bool retval = zcbor_multi_decode(0, 1, &num_decode, decoder, state, result, 0);
|
|
1095
1554
|
|
|
1096
1555
|
zcbor_assert_state(retval, "zcbor_multi_decode should not fail with these parameters.\r\n");
|
|
@@ -1101,7 +1560,8 @@ bool zcbor_present_decode(bool *present,
|
|
|
1101
1560
|
|
|
1102
1561
|
|
|
1103
1562
|
void zcbor_new_decode_state(zcbor_state_t *state_array, size_t n_states,
|
|
1104
|
-
const uint8_t *payload, size_t payload_len, size_t elem_count
|
|
1563
|
+
const uint8_t *payload, size_t payload_len, size_t elem_count,
|
|
1564
|
+
uint8_t *flags, size_t flags_bytes)
|
|
1105
1565
|
{
|
|
1106
|
-
zcbor_new_state(state_array, n_states, payload, payload_len, elem_count);
|
|
1566
|
+
zcbor_new_state(state_array, n_states, payload, payload_len, elem_count, flags, flags_bytes);
|
|
1107
1567
|
}
|