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
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
#include <zephyr/ztest.h>
|
|
8
8
|
#include "zcbor_decode.h"
|
|
9
9
|
#include "zcbor_encode.h"
|
|
10
|
-
#include "
|
|
10
|
+
#include "zcbor_print.h"
|
|
11
11
|
|
|
12
12
|
ZTEST(zcbor_unit_tests, test_int64)
|
|
13
13
|
{
|
|
@@ -16,7 +16,7 @@ ZTEST(zcbor_unit_tests, test_int64)
|
|
|
16
16
|
int32_t int32;
|
|
17
17
|
|
|
18
18
|
ZCBOR_STATE_E(state_e, 0, payload, sizeof(payload), 0);
|
|
19
|
-
ZCBOR_STATE_D(state_d, 0, payload, sizeof(payload), 10);
|
|
19
|
+
ZCBOR_STATE_D(state_d, 0, payload, sizeof(payload), 10, 0);
|
|
20
20
|
|
|
21
21
|
zassert_true(zcbor_int64_put(state_e, 5), NULL);
|
|
22
22
|
zassert_false(zcbor_int64_expect(state_d, 4), NULL);
|
|
@@ -68,9 +68,9 @@ ZTEST(zcbor_unit_tests, test_uint64)
|
|
|
68
68
|
uint32_t uint32;
|
|
69
69
|
|
|
70
70
|
zcbor_state_t state_e;
|
|
71
|
-
zcbor_new_state(&state_e, 1, payload, sizeof(payload), 0);
|
|
71
|
+
zcbor_new_state(&state_e, 1, payload, sizeof(payload), 0, NULL, 0);
|
|
72
72
|
zcbor_state_t state_d;
|
|
73
|
-
zcbor_new_state(&state_d, 1, payload, sizeof(payload), 10);
|
|
73
|
+
zcbor_new_state(&state_d, 1, payload, sizeof(payload), 10, NULL, 0);
|
|
74
74
|
|
|
75
75
|
zassert_true(zcbor_uint64_put(&state_e, 5), NULL);
|
|
76
76
|
zassert_false(zcbor_uint64_expect(&state_d, 4), NULL);
|
|
@@ -101,9 +101,9 @@ ZTEST(zcbor_unit_tests, test_size)
|
|
|
101
101
|
size_t read;
|
|
102
102
|
|
|
103
103
|
zcbor_state_t state_e;
|
|
104
|
-
zcbor_new_state(&state_e, 1, payload, sizeof(payload), 0);
|
|
104
|
+
zcbor_new_state(&state_e, 1, payload, sizeof(payload), 0, NULL, 0);
|
|
105
105
|
zcbor_state_t state_d;
|
|
106
|
-
zcbor_new_state(&state_d, 1, payload, sizeof(payload), 10);
|
|
106
|
+
zcbor_new_state(&state_d, 1, payload, sizeof(payload), 10, NULL, 0);
|
|
107
107
|
|
|
108
108
|
zassert_true(zcbor_size_put(&state_e, 5), NULL);
|
|
109
109
|
zassert_false(zcbor_size_expect(&state_d, 4), NULL);
|
|
@@ -163,7 +163,7 @@ ZTEST(zcbor_unit_tests, test_size64)
|
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
ZCBOR_STATE_E(state_e, 0, large_payload, PAYL_SIZE, 0);
|
|
166
|
-
ZCBOR_STATE_D(state_d, 0, large_payload, PAYL_SIZE, 10);
|
|
166
|
+
ZCBOR_STATE_D(state_d, 0, large_payload, PAYL_SIZE, 10, 0);
|
|
167
167
|
|
|
168
168
|
zassert_true(zcbor_tstr_encode(state_e, &tstr), NULL);
|
|
169
169
|
zassert_false(zcbor_bstr_decode(state_d, &tstr_res), NULL);
|
|
@@ -177,7 +177,7 @@ ZTEST(zcbor_unit_tests, test_size64)
|
|
|
177
177
|
#else
|
|
178
178
|
ZTEST(zcbor_unit_tests, test_size64)
|
|
179
179
|
{
|
|
180
|
-
|
|
180
|
+
printf("Skip on non-64-bit builds.\n");
|
|
181
181
|
}
|
|
182
182
|
#endif
|
|
183
183
|
|
|
@@ -189,27 +189,29 @@ ZTEST(zcbor_unit_tests, test_string_macros)
|
|
|
189
189
|
char world[] = {'w', 'o', 'r', 'l', 'd'};
|
|
190
190
|
|
|
191
191
|
zassert_true(zcbor_bstr_put_lit(state_e, "Hello"), NULL);
|
|
192
|
-
zassert_true(zcbor_bstr_put_term(state_e, "Hello"), NULL);
|
|
192
|
+
zassert_true(zcbor_bstr_put_term(state_e, "Hello world", 5), NULL); /* Check that strnlen cuts off at 5 */
|
|
193
193
|
zassert_true(zcbor_bstr_put_arr(state_e, world), NULL);
|
|
194
194
|
zassert_true(zcbor_tstr_put_lit(state_e, "Hello"), NULL);
|
|
195
|
-
zassert_true(zcbor_tstr_put_term(state_e, "
|
|
195
|
+
zassert_true(zcbor_tstr_put_term(state_e, "Hellooooo", 5), NULL); /* Check that strnlen cuts off at 5 */
|
|
196
196
|
zassert_true(zcbor_tstr_put_arr(state_e, world), NULL);
|
|
197
197
|
|
|
198
|
-
ZCBOR_STATE_D(state_d, 0, payload, sizeof(payload), 6);
|
|
198
|
+
ZCBOR_STATE_D(state_d, 0, payload, sizeof(payload), 6, 0);
|
|
199
199
|
|
|
200
200
|
zassert_false(zcbor_bstr_expect_lit(state_d, "Yello"), NULL);
|
|
201
201
|
zassert_false(zcbor_tstr_expect_lit(state_d, "Hello"), NULL);
|
|
202
202
|
zassert_true(zcbor_bstr_expect_lit(state_d, "Hello"), NULL);
|
|
203
|
-
zassert_false(zcbor_bstr_expect_term(state_d, "Hello!"), NULL);
|
|
204
|
-
|
|
203
|
+
zassert_false(zcbor_bstr_expect_term(state_d, "Hello!", 10), NULL);
|
|
204
|
+
zassert_false(zcbor_bstr_expect_term(state_d, "Hello", 4), NULL); /* Check that strnlen cuts off at 4 */
|
|
205
|
+
zassert_true(zcbor_bstr_expect_term(state_d, "Hello", 5), NULL);
|
|
205
206
|
world[3]++;
|
|
206
207
|
zassert_false(zcbor_bstr_expect_arr(state_d, world), NULL);
|
|
207
208
|
world[3]--;
|
|
208
209
|
zassert_true(zcbor_bstr_expect_arr(state_d, world), NULL);
|
|
209
210
|
zassert_false(zcbor_tstr_expect_lit(state_d, "hello"), NULL);
|
|
210
211
|
zassert_true(zcbor_tstr_expect_lit(state_d, "Hello"), NULL);
|
|
211
|
-
zassert_false(zcbor_tstr_expect_term(state_d, "Helo"), NULL);
|
|
212
|
-
|
|
212
|
+
zassert_false(zcbor_tstr_expect_term(state_d, "Helo", 10), NULL);
|
|
213
|
+
zassert_false(zcbor_tstr_expect_term(state_d, "Hello", 0), NULL);
|
|
214
|
+
zassert_true(zcbor_tstr_expect_term(state_d, "Hello", 10), NULL);
|
|
213
215
|
world[2]++;
|
|
214
216
|
zassert_false(zcbor_tstr_expect_arr(state_d, world), NULL);
|
|
215
217
|
world[2]--;
|
|
@@ -247,7 +249,8 @@ ZTEST(zcbor_unit_tests, test_stop_on_error)
|
|
|
247
249
|
zassert_false(zcbor_size_encode(state_e, &(size_t){9}), NULL);
|
|
248
250
|
zassert_false(zcbor_bstr_put_lit(state_e, "Hello"), NULL);
|
|
249
251
|
zassert_false(zcbor_tstr_put_lit(state_e, "World"), NULL);
|
|
250
|
-
zassert_false(
|
|
252
|
+
zassert_false(zcbor_tag_put(state_e, 9), NULL);
|
|
253
|
+
zassert_false(zcbor_tag_encode(state_e, &(uint32_t){10}));
|
|
251
254
|
zassert_false(zcbor_bool_put(state_e, true), NULL);
|
|
252
255
|
zassert_false(zcbor_bool_encode(state_e, &(bool){false}), NULL);
|
|
253
256
|
zassert_false(zcbor_float32_put(state_e, 10.5), NULL);
|
|
@@ -264,7 +267,6 @@ ZTEST(zcbor_unit_tests, test_stop_on_error)
|
|
|
264
267
|
zassert_false(zcbor_list_end_encode(state_e, 1), NULL);
|
|
265
268
|
zassert_false(zcbor_multi_encode(1, (zcbor_encoder_t *)zcbor_int32_put, state_e, (void*)14, 0), NULL);
|
|
266
269
|
zassert_false(zcbor_multi_encode_minmax(1, 1, &(size_t){1}, (zcbor_encoder_t *)zcbor_int32_put, state_e, (void*)15, 0), NULL);
|
|
267
|
-
zassert_false(zcbor_present_encode(&(bool){true}, (zcbor_encoder_t *)zcbor_int32_put, state_e, (void*)16), NULL);
|
|
268
270
|
|
|
269
271
|
|
|
270
272
|
zassert_mem_equal(&state_backup, state_e, sizeof(state_backup), NULL);
|
|
@@ -287,8 +289,8 @@ ZTEST(zcbor_unit_tests, test_stop_on_error)
|
|
|
287
289
|
zassert_true(zcbor_size_encode(state_e, &(size_t){9}), NULL);
|
|
288
290
|
zassert_true(zcbor_bstr_put_lit(state_e, "Hello"), NULL);
|
|
289
291
|
zassert_true(zcbor_tstr_put_lit(state_e, "World"), NULL);
|
|
290
|
-
zassert_true(
|
|
291
|
-
zassert_true(zcbor_tag_encode(state_e, 10)
|
|
292
|
+
zassert_true(zcbor_tag_put(state_e, 9), NULL);
|
|
293
|
+
zassert_true(zcbor_tag_encode(state_e, &(uint32_t){10}));
|
|
292
294
|
zassert_true(zcbor_bool_put(state_e, true), NULL);
|
|
293
295
|
zassert_true(zcbor_bool_encode(state_e, &(bool){false}), NULL);
|
|
294
296
|
zassert_true(zcbor_float32_put(state_e, 10.5), NULL);
|
|
@@ -305,9 +307,8 @@ ZTEST(zcbor_unit_tests, test_stop_on_error)
|
|
|
305
307
|
zassert_true(zcbor_list_end_encode(state_e, 1), NULL);
|
|
306
308
|
zassert_true(zcbor_multi_encode(1, (zcbor_encoder_t *)zcbor_int32_put, state_e, (void*)14, 0), NULL);
|
|
307
309
|
zassert_true(zcbor_multi_encode_minmax(1, 1, &(size_t){1}, (zcbor_encoder_t *)zcbor_int32_put, state_e, (void*)15, 0), NULL);
|
|
308
|
-
zassert_true(zcbor_present_encode(&(bool){true}, (zcbor_encoder_t *)zcbor_int32_put, state_e, (void*)16), NULL);
|
|
309
310
|
|
|
310
|
-
ZCBOR_STATE_D(state_d, 3, payload, sizeof(payload), 30);
|
|
311
|
+
ZCBOR_STATE_D(state_d, 3, payload, sizeof(payload), 30, 0);
|
|
311
312
|
state_d->constant_state->stop_on_error = true;
|
|
312
313
|
|
|
313
314
|
zassert_false(zcbor_int32_expect(state_d, 2), NULL);
|
|
@@ -334,9 +335,7 @@ ZTEST(zcbor_unit_tests, test_stop_on_error)
|
|
|
334
335
|
zassert_false(zcbor_bool_decode(state_d, &(bool){false}), NULL);
|
|
335
336
|
zassert_false(zcbor_float32_expect(state_d, 10.5), NULL);
|
|
336
337
|
zassert_false(zcbor_float32_decode(state_d, &(float){11.6}), NULL);
|
|
337
|
-
#ifndef CONFIG_BOARD_QEMU_MALTA_BE
|
|
338
338
|
zassert_false(zcbor_float64_expect(state_d, 12.7), NULL);
|
|
339
|
-
#endif
|
|
340
339
|
zassert_false(zcbor_float64_decode(state_d, &(double){13.8}), NULL);
|
|
341
340
|
zassert_false(zcbor_nil_expect(state_d, NULL), NULL);
|
|
342
341
|
zassert_false(zcbor_undefined_expect(state_d, NULL), NULL);
|
|
@@ -347,8 +346,7 @@ ZTEST(zcbor_unit_tests, test_stop_on_error)
|
|
|
347
346
|
zassert_false(zcbor_map_end_decode(state_d), NULL);
|
|
348
347
|
zassert_false(zcbor_list_end_decode(state_d), NULL);
|
|
349
348
|
zassert_false(zcbor_multi_decode(1, 1, &(size_t){1}, (zcbor_decoder_t *)zcbor_int32_expect, state_d, (void*)14, 0), NULL);
|
|
350
|
-
zassert_false(zcbor_int32_expect
|
|
351
|
-
zassert_false(zcbor_present_decode(&(bool){true}, (zcbor_decoder_t *)zcbor_int32_expect, state_d, (void*)16), NULL);
|
|
349
|
+
zassert_false(zcbor_present_decode(&(bool){true}, (zcbor_decoder_t *)zcbor_int32_expect, state_d, (void*)15), NULL);
|
|
352
350
|
|
|
353
351
|
zassert_mem_equal(&state_backup, state_d, sizeof(state_backup), NULL);
|
|
354
352
|
zassert_mem_equal(&constant_state_backup, state_d->constant_state, sizeof(constant_state_backup), NULL);
|
|
@@ -374,11 +372,7 @@ ZTEST(zcbor_unit_tests, test_stop_on_error)
|
|
|
374
372
|
zassert_true(zcbor_bool_decode(state_d, &(bool){false}), NULL);
|
|
375
373
|
zassert_true(zcbor_float32_expect(state_d, 10.5), NULL);
|
|
376
374
|
zassert_true(zcbor_float32_decode(state_d, &(float){11.6}), NULL);
|
|
377
|
-
#ifdef CONFIG_BOARD_QEMU_MALTA_BE
|
|
378
|
-
zassert_true(zcbor_float64_decode(state_d, &(double){12.7}), NULL);
|
|
379
|
-
#else
|
|
380
375
|
zassert_true(zcbor_float64_expect(state_d, 12.7), NULL);
|
|
381
|
-
#endif
|
|
382
376
|
zassert_true(zcbor_float64_decode(state_d, &(double){13.8}), NULL);
|
|
383
377
|
zassert_true(zcbor_nil_expect(state_d, NULL), NULL);
|
|
384
378
|
zassert_true(zcbor_undefined_expect(state_d, NULL), NULL);
|
|
@@ -389,8 +383,7 @@ ZTEST(zcbor_unit_tests, test_stop_on_error)
|
|
|
389
383
|
zassert_true(zcbor_map_end_decode(state_d), NULL);
|
|
390
384
|
zassert_true(zcbor_list_end_decode(state_d), NULL);
|
|
391
385
|
zassert_true(zcbor_multi_decode(1, 1, &(size_t){1}, (zcbor_decoder_t *)zcbor_int32_expect, state_d, (void*)14, 0), NULL);
|
|
392
|
-
zassert_true(zcbor_int32_expect
|
|
393
|
-
zassert_true(zcbor_present_decode(&(bool){1}, (zcbor_decoder_t *)zcbor_int32_expect, state_d, (void*)16), NULL);
|
|
386
|
+
zassert_true(zcbor_present_decode(&(bool){1}, (zcbor_decoder_t *)zcbor_int32_expect, state_d, (void*)15), NULL);
|
|
394
387
|
|
|
395
388
|
/* Everything has been decoded. */
|
|
396
389
|
zassert_equal(state_e->payload, state_d->payload, NULL);
|
|
@@ -409,8 +402,8 @@ ZTEST(zcbor_unit_tests, test_fragments)
|
|
|
409
402
|
|
|
410
403
|
zassert_true(zcbor_bstr_put_lit(state_e, "HelloWorld"), NULL);
|
|
411
404
|
|
|
412
|
-
ZCBOR_STATE_D(state_d, 0, payload, 8, 1);
|
|
413
|
-
ZCBOR_STATE_D(state_d2, 0, payload, sizeof(payload), 1);
|
|
405
|
+
ZCBOR_STATE_D(state_d, 0, payload, 8, 1, 0);
|
|
406
|
+
ZCBOR_STATE_D(state_d2, 0, payload, sizeof(payload), 1, 0);
|
|
414
407
|
|
|
415
408
|
zassert_true(zcbor_bstr_decode(state_d2, &output), NULL);
|
|
416
409
|
zassert_false(zcbor_payload_at_end(state_d2), NULL);
|
|
@@ -469,8 +462,8 @@ ZTEST(zcbor_unit_tests, test_validate_fragments)
|
|
|
469
462
|
"HelloWorldDHelloWorldEHelloWorldFHelloWorldGHelloWorldHHelloWorldI"),
|
|
470
463
|
NULL);
|
|
471
464
|
|
|
472
|
-
ZCBOR_STATE_D(state_d, 0, payload, 13, 1);
|
|
473
|
-
ZCBOR_STATE_D(state_d2, 0, payload, sizeof(payload), 1);
|
|
465
|
+
ZCBOR_STATE_D(state_d, 0, payload, 13, 1, 0);
|
|
466
|
+
ZCBOR_STATE_D(state_d2, 0, payload, sizeof(payload), 1, 0);
|
|
474
467
|
|
|
475
468
|
zassert_true(zcbor_bstr_decode(state_d2, &output), NULL);
|
|
476
469
|
zassert_true(zcbor_bstr_decode_fragment(state_d, &output_frags[0]), NULL);
|
|
@@ -590,8 +583,8 @@ ZTEST(zcbor_unit_tests, test_bstr_cbor_fragments)
|
|
|
590
583
|
zassert_true(zcbor_list_end_encode(state_e, 2), NULL); // 1 B
|
|
591
584
|
zassert_true(zcbor_bstr_end_encode(state_e, NULL), NULL); // 0 B
|
|
592
585
|
|
|
593
|
-
ZCBOR_STATE_D(state_d, 2, payload, 8, 1);
|
|
594
|
-
ZCBOR_STATE_D(state_d2, 0, payload, sizeof(payload), 1);
|
|
586
|
+
ZCBOR_STATE_D(state_d, 2, payload, 8, 1, 0);
|
|
587
|
+
ZCBOR_STATE_D(state_d2, 0, payload, sizeof(payload), 1, 0);
|
|
595
588
|
|
|
596
589
|
#ifdef ZCBOR_CANONICAL
|
|
597
590
|
#define EXP_TOTAL_LEN 17
|
|
@@ -669,7 +662,7 @@ ZTEST(zcbor_unit_tests, test_bstr_cbor_fragments)
|
|
|
669
662
|
ZTEST(zcbor_unit_tests, test_canonical_list)
|
|
670
663
|
{
|
|
671
664
|
#ifndef ZCBOR_CANONICAL
|
|
672
|
-
|
|
665
|
+
printf("Skip on non-canonical builds.\n");
|
|
673
666
|
#else
|
|
674
667
|
uint8_t payload1[100];
|
|
675
668
|
uint8_t payload2[100];
|
|
@@ -699,7 +692,7 @@ ZTEST(zcbor_unit_tests, test_int)
|
|
|
699
692
|
{
|
|
700
693
|
uint8_t payload1[100];
|
|
701
694
|
ZCBOR_STATE_E(state_e, 1, payload1, sizeof(payload1), 0);
|
|
702
|
-
ZCBOR_STATE_D(state_d, 1, payload1, sizeof(payload1), 16);
|
|
695
|
+
ZCBOR_STATE_D(state_d, 1, payload1, sizeof(payload1), 16, 0);
|
|
703
696
|
|
|
704
697
|
/* Encode all numbers */
|
|
705
698
|
/* Arbitrary positive numbers in each size */
|
|
@@ -819,7 +812,7 @@ ZTEST(zcbor_unit_tests, test_uint)
|
|
|
819
812
|
{
|
|
820
813
|
uint8_t payload1[100];
|
|
821
814
|
ZCBOR_STATE_E(state_e, 1, payload1, sizeof(payload1), 0);
|
|
822
|
-
ZCBOR_STATE_D(state_d, 1, payload1, sizeof(payload1), 16);
|
|
815
|
+
ZCBOR_STATE_D(state_d, 1, payload1, sizeof(payload1), 16, 0);
|
|
823
816
|
|
|
824
817
|
/* Encode all numbers */
|
|
825
818
|
/* Arbitrary positive numbers in each size */
|
|
@@ -870,7 +863,7 @@ ZTEST(zcbor_unit_tests, test_encode_int_0)
|
|
|
870
863
|
uint32_t values_32[2] = {0, UINT32_MAX};
|
|
871
864
|
uint64_t values_64[2] = {0, UINT64_MAX};
|
|
872
865
|
ZCBOR_STATE_E(state_e, 1, payload1, sizeof(payload1), 0);
|
|
873
|
-
ZCBOR_STATE_D(state_d, 1, payload1, sizeof(payload1), 16);
|
|
866
|
+
ZCBOR_STATE_D(state_d, 1, payload1, sizeof(payload1), 16, 0);
|
|
874
867
|
|
|
875
868
|
zassert_true(zcbor_uint32_put(state_e, values_32[0]));
|
|
876
869
|
zassert_true(zcbor_uint64_put(state_e, values_64[0]));
|
|
@@ -883,7 +876,7 @@ ZTEST(zcbor_unit_tests, test_simple)
|
|
|
883
876
|
{
|
|
884
877
|
uint8_t payload1[100];
|
|
885
878
|
ZCBOR_STATE_E(state_e, 1, payload1, sizeof(payload1), 0);
|
|
886
|
-
ZCBOR_STATE_D(state_d, 1, payload1, sizeof(payload1), 16);
|
|
879
|
+
ZCBOR_STATE_D(state_d, 1, payload1, sizeof(payload1), 16, 0);
|
|
887
880
|
uint8_t simple1 = 0;
|
|
888
881
|
uint8_t simple2 = 2;
|
|
889
882
|
|
|
@@ -908,16 +901,26 @@ ZTEST(zcbor_unit_tests, test_simple)
|
|
|
908
901
|
ZTEST(zcbor_unit_tests, test_header_len)
|
|
909
902
|
{
|
|
910
903
|
zassert_equal(1, zcbor_header_len(0), NULL);
|
|
904
|
+
zassert_equal(1, zcbor_header_len_ptr((uint8_t*)&(uint8_t){0}, 1), NULL);
|
|
911
905
|
zassert_equal(1, zcbor_header_len(23), NULL);
|
|
906
|
+
zassert_equal(1, zcbor_header_len_ptr((uint8_t*)&(uint8_t){23}, 1), NULL);
|
|
912
907
|
zassert_equal(2, zcbor_header_len(24), NULL);
|
|
908
|
+
zassert_equal(2, zcbor_header_len_ptr((uint8_t*)&(uint8_t){24}, 1), NULL);
|
|
913
909
|
zassert_equal(2, zcbor_header_len(0xFF), NULL);
|
|
910
|
+
zassert_equal(2, zcbor_header_len_ptr((uint8_t*)&(uint8_t){0xFF}, 1), NULL);
|
|
914
911
|
zassert_equal(3, zcbor_header_len(0x100), NULL);
|
|
912
|
+
zassert_equal(3, zcbor_header_len_ptr((uint8_t*)&(uint16_t){0x100}, 2), NULL);
|
|
915
913
|
zassert_equal(3, zcbor_header_len(0xFFFF), NULL);
|
|
914
|
+
zassert_equal(3, zcbor_header_len_ptr((uint8_t*)&(uint16_t){0xFFFF}, 2), NULL);
|
|
916
915
|
zassert_equal(5, zcbor_header_len(0x10000), NULL);
|
|
916
|
+
zassert_equal(5, zcbor_header_len_ptr((uint8_t*)&(uint32_t){0x10000}, 4), NULL);
|
|
917
917
|
zassert_equal(5, zcbor_header_len(0xFFFFFFFF), NULL);
|
|
918
|
+
zassert_equal(5, zcbor_header_len_ptr((uint8_t*)&(uint32_t){0xFFFFFFFF}, 4), NULL);
|
|
918
919
|
#if SIZE_MAX >= 0x100000000ULL
|
|
919
920
|
zassert_equal(9, zcbor_header_len(0x100000000), NULL);
|
|
921
|
+
zassert_equal(9, zcbor_header_len_ptr((uint8_t*)&(uint64_t){0x100000000}, 8), NULL);
|
|
920
922
|
zassert_equal(9, zcbor_header_len(0xFFFFFFFFFFFFFFFF), NULL);
|
|
923
|
+
zassert_equal(9, zcbor_header_len_ptr((uint8_t*)&(uint64_t){0xFFFFFFFFFFFFFFFF}, 8), NULL);
|
|
921
924
|
#endif
|
|
922
925
|
}
|
|
923
926
|
|
|
@@ -975,29 +978,65 @@ ZTEST(zcbor_unit_tests, test_compare_strings)
|
|
|
975
978
|
}
|
|
976
979
|
|
|
977
980
|
|
|
981
|
+
ZTEST(zcbor_unit_tests, test_error_str)
|
|
982
|
+
{
|
|
983
|
+
#define test_str(err) zassert_mem_equal(zcbor_error_str(err), #err, sizeof(#err), NULL)
|
|
984
|
+
|
|
985
|
+
test_str(ZCBOR_SUCCESS);
|
|
986
|
+
test_str(ZCBOR_ERR_NO_BACKUP_MEM);
|
|
987
|
+
test_str(ZCBOR_ERR_NO_BACKUP_ACTIVE);
|
|
988
|
+
test_str(ZCBOR_ERR_LOW_ELEM_COUNT);
|
|
989
|
+
test_str(ZCBOR_ERR_HIGH_ELEM_COUNT);
|
|
990
|
+
test_str(ZCBOR_ERR_INT_SIZE);
|
|
991
|
+
test_str(ZCBOR_ERR_FLOAT_SIZE);
|
|
992
|
+
test_str(ZCBOR_ERR_ADDITIONAL_INVAL);
|
|
993
|
+
test_str(ZCBOR_ERR_NO_PAYLOAD);
|
|
994
|
+
test_str(ZCBOR_ERR_PAYLOAD_NOT_CONSUMED);
|
|
995
|
+
test_str(ZCBOR_ERR_WRONG_TYPE);
|
|
996
|
+
test_str(ZCBOR_ERR_WRONG_VALUE);
|
|
997
|
+
test_str(ZCBOR_ERR_WRONG_RANGE);
|
|
998
|
+
test_str(ZCBOR_ERR_ITERATIONS);
|
|
999
|
+
test_str(ZCBOR_ERR_ASSERTION);
|
|
1000
|
+
test_str(ZCBOR_ERR_PAYLOAD_OUTDATED);
|
|
1001
|
+
test_str(ZCBOR_ERR_ELEM_NOT_FOUND);
|
|
1002
|
+
test_str(ZCBOR_ERR_MAP_MISALIGNED);
|
|
1003
|
+
test_str(ZCBOR_ERR_ELEMS_NOT_PROCESSED);
|
|
1004
|
+
test_str(ZCBOR_ERR_NOT_AT_END);
|
|
1005
|
+
test_str(ZCBOR_ERR_MAP_FLAGS_NOT_AVAILABLE);
|
|
1006
|
+
test_str(ZCBOR_ERR_INVALID_VALUE_ENCODING);
|
|
1007
|
+
test_str(ZCBOR_ERR_UNKNOWN);
|
|
1008
|
+
zassert_mem_equal(zcbor_error_str(-1), "ZCBOR_ERR_UNKNOWN", sizeof("ZCBOR_ERR_UNKNOWN"), NULL);
|
|
1009
|
+
zassert_mem_equal(zcbor_error_str(-10), "ZCBOR_ERR_UNKNOWN", sizeof("ZCBOR_ERR_UNKNOWN"), NULL);
|
|
1010
|
+
zassert_mem_equal(zcbor_error_str(ZCBOR_ERR_INVALID_VALUE_ENCODING + 1), "ZCBOR_ERR_UNKNOWN", sizeof("ZCBOR_ERR_UNKNOWN"), NULL);
|
|
1011
|
+
zassert_mem_equal(zcbor_error_str(100000), "ZCBOR_ERR_UNKNOWN", sizeof("ZCBOR_ERR_UNKNOWN"), NULL);
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
|
|
978
1015
|
ZTEST(zcbor_unit_tests, test_any_skip)
|
|
979
1016
|
{
|
|
980
1017
|
uint8_t payload[200];
|
|
981
1018
|
ZCBOR_STATE_E(state_e, 1, payload, sizeof(payload), 0);
|
|
982
|
-
ZCBOR_STATE_D(state_d, 0, payload, sizeof(payload), 10);
|
|
1019
|
+
ZCBOR_STATE_D(state_d, 0, payload, sizeof(payload), 10, 0);
|
|
983
1020
|
size_t exp_elem_count = 10;
|
|
984
1021
|
|
|
985
1022
|
zassert_true(zcbor_uint32_put(state_e, 10), NULL);
|
|
986
|
-
|
|
1023
|
+
bool ret = zcbor_any_skip(state_d, NULL);
|
|
1024
|
+
zassert_true(ret, "err: %d\n", zcbor_peek_error(state_d));
|
|
987
1025
|
zassert_equal(state_d->payload, state_e->payload, NULL);
|
|
988
1026
|
zassert_equal(state_d->elem_count, --exp_elem_count, NULL);
|
|
989
1027
|
|
|
990
1028
|
zassert_true(zcbor_int64_put(state_e, -10000000000000), NULL);
|
|
991
|
-
|
|
1029
|
+
ret = zcbor_any_skip(state_d, NULL);
|
|
1030
|
+
zassert_true(ret, "err: %d\n", zcbor_peek_error(state_d));
|
|
992
1031
|
zassert_equal(state_d->payload, state_e->payload, NULL);
|
|
993
1032
|
zassert_equal(state_d->elem_count, --exp_elem_count, NULL);
|
|
994
1033
|
|
|
995
|
-
zassert_true(zcbor_bstr_put_term(state_e, "hello"), NULL);
|
|
1034
|
+
zassert_true(zcbor_bstr_put_term(state_e, "hello", 10), NULL);
|
|
996
1035
|
zassert_true(zcbor_any_skip(state_d, NULL));
|
|
997
1036
|
zassert_equal(state_d->payload, state_e->payload, NULL);
|
|
998
1037
|
zassert_equal(state_d->elem_count, --exp_elem_count, NULL);
|
|
999
1038
|
|
|
1000
|
-
zassert_true(zcbor_tstr_put_term(state_e, "world"), NULL);
|
|
1039
|
+
zassert_true(zcbor_tstr_put_term(state_e, "world", 5), NULL);
|
|
1001
1040
|
zassert_true(zcbor_any_skip(state_d, NULL));
|
|
1002
1041
|
zassert_equal(state_d->payload, state_e->payload, NULL);
|
|
1003
1042
|
zassert_equal(state_d->elem_count, --exp_elem_count, NULL);
|
|
@@ -1015,23 +1054,24 @@ ZTEST(zcbor_unit_tests, test_any_skip)
|
|
|
1015
1054
|
zassert_true(zcbor_list_start_encode(state_e, 6), NULL);
|
|
1016
1055
|
zassert_true(zcbor_uint32_put(state_e, 10), NULL);
|
|
1017
1056
|
zassert_true(zcbor_int64_put(state_e, -10000000000000), NULL);
|
|
1018
|
-
zassert_true(zcbor_bstr_put_term(state_e, "hello"), NULL);
|
|
1019
|
-
zassert_true(zcbor_tstr_put_term(state_e, "world"), NULL);
|
|
1057
|
+
zassert_true(zcbor_bstr_put_term(state_e, "hello", 10), NULL);
|
|
1058
|
+
zassert_true(zcbor_tstr_put_term(state_e, "world", 10), NULL);
|
|
1020
1059
|
zassert_true(zcbor_bool_put(state_e, true), NULL);
|
|
1021
1060
|
zassert_true(zcbor_float64_put(state_e, 3.14), NULL);
|
|
1022
1061
|
zassert_true(zcbor_list_end_encode(state_e, 6), NULL);
|
|
1023
|
-
|
|
1062
|
+
ret = zcbor_any_skip(state_d, NULL);
|
|
1063
|
+
zassert_true(ret, "err: %d\n", zcbor_peek_error(state_d));
|
|
1024
1064
|
zassert_equal(state_d->payload, state_e->payload, NULL);
|
|
1025
1065
|
zassert_equal(state_d->elem_count, --exp_elem_count, NULL);
|
|
1026
1066
|
|
|
1027
|
-
zassert_true(
|
|
1028
|
-
zassert_true(
|
|
1029
|
-
zassert_true(
|
|
1067
|
+
zassert_true(zcbor_tag_put(state_e, 1), NULL);
|
|
1068
|
+
zassert_true(zcbor_tag_put(state_e, 200), NULL);
|
|
1069
|
+
zassert_true(zcbor_tag_put(state_e, 3000), NULL);
|
|
1030
1070
|
zassert_true(zcbor_map_start_encode(state_e, 6), NULL);
|
|
1031
1071
|
zassert_true(zcbor_uint32_put(state_e, 10), NULL);
|
|
1032
1072
|
zassert_true(zcbor_int64_put(state_e, -10000000000000), NULL);
|
|
1033
|
-
zassert_true(zcbor_bstr_put_term(state_e, "hello"), NULL);
|
|
1034
|
-
zassert_true(zcbor_tstr_put_term(state_e, "world"), NULL);
|
|
1073
|
+
zassert_true(zcbor_bstr_put_term(state_e, "hello", 10), NULL);
|
|
1074
|
+
zassert_true(zcbor_tstr_put_term(state_e, "world", 10), NULL);
|
|
1035
1075
|
zassert_true(zcbor_undefined_put(state_e, NULL), NULL);
|
|
1036
1076
|
zassert_true(zcbor_float64_put(state_e, 3.14), NULL);
|
|
1037
1077
|
zassert_true(zcbor_map_end_encode(state_e, 6), NULL);
|
|
@@ -1041,4 +1081,357 @@ ZTEST(zcbor_unit_tests, test_any_skip)
|
|
|
1041
1081
|
zassert_equal(state_d->elem_count, --exp_elem_count, NULL);
|
|
1042
1082
|
}
|
|
1043
1083
|
|
|
1084
|
+
|
|
1085
|
+
ZTEST(zcbor_unit_tests, test_pexpect)
|
|
1086
|
+
{
|
|
1087
|
+
uint8_t payload[100];
|
|
1088
|
+
ZCBOR_STATE_E(state_e, 2, payload, sizeof(payload), 0);
|
|
1089
|
+
ZCBOR_STATE_D(state_d, 2, payload, sizeof(payload), 20, 0);
|
|
1090
|
+
|
|
1091
|
+
zassert_true(zcbor_int32_put(state_e, 1), NULL);
|
|
1092
|
+
zassert_true(zcbor_int32_put(state_e, 2), NULL);
|
|
1093
|
+
zassert_true(zcbor_int32_put(state_e, 3), NULL);
|
|
1094
|
+
zassert_true(zcbor_int32_put(state_e, 4), NULL);
|
|
1095
|
+
zassert_true(zcbor_int32_put(state_e, 5), NULL);
|
|
1096
|
+
zassert_true(zcbor_tag_put(state_e, 6), NULL);
|
|
1097
|
+
zassert_true(zcbor_simple_put(state_e, 7), NULL);
|
|
1098
|
+
zassert_true(zcbor_bool_put(state_e, true), NULL);
|
|
1099
|
+
zassert_true(zcbor_float16_bytes_put(state_e, 0x4800), NULL);
|
|
1100
|
+
zassert_true(zcbor_float16_bytes_put(state_e, 0x4880), NULL);
|
|
1101
|
+
zassert_true(zcbor_float32_put(state_e, 10.0), NULL);
|
|
1102
|
+
zassert_true(zcbor_float32_put(state_e, 11.0), NULL);
|
|
1103
|
+
zassert_true(zcbor_float32_put(state_e, 12.0), NULL);
|
|
1104
|
+
zassert_true(zcbor_float64_put(state_e, 13.0), NULL);
|
|
1105
|
+
zassert_true(zcbor_float64_put(state_e, 14.0), NULL);
|
|
1106
|
+
|
|
1107
|
+
zassert_true(zcbor_int32_pexpect(state_d, &(int32_t){1}), NULL);
|
|
1108
|
+
zassert_true(zcbor_int64_pexpect(state_d, &(int64_t){2}), NULL);
|
|
1109
|
+
zassert_true(zcbor_uint32_pexpect(state_d, &(uint32_t){3}), NULL);
|
|
1110
|
+
zassert_true(zcbor_uint64_pexpect(state_d, &(uint64_t){4}), NULL);
|
|
1111
|
+
zassert_true(zcbor_size_pexpect(state_d, &(size_t){5}), NULL);
|
|
1112
|
+
zassert_true(zcbor_tag_pexpect(state_d, &(uint32_t){6}), NULL);
|
|
1113
|
+
zassert_true(zcbor_simple_pexpect(state_d, &(uint8_t){7}), NULL);
|
|
1114
|
+
zassert_true(zcbor_bool_pexpect(state_d, &(bool){true}), NULL);
|
|
1115
|
+
zassert_true(zcbor_float16_pexpect(state_d, &(float){8.0}), NULL);
|
|
1116
|
+
zassert_true(zcbor_float16_bytes_pexpect(state_d, &(uint16_t){0x4880}), NULL);
|
|
1117
|
+
zassert_true(zcbor_float16_32_pexpect(state_d, &(float){10.0}), NULL);
|
|
1118
|
+
zassert_true(zcbor_float32_pexpect(state_d, &(float){11.0}), NULL);
|
|
1119
|
+
zassert_true(zcbor_float32_64_pexpect(state_d, &(double){12.0}), NULL);
|
|
1120
|
+
zassert_true(zcbor_float64_pexpect(state_d, &(double){13.0}), NULL);
|
|
1121
|
+
zassert_true(zcbor_float_pexpect(state_d, &(double){14.0}), NULL);
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
|
|
1125
|
+
void decode_inner_map(zcbor_state_t *state, void *result)
|
|
1126
|
+
{
|
|
1127
|
+
zassert_true(zcbor_unordered_map_start_decode(state), NULL);
|
|
1128
|
+
zassert_true(zcbor_unordered_map_search((zcbor_decoder_t *)zcbor_bool_pexpect, state, &(bool){false}), NULL);
|
|
1129
|
+
zassert_true(zcbor_undefined_expect(state, NULL), NULL);
|
|
1130
|
+
zcbor_elem_processed(state);
|
|
1131
|
+
zassert_true(zcbor_unordered_map_search((zcbor_decoder_t *)zcbor_tstr_expect, state, &(struct zcbor_string){"hello", 5}), NULL);
|
|
1132
|
+
zassert_true(zcbor_tstr_expect(state, &(struct zcbor_string){"world", 5}), NULL);
|
|
1133
|
+
zcbor_elem_processed(state);
|
|
1134
|
+
bool ret = zcbor_unordered_map_end_decode(state);
|
|
1135
|
+
zassert_true(ret, "err: %d\n", zcbor_peek_error(state));
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
|
|
1139
|
+
ZTEST(zcbor_unit_tests, test_unordered_map)
|
|
1140
|
+
{
|
|
1141
|
+
uint8_t payload[200];
|
|
1142
|
+
ZCBOR_STATE_E(state_e, 2, payload, sizeof(payload), 0);
|
|
1143
|
+
ZCBOR_STATE_D(state_d, 2, payload, sizeof(payload), 10, 40);
|
|
1144
|
+
struct zcbor_string str_result1;
|
|
1145
|
+
struct zcbor_string str_result2;
|
|
1146
|
+
struct zcbor_string str_result3;
|
|
1147
|
+
int32_t int_result1;
|
|
1148
|
+
uint8_t const *start2, *start3, *start4;
|
|
1149
|
+
bool ret;
|
|
1150
|
+
|
|
1151
|
+
zassert_true(zcbor_map_start_encode(state_e, 0), NULL);
|
|
1152
|
+
zassert_true(zcbor_map_end_encode(state_e, 0), NULL);
|
|
1153
|
+
start2 = state_e->payload;
|
|
1154
|
+
|
|
1155
|
+
zassert_true(zcbor_map_start_encode(state_e, 0), NULL);
|
|
1156
|
+
zassert_true(zcbor_uint32_put(state_e, 1), NULL);
|
|
1157
|
+
zassert_true(zcbor_uint32_put(state_e, 1), NULL);
|
|
1158
|
+
zassert_true(zcbor_map_end_encode(state_e, 0), NULL);
|
|
1159
|
+
start3 = state_e->payload;
|
|
1160
|
+
|
|
1161
|
+
zassert_true(zcbor_map_start_encode(state_e, 0), NULL);
|
|
1162
|
+
zassert_true(zcbor_uint32_put(state_e, 1), NULL);
|
|
1163
|
+
zassert_true(zcbor_uint32_put(state_e, 1), NULL);
|
|
1164
|
+
zassert_true(zcbor_uint32_put(state_e, 2), NULL);
|
|
1165
|
+
zassert_true(zcbor_uint32_put(state_e, 2), NULL);
|
|
1166
|
+
zassert_true(zcbor_map_end_encode(state_e, 0), NULL);
|
|
1167
|
+
start4 = state_e->payload;
|
|
1168
|
+
|
|
1169
|
+
ZCBOR_STATE_D(state_d2, 2, start3, start4 - start3, 10, 2);
|
|
1170
|
+
ZCBOR_STATE_D(state_d3, 2, start3, start4 - start3, 10, 0); // No flags
|
|
1171
|
+
|
|
1172
|
+
zassert_true(zcbor_map_start_encode(state_e, 43), NULL);
|
|
1173
|
+
zassert_true(zcbor_uint32_put(state_e, 1), NULL);
|
|
1174
|
+
zassert_true(zcbor_tstr_put_lit(state_e, "hello"), NULL);
|
|
1175
|
+
zassert_true(zcbor_int32_put(state_e, -1), NULL);
|
|
1176
|
+
zassert_true(zcbor_tstr_put_lit(state_e, "world"), NULL);
|
|
1177
|
+
zassert_true(zcbor_bool_put(state_e, true), NULL);
|
|
1178
|
+
zassert_true(zcbor_tstr_put_lit(state_e, "foo"), NULL);
|
|
1179
|
+
|
|
1180
|
+
/* Nested map */
|
|
1181
|
+
zassert_true(zcbor_tstr_put_lit(state_e, "bar"), NULL);
|
|
1182
|
+
zassert_true(zcbor_map_start_encode(state_e, 0), NULL);
|
|
1183
|
+
zassert_true(zcbor_tstr_put_lit(state_e, "hello"), NULL);
|
|
1184
|
+
zassert_true(zcbor_tstr_put_lit(state_e, "world"), NULL);
|
|
1185
|
+
zassert_true(zcbor_bool_put(state_e, false), NULL);
|
|
1186
|
+
zassert_true(zcbor_undefined_put(state_e, NULL), NULL);
|
|
1187
|
+
zassert_true(zcbor_map_end_encode(state_e, 0), NULL);
|
|
1188
|
+
/* Nested map end */
|
|
1189
|
+
|
|
1190
|
+
for (int i = 2; i < 35; i++) {
|
|
1191
|
+
zassert_true(zcbor_uint32_put(state_e, i), NULL);
|
|
1192
|
+
zassert_true(zcbor_int32_put(state_e, -i), NULL);
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
zassert_true(zcbor_tstr_put_lit(state_e, "baz1"), NULL);
|
|
1196
|
+
zassert_true(zcbor_nil_put(state_e, NULL), NULL);
|
|
1197
|
+
zassert_true(zcbor_tstr_put_lit(state_e, "baz2"), NULL);
|
|
1198
|
+
zassert_true(zcbor_nil_put(state_e, NULL), NULL);
|
|
1199
|
+
zassert_true(zcbor_bstr_put_term(state_e, "baz3", 4), NULL);
|
|
1200
|
+
zassert_true(zcbor_nil_put(state_e, NULL), NULL);
|
|
1201
|
+
zassert_true(zcbor_bstr_put_term(state_e, "baz4", 4), NULL);
|
|
1202
|
+
zassert_true(zcbor_nil_put(state_e, NULL), NULL);
|
|
1203
|
+
zassert_true(zcbor_bstr_put_term(state_e, "baz5", 4), NULL);
|
|
1204
|
+
zassert_true(zcbor_nil_put(state_e, NULL), NULL);
|
|
1205
|
+
zassert_true(zcbor_map_end_encode(state_e, 43), NULL);
|
|
1206
|
+
|
|
1207
|
+
|
|
1208
|
+
/* Test empty map */
|
|
1209
|
+
zassert_true(zcbor_unordered_map_start_decode(state_d), NULL);
|
|
1210
|
+
zassert_false(zcbor_unordered_map_search((zcbor_decoder_t *)zcbor_int32_pexpect, state_d, &(int32_t){2}), NULL);
|
|
1211
|
+
zassert_equal(ZCBOR_ERR_ELEM_NOT_FOUND, zcbor_peek_error(state_d), "err: %d\n", zcbor_peek_error(state_d));
|
|
1212
|
+
ret = zcbor_unordered_map_end_decode(state_d);
|
|
1213
|
+
zassert_true(ret, "err: %d\n", zcbor_peek_error(state_d));
|
|
1214
|
+
zassert_equal(start2, state_d->payload, NULL);
|
|
1215
|
+
|
|
1216
|
+
/* Test single entry map */
|
|
1217
|
+
zassert_true(zcbor_unordered_map_start_decode(state_d), NULL);
|
|
1218
|
+
ret = zcbor_unordered_map_search((zcbor_decoder_t *)zcbor_int32_pexpect, state_d, &(int32_t){1});
|
|
1219
|
+
zassert_true(ret, "err: %d\n", zcbor_peek_error);
|
|
1220
|
+
zassert_true(zcbor_int32_expect(state_d, 1), NULL);
|
|
1221
|
+
ret = zcbor_unordered_map_end_decode(state_d);
|
|
1222
|
+
zassert_true(ret, "err: %d\n", zcbor_peek_error(state_d));
|
|
1223
|
+
zassert_equal(start3, state_d->payload, NULL);
|
|
1224
|
+
|
|
1225
|
+
/* Test that looping stops both if it starts at the very start and very end of the map.
|
|
1226
|
+
* Also test ZCBOR_ERR_MAP_MISALIGNED. */
|
|
1227
|
+
zassert_true(zcbor_unordered_map_start_decode(state_d2), NULL);
|
|
1228
|
+
zassert_false(zcbor_unordered_map_search((zcbor_decoder_t *)zcbor_int32_pexpect, state_d2, &(int32_t){3}), NULL);
|
|
1229
|
+
ret = zcbor_unordered_map_search((zcbor_decoder_t *)zcbor_int32_pexpect, state_d2, &(int32_t){2});
|
|
1230
|
+
zassert_true(ret, "err: %d\n", zcbor_peek_error(state_d2));
|
|
1231
|
+
zassert_false(zcbor_unordered_map_search((zcbor_decoder_t *)zcbor_int32_pexpect, state_d2, &(int32_t){1}), NULL);
|
|
1232
|
+
zassert_equal(zcbor_peek_error(state_d2), ZCBOR_ERR_MAP_MISALIGNED, NULL);
|
|
1233
|
+
zassert_true(zcbor_int32_expect(state_d2, 2), NULL);
|
|
1234
|
+
zassert_true(zcbor_array_at_end(state_d2), NULL);
|
|
1235
|
+
zassert_false(zcbor_unordered_map_search((zcbor_decoder_t *)zcbor_int32_pexpect, state_d2, &(int32_t){3}), NULL);
|
|
1236
|
+
zassert_true(zcbor_unordered_map_search((zcbor_decoder_t *)zcbor_int32_pexpect, state_d2, &(int32_t){1}), NULL);
|
|
1237
|
+
zassert_true(zcbor_int32_expect(state_d2, 1), NULL);
|
|
1238
|
+
ret = zcbor_unordered_map_end_decode(state_d2);
|
|
1239
|
+
zassert_true(ret, NULL);
|
|
1240
|
+
|
|
1241
|
+
/* Test that state_d3 fails because of missing flags. */
|
|
1242
|
+
#ifdef ZCBOR_MAP_SMART_SEARCH
|
|
1243
|
+
#ifdef ZCBOR_CANONICAL
|
|
1244
|
+
zassert_false(zcbor_unordered_map_start_decode(state_d3), NULL);
|
|
1245
|
+
#else
|
|
1246
|
+
zassert_true(zcbor_unordered_map_start_decode(state_d3), NULL);
|
|
1247
|
+
zassert_false(zcbor_unordered_map_search((zcbor_decoder_t *)zcbor_int32_pexpect, state_d3, &(int32_t){2}), NULL);
|
|
1248
|
+
#endif
|
|
1249
|
+
zassert_equal(zcbor_peek_error(state_d3), ZCBOR_ERR_MAP_FLAGS_NOT_AVAILABLE, NULL);
|
|
1250
|
+
#endif
|
|
1251
|
+
|
|
1252
|
+
/* Test premature map end */
|
|
1253
|
+
zassert_true(zcbor_unordered_map_start_decode(state_d), NULL);
|
|
1254
|
+
ret = zcbor_unordered_map_end_decode(state_d);
|
|
1255
|
+
zassert_false(ret, NULL);
|
|
1256
|
+
zassert_equal(ZCBOR_ERR_ELEMS_NOT_PROCESSED, zcbor_peek_error(state_d), NULL);
|
|
1257
|
+
#ifndef ZCBOR_CANONICAL
|
|
1258
|
+
zcbor_elem_processed(state_d); // Should do nothing because no elements have been discovered.
|
|
1259
|
+
#endif
|
|
1260
|
+
zassert_true(zcbor_unordered_map_search((zcbor_decoder_t *)zcbor_int32_pexpect, state_d, &(int32_t){1}), NULL);
|
|
1261
|
+
zassert_true(zcbor_int32_expect(state_d, 1), NULL);
|
|
1262
|
+
ret = zcbor_unordered_map_end_decode(state_d);
|
|
1263
|
+
zassert_false(ret, NULL);
|
|
1264
|
+
zassert_equal(ZCBOR_ERR_ELEMS_NOT_PROCESSED, zcbor_peek_error(state_d), NULL);
|
|
1265
|
+
/* Cause a restart of the map */
|
|
1266
|
+
zassert_false(zcbor_unordered_map_search((zcbor_decoder_t *)zcbor_int32_pexpect, state_d, &(int32_t){3}), NULL);
|
|
1267
|
+
ret = zcbor_unordered_map_end_decode(state_d);
|
|
1268
|
+
zassert_false(ret, NULL);
|
|
1269
|
+
zassert_equal(ZCBOR_ERR_ELEMS_NOT_PROCESSED, zcbor_peek_error(state_d), NULL);
|
|
1270
|
+
zassert_true(zcbor_unordered_map_search((zcbor_decoder_t *)zcbor_int32_pexpect, state_d, &(int32_t){2}), NULL);
|
|
1271
|
+
zassert_true(zcbor_int32_expect(state_d, 2), NULL);
|
|
1272
|
+
ret = zcbor_unordered_map_end_decode(state_d);
|
|
1273
|
+
zassert_true(ret, "err: %d\n", zcbor_peek_error(state_d));
|
|
1274
|
+
zassert_equal(start4, state_d->payload, NULL);
|
|
1275
|
+
|
|
1276
|
+
/* Test a large map, including nesting. */
|
|
1277
|
+
state_d->constant_state->manually_process_elem = true;
|
|
1278
|
+
zassert_true(zcbor_unordered_map_start_decode(state_d), NULL);
|
|
1279
|
+
ret = zcbor_unordered_map_search((zcbor_decoder_t *)zcbor_int32_pexpect, state_d, &(int32_t){-1});
|
|
1280
|
+
zassert_true(ret, "err: %d\n", zcbor_peek_error(state_d));
|
|
1281
|
+
zassert_true(zcbor_tstr_decode(state_d, &str_result1), NULL);
|
|
1282
|
+
zcbor_elem_processed(state_d);
|
|
1283
|
+
|
|
1284
|
+
zassert_true(zcbor_unordered_map_search((zcbor_decoder_t *)zcbor_bool_pexpect, state_d, &(bool){true}), NULL);
|
|
1285
|
+
zassert_true(zcbor_tstr_decode(state_d, &str_result2), NULL);
|
|
1286
|
+
zcbor_elem_processed(state_d);
|
|
1287
|
+
zassert_true(zcbor_unordered_map_search((zcbor_decoder_t *)zcbor_int32_pexpect, state_d, &(int32_t){2}), NULL);
|
|
1288
|
+
zassert_true(zcbor_int32_decode(state_d, &int_result1), NULL);
|
|
1289
|
+
zcbor_elem_processed(state_d);
|
|
1290
|
+
zassert_true(zcbor_unordered_map_search((zcbor_decoder_t *)zcbor_int32_pexpect, state_d, &(int32_t){1}), NULL);
|
|
1291
|
+
zassert_true(zcbor_tstr_decode(state_d, &str_result3), NULL);
|
|
1292
|
+
zcbor_elem_processed(state_d);
|
|
1293
|
+
|
|
1294
|
+
char baz4[] = {'b', 'a', 'z', '4'};
|
|
1295
|
+
char baz3[] = "baz3";
|
|
1296
|
+
char baz2[] = {'b', 'a', 'z', '2'};
|
|
1297
|
+
char baz1[] = "baz1";
|
|
1298
|
+
ret = zcbor_search_key_bstr_lit(state_d, "baz5");
|
|
1299
|
+
zassert_true(ret, "err: %d\n", zcbor_peek_error(state_d));
|
|
1300
|
+
zassert_true(zcbor_nil_expect(state_d, NULL), NULL);
|
|
1301
|
+
zcbor_elem_processed(state_d);
|
|
1302
|
+
zassert_true(zcbor_search_key_bstr_arr(state_d, baz4), NULL);
|
|
1303
|
+
zassert_true(zcbor_nil_expect(state_d, NULL), NULL);
|
|
1304
|
+
zcbor_elem_processed(state_d);
|
|
1305
|
+
zassert_true(zcbor_search_key_bstr_term(state_d, baz3, 6), NULL);
|
|
1306
|
+
zassert_true(zcbor_nil_expect(state_d, NULL), NULL);
|
|
1307
|
+
zcbor_elem_processed(state_d);
|
|
1308
|
+
zassert_true(zcbor_search_key_tstr_arr(state_d, baz2), NULL);
|
|
1309
|
+
zassert_true(zcbor_nil_expect(state_d, NULL), NULL);
|
|
1310
|
+
zcbor_elem_processed(state_d);
|
|
1311
|
+
zassert_true(zcbor_search_key_tstr_term(state_d, baz1, 6), NULL);
|
|
1312
|
+
zassert_true(zcbor_nil_expect(state_d, NULL), NULL);
|
|
1313
|
+
// Don't call zcbor_elem_processed() To check that we can find the element again.
|
|
1314
|
+
zassert_true(zcbor_search_key_tstr_term(state_d, baz1, 6), NULL);
|
|
1315
|
+
zassert_true(zcbor_nil_expect(state_d, NULL), NULL);
|
|
1316
|
+
zcbor_elem_processed(state_d);
|
|
1317
|
+
// Check whether we can find the element again when it has been marked as processed.
|
|
1318
|
+
#ifdef ZCBOR_MAP_SMART_SEARCH
|
|
1319
|
+
zassert_false(zcbor_search_key_tstr_term(state_d, baz1, 6), NULL);
|
|
1320
|
+
#else
|
|
1321
|
+
zassert_true(zcbor_search_key_tstr_term(state_d, baz1, 6), NULL);
|
|
1322
|
+
zassert_true(zcbor_nil_expect(state_d, NULL), NULL);
|
|
1323
|
+
#endif
|
|
1324
|
+
|
|
1325
|
+
zassert_true(zcbor_search_key_tstr_lit(state_d, "bar"), NULL);
|
|
1326
|
+
decode_inner_map(state_d, NULL);
|
|
1327
|
+
zcbor_elem_processed(state_d);
|
|
1328
|
+
|
|
1329
|
+
for (size_t i = 34; i > 2; i--) {
|
|
1330
|
+
zassert_true(zcbor_unordered_map_search((zcbor_decoder_t *)zcbor_int32_pexpect, state_d, &i), "i: %d, err: %d\n", i, zcbor_peek_error(state_d));
|
|
1331
|
+
zassert_false(zcbor_int32_expect(state_d, i), NULL);
|
|
1332
|
+
zassert_true(zcbor_int32_expect(state_d, -1 * i), NULL);
|
|
1333
|
+
zcbor_elem_processed(state_d);
|
|
1334
|
+
}
|
|
1335
|
+
ret = zcbor_unordered_map_end_decode(state_d);
|
|
1336
|
+
zassert_true(ret, "err: %d\n", zcbor_peek_error(state_d));
|
|
1337
|
+
|
|
1338
|
+
zassert_equal(int_result1, -2, NULL);
|
|
1339
|
+
zassert_true(zcbor_compare_strings(&str_result1, &(struct zcbor_string){"world", 5}), "%s (len: %d)\n", &str_result1.value, str_result1.len);
|
|
1340
|
+
zassert_true(zcbor_compare_strings(&str_result2, &(struct zcbor_string){"foo", 3}), NULL);
|
|
1341
|
+
zassert_true(zcbor_compare_strings(&str_result3, &(struct zcbor_string){"hello", 5}), NULL);
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
|
|
1345
|
+
ZTEST(zcbor_unit_tests, test_canonical_check)
|
|
1346
|
+
{
|
|
1347
|
+
uint8_t payload[] = {
|
|
1348
|
+
0xBF, /* Invalid map start */
|
|
1349
|
+
0x9F, /* Invalid list start */
|
|
1350
|
+
0x78, 0x00, /* invalid 0 */
|
|
1351
|
+
0x78, 0x17, /* invalid 23 */
|
|
1352
|
+
0x59, 0x00, 0x18, /* invalid 24 */
|
|
1353
|
+
0x59, 0x00, 0xFF, /* invalid 255 */
|
|
1354
|
+
0x3A, 0x00, 0x00, 0x01, 0x00, /* invalid 256 */
|
|
1355
|
+
0x3A, 0x00, 0x00, 0xFF, 0xFF, /* invalid 65535 */
|
|
1356
|
+
0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, /* invalid 65536 */
|
|
1357
|
+
0x1B, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, /* invalid 4294967295 */
|
|
1358
|
+
0xFF, 0xFF,
|
|
1359
|
+
};
|
|
1360
|
+
ZCBOR_STATE_D(state_d, 2, payload, sizeof(payload), 20, 0);
|
|
1361
|
+
uint64_t u64_result;
|
|
1362
|
+
int64_t i64_result;
|
|
1363
|
+
struct zcbor_string str_result;
|
|
1364
|
+
|
|
1365
|
+
#ifdef ZCBOR_CANONICAL
|
|
1366
|
+
#define CHECK_ERROR1(state) zassert_equal(ZCBOR_ERR_ADDITIONAL_INVAL, zcbor_pop_error(state), "err: %s\n", zcbor_error_str(zcbor_peek_error(state)))
|
|
1367
|
+
#define CHECK_ERROR2(state) zassert_equal(ZCBOR_ERR_INVALID_VALUE_ENCODING, zcbor_pop_error(state), "err: %s\n", zcbor_error_str(zcbor_peek_error(state)))
|
|
1368
|
+
|
|
1369
|
+
zassert_false(zcbor_map_start_decode(state_d), NULL);
|
|
1370
|
+
CHECK_ERROR1(state_d);
|
|
1371
|
+
state_d->payload += 1;
|
|
1372
|
+
zassert_false(zcbor_list_start_decode(state_d), NULL);
|
|
1373
|
+
CHECK_ERROR1(state_d);
|
|
1374
|
+
state_d->payload += 1;
|
|
1375
|
+
zassert_false(zcbor_tstr_decode(state_d, &str_result), NULL);
|
|
1376
|
+
CHECK_ERROR2(state_d);
|
|
1377
|
+
state_d->payload += 2;
|
|
1378
|
+
zassert_false(zcbor_tstr_decode(state_d, &str_result), NULL);
|
|
1379
|
+
CHECK_ERROR2(state_d);
|
|
1380
|
+
state_d->payload += 2;
|
|
1381
|
+
zassert_false(zcbor_bstr_decode(state_d, &str_result), NULL);
|
|
1382
|
+
CHECK_ERROR2(state_d);
|
|
1383
|
+
state_d->payload += 3;
|
|
1384
|
+
zassert_false(zcbor_bstr_decode(state_d, &str_result), NULL);
|
|
1385
|
+
CHECK_ERROR2(state_d);
|
|
1386
|
+
state_d->payload += 3;
|
|
1387
|
+
zassert_false(zcbor_int64_decode(state_d, &i64_result), NULL);
|
|
1388
|
+
CHECK_ERROR2(state_d);
|
|
1389
|
+
state_d->payload += 5;
|
|
1390
|
+
zassert_false(zcbor_int64_decode(state_d, &i64_result), NULL);
|
|
1391
|
+
CHECK_ERROR2(state_d);
|
|
1392
|
+
state_d->payload += 5;
|
|
1393
|
+
zassert_false(zcbor_uint64_decode(state_d, &u64_result), NULL);
|
|
1394
|
+
CHECK_ERROR2(state_d);
|
|
1395
|
+
state_d->payload += 9;
|
|
1396
|
+
zassert_false(zcbor_uint64_decode(state_d, &u64_result), NULL);
|
|
1397
|
+
CHECK_ERROR2(state_d);
|
|
1398
|
+
state_d->payload += 9;
|
|
1399
|
+
|
|
1400
|
+
#else
|
|
1401
|
+
#define CHECK_ERROR1(state) zassert_equal(ZCBOR_ERR_NO_PAYLOAD, zcbor_pop_error(state), "err: %s\n", zcbor_error_str(zcbor_peek_error(state)))
|
|
1402
|
+
|
|
1403
|
+
zassert_true(zcbor_map_start_decode(state_d), NULL);
|
|
1404
|
+
zassert_true(zcbor_list_start_decode(state_d), NULL);
|
|
1405
|
+
zassert_true(zcbor_tstr_decode(state_d, &str_result), NULL);
|
|
1406
|
+
zassert_true(zcbor_tstr_decode(state_d, &str_result), NULL);
|
|
1407
|
+
state_d->payload = state_d->payload_bak + 2; /* Reset since test vector doesn't contain the string value, just the header. */
|
|
1408
|
+
zassert_true(zcbor_bstr_decode(state_d, &str_result), NULL);
|
|
1409
|
+
state_d->payload = state_d->payload_bak + 3; /* Reset since test vector doesn't contain the string value, just the header. */
|
|
1410
|
+
zassert_false(zcbor_bstr_decode(state_d, &str_result), NULL); /* Fails because payload isn't big enough. */
|
|
1411
|
+
CHECK_ERROR1(state_d);
|
|
1412
|
+
state_d->payload += 3;
|
|
1413
|
+
zassert_true(zcbor_int64_decode(state_d, &i64_result), NULL);
|
|
1414
|
+
zassert_true(zcbor_int64_decode(state_d, &i64_result), NULL);
|
|
1415
|
+
zassert_true(zcbor_uint64_decode(state_d, &u64_result), NULL);
|
|
1416
|
+
zassert_true(zcbor_uint64_decode(state_d, &u64_result), NULL);
|
|
1417
|
+
zassert_true(zcbor_list_end_decode(state_d), NULL);
|
|
1418
|
+
zassert_true(zcbor_map_end_decode(state_d), NULL);
|
|
1419
|
+
#endif
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
|
|
1423
|
+
ZTEST(zcbor_unit_tests, test_zcbor_version)
|
|
1424
|
+
{
|
|
1425
|
+
const char zcbor_version_str[] = ZCBOR_VERSION_STR;
|
|
1426
|
+
const char zcbor_version_expected[] = TEST_ZCBOR_VERSION_STR;
|
|
1427
|
+
|
|
1428
|
+
|
|
1429
|
+
zassert_mem_equal(zcbor_version_expected, zcbor_version_str, sizeof(zcbor_version_expected));
|
|
1430
|
+
zassert_equal(TEST_ZCBOR_VERSION, ZCBOR_VERSION, NULL);
|
|
1431
|
+
zassert_equal(TEST_ZCBOR_VERSION_MAJOR, ZCBOR_VERSION_MAJOR, NULL);
|
|
1432
|
+
zassert_equal(TEST_ZCBOR_VERSION_MINOR, ZCBOR_VERSION_MINOR, NULL);
|
|
1433
|
+
zassert_equal(TEST_ZCBOR_VERSION_BUGFIX, ZCBOR_VERSION_BUGFIX, NULL);
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
|
|
1044
1437
|
ZTEST_SUITE(zcbor_unit_tests, NULL, NULL, NULL, NULL, NULL);
|