edhoc 1.0.5 → 1.1.0

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.
Files changed (313) hide show
  1. package/README.md +170 -0
  2. package/binding.gyp +13 -11
  3. package/dist/crypto.d.ts +9 -2
  4. package/dist/crypto.d.ts.map +1 -1
  5. package/dist/crypto.js +112 -84
  6. package/dist/edhoc.d.ts +31 -9
  7. package/dist/edhoc.d.ts.map +1 -1
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +1 -1
  11. package/dist/x509credentials.d.ts +20 -0
  12. package/dist/x509credentials.d.ts.map +1 -0
  13. package/dist/x509credentials.js +140 -0
  14. package/external/libedhoc/backends/cbor/include/backend_cbor_bstr_type_decode.h +1 -1
  15. package/external/libedhoc/backends/cbor/include/backend_cbor_bstr_type_encode.h +1 -1
  16. package/external/libedhoc/backends/cbor/include/backend_cbor_bstr_type_types.h +1 -1
  17. package/external/libedhoc/backends/cbor/include/backend_cbor_ead_decode.h +2 -2
  18. package/external/libedhoc/backends/cbor/include/backend_cbor_ead_encode.h +2 -2
  19. package/external/libedhoc/backends/cbor/include/backend_cbor_edhoc_types.h +48 -43
  20. package/external/libedhoc/backends/cbor/include/backend_cbor_enc_structure_decode.h +1 -1
  21. package/external/libedhoc/backends/cbor/include/backend_cbor_enc_structure_encode.h +1 -1
  22. package/external/libedhoc/backends/cbor/include/backend_cbor_enc_structure_types.h +3 -3
  23. package/external/libedhoc/backends/cbor/include/backend_cbor_id_cred_x_decode.h +1 -1
  24. package/external/libedhoc/backends/cbor/include/backend_cbor_id_cred_x_encode.h +1 -1
  25. package/external/libedhoc/backends/cbor/include/backend_cbor_info_decode.h +1 -1
  26. package/external/libedhoc/backends/cbor/include/backend_cbor_info_encode.h +1 -1
  27. package/external/libedhoc/backends/cbor/include/backend_cbor_int_type_decode.h +1 -1
  28. package/external/libedhoc/backends/cbor/include/backend_cbor_int_type_encode.h +1 -1
  29. package/external/libedhoc/backends/cbor/include/backend_cbor_int_type_types.h +1 -1
  30. package/external/libedhoc/backends/cbor/include/backend_cbor_message_1_decode.h +1 -1
  31. package/external/libedhoc/backends/cbor/include/backend_cbor_message_1_encode.h +1 -1
  32. package/external/libedhoc/backends/cbor/include/backend_cbor_message_2_decode.h +1 -1
  33. package/external/libedhoc/backends/cbor/include/backend_cbor_message_2_encode.h +1 -1
  34. package/external/libedhoc/backends/cbor/include/backend_cbor_message_3_decode.h +1 -1
  35. package/external/libedhoc/backends/cbor/include/backend_cbor_message_3_encode.h +1 -1
  36. package/external/libedhoc/backends/cbor/include/backend_cbor_message_4_decode.h +1 -1
  37. package/external/libedhoc/backends/cbor/include/backend_cbor_message_4_encode.h +1 -1
  38. package/external/libedhoc/backends/cbor/include/backend_cbor_message_error_decode.h +1 -1
  39. package/external/libedhoc/backends/cbor/include/backend_cbor_message_error_encode.h +1 -1
  40. package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_2_decode.h +1 -1
  41. package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_2_encode.h +1 -1
  42. package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_3_decode.h +1 -1
  43. package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_3_encode.h +1 -1
  44. package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_4_decode.h +3 -3
  45. package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_4_encode.h +3 -3
  46. package/external/libedhoc/backends/cbor/include/backend_cbor_sig_structure_decode.h +1 -1
  47. package/external/libedhoc/backends/cbor/include/backend_cbor_sig_structure_encode.h +1 -1
  48. package/external/libedhoc/backends/cbor/include/backend_cbor_sig_structure_types.h +4 -4
  49. package/external/libedhoc/backends/cbor/include/backend_cbor_x509_types.h +93 -83
  50. package/external/libedhoc/backends/cbor/src/backend_cbor_bstr_type_decode.c +11 -20
  51. package/external/libedhoc/backends/cbor/src/backend_cbor_bstr_type_encode.c +11 -20
  52. package/external/libedhoc/backends/cbor/src/backend_cbor_ead_decode.c +27 -32
  53. package/external/libedhoc/backends/cbor/src/backend_cbor_ead_encode.c +27 -32
  54. package/external/libedhoc/backends/cbor/src/backend_cbor_enc_structure_decode.c +14 -23
  55. package/external/libedhoc/backends/cbor/src/backend_cbor_enc_structure_encode.c +14 -23
  56. package/external/libedhoc/backends/cbor/src/backend_cbor_id_cred_x_decode.c +63 -52
  57. package/external/libedhoc/backends/cbor/src/backend_cbor_id_cred_x_encode.c +62 -51
  58. package/external/libedhoc/backends/cbor/src/backend_cbor_info_decode.c +14 -23
  59. package/external/libedhoc/backends/cbor/src/backend_cbor_info_encode.c +14 -23
  60. package/external/libedhoc/backends/cbor/src/backend_cbor_int_type_decode.c +11 -20
  61. package/external/libedhoc/backends/cbor/src/backend_cbor_int_type_encode.c +11 -20
  62. package/external/libedhoc/backends/cbor/src/backend_cbor_message_1_decode.c +54 -51
  63. package/external/libedhoc/backends/cbor/src/backend_cbor_message_1_encode.c +54 -51
  64. package/external/libedhoc/backends/cbor/src/backend_cbor_message_2_decode.c +11 -20
  65. package/external/libedhoc/backends/cbor/src/backend_cbor_message_2_encode.c +11 -20
  66. package/external/libedhoc/backends/cbor/src/backend_cbor_message_3_decode.c +11 -20
  67. package/external/libedhoc/backends/cbor/src/backend_cbor_message_3_encode.c +11 -20
  68. package/external/libedhoc/backends/cbor/src/backend_cbor_message_4_decode.c +11 -20
  69. package/external/libedhoc/backends/cbor/src/backend_cbor_message_4_encode.c +11 -20
  70. package/external/libedhoc/backends/cbor/src/backend_cbor_message_error_decode.c +36 -37
  71. package/external/libedhoc/backends/cbor/src/backend_cbor_message_error_encode.c +36 -37
  72. package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_2_decode.c +103 -80
  73. package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_2_encode.c +102 -79
  74. package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_3_decode.c +99 -76
  75. package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_3_encode.c +98 -75
  76. package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_4_decode.c +40 -41
  77. package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_4_encode.c +40 -41
  78. package/external/libedhoc/backends/cbor/src/backend_cbor_sig_structure_decode.c +15 -24
  79. package/external/libedhoc/backends/cbor/src/backend_cbor_sig_structure_encode.c +15 -24
  80. package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode.c +31 -0
  81. package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode.h +10 -0
  82. package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode2.c +18 -0
  83. package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode2.h +9 -0
  84. package/external/libedhoc/externals/Unity/examples/example_1/test/TestProductionCode.c +69 -0
  85. package/external/libedhoc/externals/Unity/examples/example_1/test/TestProductionCode2.c +38 -0
  86. package/external/libedhoc/externals/Unity/examples/example_1/test/test_runners/TestProductionCode2_Runner.c +53 -0
  87. package/external/libedhoc/externals/Unity/examples/example_1/test/test_runners/TestProductionCode_Runner.c +57 -0
  88. package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode.c +31 -0
  89. package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode.h +10 -0
  90. package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode2.c +18 -0
  91. package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode2.h +9 -0
  92. package/external/libedhoc/externals/Unity/examples/example_2/test/TestProductionCode.c +71 -0
  93. package/external/libedhoc/externals/Unity/examples/example_2/test/TestProductionCode2.c +40 -0
  94. package/external/libedhoc/externals/Unity/examples/example_2/test/test_runners/TestProductionCode2_Runner.c +16 -0
  95. package/external/libedhoc/externals/Unity/examples/example_2/test/test_runners/TestProductionCode_Runner.c +18 -0
  96. package/external/libedhoc/externals/Unity/examples/example_2/test/test_runners/all_tests.c +19 -0
  97. package/external/libedhoc/externals/Unity/examples/example_3/helper/UnityHelper.c +17 -0
  98. package/external/libedhoc/externals/Unity/examples/example_3/helper/UnityHelper.h +19 -0
  99. package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode.c +31 -0
  100. package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode.h +10 -0
  101. package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode2.c +18 -0
  102. package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode2.h +9 -0
  103. package/external/libedhoc/externals/Unity/examples/example_3/test/TestProductionCode.c +69 -0
  104. package/external/libedhoc/externals/Unity/examples/example_3/test/TestProductionCode2.c +38 -0
  105. package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode.c +31 -0
  106. package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode.h +10 -0
  107. package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode2.c +18 -0
  108. package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode2.h +9 -0
  109. package/external/libedhoc/externals/Unity/examples/example_4/test/TestProductionCode.c +70 -0
  110. package/external/libedhoc/externals/Unity/examples/example_4/test/TestProductionCode2.c +42 -0
  111. package/external/libedhoc/externals/Unity/examples/example_4/test/test_runners/TestProductionCode2_Runner.c +53 -0
  112. package/external/libedhoc/externals/Unity/examples/example_4/test/test_runners/TestProductionCode_Runner.c +57 -0
  113. package/external/libedhoc/externals/Unity/examples/unity_config.h +251 -0
  114. package/external/libedhoc/externals/Unity/extras/bdd/src/unity_bdd.h +44 -0
  115. package/external/libedhoc/externals/Unity/extras/bdd/test/test_bdd.c +129 -0
  116. package/external/libedhoc/externals/Unity/extras/fixture/src/unity_fixture.c +310 -0
  117. package/external/libedhoc/externals/Unity/extras/fixture/src/unity_fixture.h +95 -0
  118. package/external/libedhoc/externals/Unity/extras/fixture/src/unity_fixture_internals.h +51 -0
  119. package/external/libedhoc/externals/Unity/extras/fixture/test/main/AllTests.c +20 -0
  120. package/external/libedhoc/externals/Unity/extras/fixture/test/template_fixture_tests.c +40 -0
  121. package/external/libedhoc/externals/Unity/extras/fixture/test/unity_fixture_Test.c +246 -0
  122. package/external/libedhoc/externals/Unity/extras/fixture/test/unity_fixture_TestRunner.c +33 -0
  123. package/external/libedhoc/externals/Unity/extras/memory/src/unity_memory.c +203 -0
  124. package/external/libedhoc/externals/Unity/extras/memory/src/unity_memory.h +61 -0
  125. package/external/libedhoc/externals/Unity/extras/memory/test/unity_memory_Test.c +326 -0
  126. package/external/libedhoc/externals/Unity/extras/memory/test/unity_memory_TestRunner.c +50 -0
  127. package/external/libedhoc/externals/Unity/extras/memory/test/unity_output_Spy.c +57 -0
  128. package/external/libedhoc/externals/Unity/extras/memory/test/unity_output_Spy.h +17 -0
  129. package/external/libedhoc/externals/Unity/src/unity.c +2501 -0
  130. package/external/libedhoc/externals/Unity/src/unity.h +698 -0
  131. package/external/libedhoc/externals/Unity/src/unity_internals.h +1183 -0
  132. package/external/libedhoc/externals/Unity/test/expectdata/testsample_cmd.c +61 -0
  133. package/external/libedhoc/externals/Unity/test/expectdata/testsample_def.c +57 -0
  134. package/external/libedhoc/externals/Unity/test/expectdata/testsample_head1.c +55 -0
  135. package/external/libedhoc/externals/Unity/test/expectdata/testsample_head1.h +15 -0
  136. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_cmd.c +80 -0
  137. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_def.c +76 -0
  138. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_head1.c +75 -0
  139. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_head1.h +13 -0
  140. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_new1.c +89 -0
  141. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_new2.c +89 -0
  142. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_param.c +77 -0
  143. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_run1.c +89 -0
  144. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_run2.c +89 -0
  145. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_yaml.c +90 -0
  146. package/external/libedhoc/externals/Unity/test/expectdata/testsample_new1.c +67 -0
  147. package/external/libedhoc/externals/Unity/test/expectdata/testsample_new2.c +70 -0
  148. package/external/libedhoc/externals/Unity/test/expectdata/testsample_param.c +58 -0
  149. package/external/libedhoc/externals/Unity/test/expectdata/testsample_run1.c +67 -0
  150. package/external/libedhoc/externals/Unity/test/expectdata/testsample_run2.c +70 -0
  151. package/external/libedhoc/externals/Unity/test/expectdata/testsample_yaml.c +71 -0
  152. package/external/libedhoc/externals/Unity/test/testdata/CException.h +18 -0
  153. package/external/libedhoc/externals/Unity/test/testdata/Defs.h +16 -0
  154. package/external/libedhoc/externals/Unity/test/testdata/cmock.h +21 -0
  155. package/external/libedhoc/externals/Unity/test/testdata/mockMock.h +20 -0
  156. package/external/libedhoc/externals/Unity/test/testdata/testRunnerGenerator.c +204 -0
  157. package/external/libedhoc/externals/Unity/test/testdata/testRunnerGeneratorSmall.c +73 -0
  158. package/external/libedhoc/externals/Unity/test/testdata/testRunnerGeneratorWithMocks.c +200 -0
  159. package/external/libedhoc/externals/Unity/test/tests/self_assessment_utils.h +151 -0
  160. package/external/libedhoc/externals/Unity/test/tests/test_unity_arrays.c +2941 -0
  161. package/external/libedhoc/externals/Unity/test/tests/test_unity_core.c +375 -0
  162. package/external/libedhoc/externals/Unity/test/tests/test_unity_doubles.c +1285 -0
  163. package/external/libedhoc/externals/Unity/test/tests/test_unity_floats.c +1395 -0
  164. package/external/libedhoc/externals/Unity/test/tests/test_unity_integers.c +2863 -0
  165. package/external/libedhoc/externals/Unity/test/tests/test_unity_integers_64.c +783 -0
  166. package/external/libedhoc/externals/Unity/test/tests/test_unity_memory.c +82 -0
  167. package/external/libedhoc/externals/Unity/test/tests/test_unity_parameterized.c +309 -0
  168. package/external/libedhoc/externals/Unity/test/tests/test_unity_parameterizedDemo.c +28 -0
  169. package/external/libedhoc/externals/Unity/test/tests/test_unity_strings.c +330 -0
  170. package/external/libedhoc/externals/Unity/test/tests/types_for_test.h +21 -0
  171. package/external/libedhoc/externals/zcbor/include/zcbor_common.h +147 -60
  172. package/external/libedhoc/externals/zcbor/include/zcbor_decode.h +291 -202
  173. package/external/libedhoc/externals/zcbor/include/zcbor_encode.h +100 -156
  174. package/external/libedhoc/externals/zcbor/include/zcbor_print.h +165 -0
  175. package/external/libedhoc/externals/zcbor/samples/hello_world/src/main.c +1 -1
  176. package/external/libedhoc/externals/zcbor/samples/pet/include/pet_decode.h +1 -1
  177. package/external/libedhoc/externals/zcbor/samples/pet/include/pet_encode.h +1 -1
  178. package/external/libedhoc/externals/zcbor/samples/pet/include/pet_types.h +4 -4
  179. package/external/libedhoc/externals/zcbor/samples/pet/src/main.c +4 -4
  180. package/external/libedhoc/externals/zcbor/samples/pet/src/pet_decode.c +15 -24
  181. package/external/libedhoc/externals/zcbor/samples/pet/src/pet_encode.c +14 -23
  182. package/external/libedhoc/externals/zcbor/src/zcbor_common.c +202 -29
  183. package/external/libedhoc/externals/zcbor/src/zcbor_decode.c +633 -173
  184. package/external/libedhoc/externals/zcbor/src/zcbor_encode.c +71 -184
  185. package/external/libedhoc/externals/zcbor/tests/decode/test1_suit_old_formats/src/main.c +152 -153
  186. package/external/libedhoc/externals/zcbor/tests/decode/test2_suit/src/main.c +64 -64
  187. package/external/libedhoc/externals/zcbor/tests/decode/test3_simple/src/main.c +15 -16
  188. package/external/libedhoc/externals/zcbor/tests/decode/test5_corner_cases/src/main.c +228 -84
  189. package/external/libedhoc/externals/zcbor/tests/decode/test7_suit9_simple/src/main.c +9 -9
  190. package/external/libedhoc/externals/zcbor/tests/decode/test8_suit12/src/main.c +0 -1
  191. package/external/libedhoc/externals/zcbor/tests/decode/test9_manifest14/src/main.c +172 -173
  192. package/external/libedhoc/externals/zcbor/tests/encode/test1_suit/src/main.c +73 -73
  193. package/external/libedhoc/externals/zcbor/tests/encode/test2_simple/src/main.c +1 -2
  194. package/external/libedhoc/externals/zcbor/tests/encode/test3_corner_cases/src/main.c +83 -56
  195. package/external/libedhoc/externals/zcbor/tests/encode/test4_senml/src/main.c +15 -16
  196. package/external/libedhoc/externals/zcbor/tests/fuzz/fuzz_everything.c +12 -0
  197. package/external/libedhoc/externals/zcbor/tests/fuzz/fuzz_manifest12.c +69 -69
  198. package/external/libedhoc/externals/zcbor/tests/unit/test1_unit_tests/src/main.c +448 -55
  199. package/external/libedhoc/externals/zcbor/tests/unit/test3_float16/src/main.c +49 -48
  200. package/external/libedhoc/include/edhoc.h +348 -54
  201. package/external/libedhoc/include/edhoc_common.h +289 -0
  202. package/external/libedhoc/include/edhoc_context.h +60 -35
  203. package/external/libedhoc/include/edhoc_credentials.h +55 -7
  204. package/external/libedhoc/include/edhoc_crypto.h +10 -10
  205. package/external/libedhoc/include/edhoc_ead.h +13 -10
  206. package/external/libedhoc/include/edhoc_macros.h +20 -11
  207. package/external/libedhoc/include/edhoc_values.h +2 -2
  208. package/external/libedhoc/library/edhoc.c +70 -36
  209. package/external/libedhoc/library/edhoc_common.c +1314 -0
  210. package/external/libedhoc/library/edhoc_exporter.c +45 -46
  211. package/external/libedhoc/library/edhoc_message_1.c +107 -72
  212. package/external/libedhoc/library/edhoc_message_2.c +396 -1693
  213. package/external/libedhoc/library/edhoc_message_3.c +465 -1656
  214. package/external/libedhoc/library/edhoc_message_4.c +93 -91
  215. package/external/libedhoc/library/edhoc_message_error.c +41 -41
  216. package/external/libedhoc/tests/include/{cipher_suites/cipher_suite_0.h → cipher_suite_0.h} +131 -134
  217. package/external/libedhoc/tests/include/{cipher_suites/cipher_suite_2.h → cipher_suite_2.h} +139 -140
  218. package/external/libedhoc/tests/include/{edhoc_trace_1/test_vector_1.h → test_vector_rfc9529_chapter_2.h} +786 -738
  219. package/external/libedhoc/tests/include/{edhoc_trace_2/test_vector_2.h → test_vector_rfc9529_chapter_3.h} +14 -10
  220. 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
  221. 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
  222. 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
  223. 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
  224. package/external/libedhoc/tests/src/{cipher_suites/cipher_suite_0.c → cipher_suite_0.c} +445 -447
  225. package/external/libedhoc/tests/src/{cipher_suites/cipher_suite_2.c → cipher_suite_2.c} +600 -600
  226. package/external/libedhoc/tests/src/module_test_api.c +430 -0
  227. package/external/libedhoc/tests/src/module_test_cipher_suite_0.c +395 -0
  228. package/external/libedhoc/tests/src/module_test_cipher_suite_2.c +392 -0
  229. package/external/libedhoc/tests/src/{error_message/test_edhoc_error_message.c → module_test_error_message.c} +94 -69
  230. package/external/libedhoc/tests/src/module_test_main.c +49 -0
  231. package/external/libedhoc/tests/src/{cipher_suite_negotiation/test_edhoc_cipher_suite_negotiation.c → module_test_rfc9528_suites_negotiation.c} +224 -227
  232. package/external/libedhoc/tests/src/module_test_rfc9529_chapter_2.c +2681 -0
  233. package/external/libedhoc/tests/src/module_test_rfc9529_chapter_3.c +1635 -0
  234. package/external/libedhoc/tests/src/module_test_x5chain_sign_keys_suite_0.c +1135 -0
  235. package/external/libedhoc/tests/src/module_test_x5chain_sign_keys_suite_2.c +1249 -0
  236. package/external/libedhoc/tests/src/module_test_x5chain_static_dh_keys_suite_2.c +798 -0
  237. package/external/libedhoc/tests/src/module_test_x5t_sign_keys_suite_2.c +956 -0
  238. package/include/EdhocComposeAsyncWorker.h +8 -6
  239. package/include/EdhocCredentialManager.h +16 -11
  240. package/include/EdhocCryptoManager.h +28 -21
  241. package/include/EdhocEadManager.h +3 -6
  242. package/include/{EdhocExportAsyncWorker.h → EdhocExportOscoreAsyncWorker.h} +20 -17
  243. package/include/EdhocKeyExporterAsyncWorker.h +76 -0
  244. package/include/EdhocKeyUpdateAsyncWorker.h +72 -0
  245. package/include/EdhocProcessAsyncWorker.h +14 -10
  246. package/include/LibEDHOC.h +44 -20
  247. package/include/UserContext.h +7 -9
  248. package/include/Utils.h +31 -27
  249. package/package.json +14 -3
  250. package/prebuilds/android-arm/edhoc.armv7.node +0 -0
  251. package/prebuilds/android-arm64/edhoc.armv8.node +0 -0
  252. package/prebuilds/darwin-arm64/edhoc.node +0 -0
  253. package/prebuilds/darwin-x64/edhoc.node +0 -0
  254. package/prebuilds/linux-arm/edhoc.armv6.node +0 -0
  255. package/prebuilds/linux-arm/edhoc.armv7.node +0 -0
  256. package/prebuilds/linux-arm64/edhoc.armv8.node +0 -0
  257. package/prebuilds/linux-x64/edhoc.glibc.node +0 -0
  258. package/prebuilds/linux-x64/edhoc.musl.node +0 -0
  259. package/prebuilds/win32-ia32/edhoc.node +0 -0
  260. package/prebuilds/win32-x64/edhoc.node +0 -0
  261. package/src/EdhocComposeAsyncWorker.cpp +18 -35
  262. package/src/EdhocCredentialManager.cpp +160 -187
  263. package/src/EdhocCryptoManager.cpp +386 -586
  264. package/src/EdhocEadManager.cpp +10 -18
  265. package/src/EdhocExportOscoreAsyncWorker.cpp +77 -0
  266. package/src/EdhocKeyExporterAsyncWorker.cpp +49 -0
  267. package/src/EdhocKeyUpdateAsyncWorker.cpp +41 -0
  268. package/src/EdhocProcessAsyncWorker.cpp +72 -19
  269. package/src/LibEDHOC.cpp +213 -174
  270. package/src/Suites.cpp +39 -72
  271. package/src/Utils.cpp +32 -56
  272. package/test/basic.test.ts +64 -0
  273. package/test/vectors.test.ts +111 -0
  274. package/dist/credentials.d.ts +0 -16
  275. package/dist/credentials.d.ts.map +0 -1
  276. package/dist/credentials.js +0 -84
  277. package/external/libedhoc/externals/zcbor/include/zcbor_debug.h +0 -69
  278. package/external/libedhoc/tests/include/cipher_suite_negotiation/test_edhoc_cipher_suite_negotiation.h +0 -37
  279. package/external/libedhoc/tests/include/cipher_suites/test_cipher_suite_0.h +0 -48
  280. package/external/libedhoc/tests/include/cipher_suites/test_cipher_suite_2.h +0 -48
  281. package/external/libedhoc/tests/include/edhoc_trace_1/authentication_credentials_1.h +0 -60
  282. package/external/libedhoc/tests/include/edhoc_trace_1/test_edhoc_handshake_1.h +0 -208
  283. package/external/libedhoc/tests/include/edhoc_trace_1/test_edhoc_handshake_ead_1.h +0 -59
  284. package/external/libedhoc/tests/include/edhoc_trace_2/authentication_credentials_2.h +0 -60
  285. package/external/libedhoc/tests/include/edhoc_trace_2/test_edhoc_handshake_2.h +0 -199
  286. package/external/libedhoc/tests/include/error_message/test_edhoc_error_message.h +0 -48
  287. package/external/libedhoc/tests/include/x509_chain_cs_0/authentication_credentials_x5chain_cs_0.h +0 -92
  288. package/external/libedhoc/tests/include/x509_chain_cs_0/test_edhoc_handshake_x5chain_cs_0.h +0 -96
  289. package/external/libedhoc/tests/include/x509_chain_cs_2/authentication_credentials_x5chain_cs_2.h +0 -58
  290. package/external/libedhoc/tests/include/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2.h +0 -56
  291. package/external/libedhoc/tests/include/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2_ead.h +0 -57
  292. package/external/libedhoc/tests/include/x509_chain_cs_2_static_dh/authentication_credentials_x5chain_cs_2_static_dh.h +0 -59
  293. package/external/libedhoc/tests/include/x509_chain_cs_2_static_dh/test_edhoc_handshake_x5chain_cs_2_static_dh_ead.h +0 -57
  294. package/external/libedhoc/tests/include/x509_hash_cs_2/authentication_credentials_x5t_cs_2.h +0 -60
  295. package/external/libedhoc/tests/include/x509_hash_cs_2/test_edhoc_handshake_x5t_cs_2_ead.h +0 -57
  296. package/external/libedhoc/tests/src/cipher_suites/test_cipher_suite_0.c +0 -475
  297. package/external/libedhoc/tests/src/cipher_suites/test_cipher_suite_2.c +0 -473
  298. package/external/libedhoc/tests/src/edhoc_trace_1/authentication_credentials_1.c +0 -252
  299. package/external/libedhoc/tests/src/edhoc_trace_1/test_edhoc_handshake_1.c +0 -1829
  300. package/external/libedhoc/tests/src/edhoc_trace_1/test_edhoc_handshake_ead_1.c +0 -1247
  301. package/external/libedhoc/tests/src/edhoc_trace_2/authentication_credentials_2.c +0 -170
  302. package/external/libedhoc/tests/src/edhoc_trace_2/test_edhoc_handshake_2.c +0 -1783
  303. package/external/libedhoc/tests/src/tests.c +0 -228
  304. package/external/libedhoc/tests/src/x509_chain_cs_0/authentication_credentials_x5chain_cs_0.c +0 -332
  305. package/external/libedhoc/tests/src/x509_chain_cs_0/test_edhoc_handshake_x5chain_cs_0.c +0 -936
  306. package/external/libedhoc/tests/src/x509_chain_cs_2/authentication_credentials_x5chain_cs_2.c +0 -166
  307. package/external/libedhoc/tests/src/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2.c +0 -587
  308. package/external/libedhoc/tests/src/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2_ead.c +0 -917
  309. package/external/libedhoc/tests/src/x509_chain_cs_2_static_dh/authentication_credentials_x5chain_cs_2_static_dh.c +0 -186
  310. package/external/libedhoc/tests/src/x509_chain_cs_2_static_dh/test_edhoc_handshake_x5chain_cs_2_static_dh_ead.c +0 -743
  311. package/external/libedhoc/tests/src/x509_hash_cs_2/authentication_credentials_x5t_cs_2.c +0 -261
  312. package/external/libedhoc/tests/src/x509_hash_cs_2/test_edhoc_handshake_x5t_cs_2_ead.c +0 -854
  313. package/src/EdhocExportAsyncWorker.cpp +0 -82
@@ -16,6 +16,7 @@
16
16
  extern "C" {
17
17
  #endif
18
18
 
19
+
19
20
  /** The zcbor_encode library provides functions for encoding CBOR data elements.
20
21
  *
21
22
  * See The README for an introduction to CBOR, including the meaning of pint,
@@ -23,139 +24,72 @@ extern "C" {
23
24
  */
24
25
 
25
26
 
26
- /** The following param and retval docs apply to all single value encoding functions
27
- *
28
- * @param[inout] state The current state of the encoding.
29
- * @param[in] input The value to encode.
30
- *
31
- * @retval true Everything is ok.
32
- * @retval false If the payload is exhausted. Or an unexpected error happened.
33
- */
34
-
35
- /** Encode a pint/nint. */
36
- bool zcbor_int32_put(zcbor_state_t *state, int32_t input);
37
- bool zcbor_int64_put(zcbor_state_t *state, int64_t input);
38
- bool zcbor_uint32_put(zcbor_state_t *state, uint32_t input);
39
- bool zcbor_uint64_put(zcbor_state_t *state, uint64_t input);
40
- bool zcbor_size_put(zcbor_state_t *state, size_t input);
41
-
42
- /** Encode a pint/nint from a pointer.
43
- *
44
- * Can be used for bulk encoding with @ref zcbor_multi_encode.
45
- */
46
- bool zcbor_int_encode(zcbor_state_t *state, const void *input_int, size_t int_size);
47
- bool zcbor_int32_encode(zcbor_state_t *state, const int32_t *input);
48
- bool zcbor_int64_encode(zcbor_state_t *state, const int64_t *input);
49
- bool zcbor_uint_encode(zcbor_state_t *state, const void *input_uint, size_t uint_size);
50
- bool zcbor_uint32_encode(zcbor_state_t *state, const uint32_t *input);
51
- bool zcbor_uint64_encode(zcbor_state_t *state, const uint64_t *input);
52
- bool zcbor_size_encode(zcbor_state_t *state, const size_t *input);
53
-
54
- /** Encode a bstr. */
55
- bool zcbor_bstr_encode(zcbor_state_t *state, const struct zcbor_string *input);
56
- /** Encode a tstr. */
57
- bool zcbor_tstr_encode(zcbor_state_t *state, const struct zcbor_string *input);
58
-
59
- /** Encode a pointer to a string as a bstr/tstr.
60
- *
61
- * @param[inout] state The current state of the encoding.
62
- * @param[in] string The value to encode. A pointer to the string
63
- * @param[in] len The length of the string pointed to by @p string.
64
- */
65
- static inline bool zcbor_bstr_encode_ptr(zcbor_state_t *state, const char *ptr, size_t len)
66
- {
67
- const struct zcbor_string zs = { .value = (const uint8_t *)ptr, .len = len };
68
-
69
- return zcbor_bstr_encode(state, &zs);
70
- }
71
- static inline bool zcbor_tstr_encode_ptr(zcbor_state_t *state, const char *ptr, size_t len)
72
- {
73
- const struct zcbor_string zs = { .value = (const uint8_t *)ptr, .len = len };
74
-
75
- return zcbor_tstr_encode(state, &zs);
76
- }
77
-
78
- /** Encode a string literal as a bstr/tstr.
79
- *
80
- * @param[inout] state The current state of the encoding.
81
- * @param[in] string The value to encode. A string literal, e.g. "Foo", so
82
- * that sizeof(string) - 1 is the length of the string.
83
- */
84
- #define zcbor_bstr_put_lit(state, string) \
85
- zcbor_bstr_encode_ptr(state, string, sizeof(string) - 1)
86
- #define zcbor_tstr_put_lit(state, string) \
87
- zcbor_tstr_encode_ptr(state, string, sizeof(string) - 1)
27
+ /** See @ref zcbor_new_state() */
28
+ void zcbor_new_encode_state(zcbor_state_t *state_array, size_t n_states,
29
+ uint8_t *payload, size_t payload_len, size_t elem_count);
88
30
 
89
- /** Encode null-terminated string as a bstr/tstr.
31
+ /** Convenience macro for declaring and initializing an encoding state with backups.
90
32
  *
91
- * @param[inout] state The current state of the encoding.
92
- * @param[in] string The value to encode. Must be a null-terminated string,
93
- * so that strlen can be used.
94
- */
95
- #define zcbor_bstr_put_term(state, string) \
96
- zcbor_bstr_encode_ptr(state, string, strlen(string))
97
- #define zcbor_tstr_put_term(state, string) \
98
- zcbor_tstr_encode_ptr(state, string, strlen(string))
99
-
100
- /** Encode a char array literal as a bstr/tstr.
33
+ * This gives you a state variable named @p name. The variable functions like
34
+ * a pointer.
101
35
  *
102
- * @param[inout] state The current state of the encoding.
103
- * @param[in] string The value to encode. An array literal, e.g. {'F', 'o', 'o'},
104
- * so that sizeof(string) is the length of the string.
36
+ * @param[in] name The name of the new state variable.
37
+ * @param[in] num_backups The number of backup slots to keep in the state.
38
+ * @param[in] payload The payload to work on.
39
+ * @param[in] payload_size The size (in bytes) of @p payload.
40
+ * @param[in] elem_count The starting elem_count (typically 1).
105
41
  */
106
- #define zcbor_bstr_put_arr(state, string) \
107
- zcbor_bstr_encode_ptr(state, string, sizeof(string))
108
- #define zcbor_tstr_put_arr(state, string) \
109
- zcbor_tstr_encode_ptr(state, string, sizeof(string))
110
-
111
- /** Encode a tag. Must be called before encoding the value being tagged. */
112
- bool zcbor_tag_encode(zcbor_state_t *state, uint32_t tag);
113
-
114
- /** Encode a simple value. */
115
- bool zcbor_simple_encode(zcbor_state_t *state, uint8_t *input);
116
- bool zcbor_simple_put(zcbor_state_t *state, uint8_t input);
117
-
118
- /** Encode a boolean simple value. */
119
- bool zcbor_bool_put(zcbor_state_t *state, bool input);
120
- bool zcbor_bool_encode(zcbor_state_t *state, const bool *input);
42
+ #define ZCBOR_STATE_E(name, num_backups, payload, payload_size, elem_count) \
43
+ zcbor_state_t name[((num_backups) + 2)]; \
44
+ do { \
45
+ zcbor_new_encode_state(name, ZCBOR_ARRAY_SIZE(name), payload, payload_size, elem_count); \
46
+ } while(0)
121
47
 
122
- /** Encode an IEEE754 float */
123
- bool zcbor_float16_put(zcbor_state_t *state, float input);
124
- bool zcbor_float16_encode(zcbor_state_t *state, const float *input);
125
- bool zcbor_float16_bytes_put(zcbor_state_t *state, uint16_t input);
126
- bool zcbor_float16_bytes_encode(zcbor_state_t *state, const uint16_t *input);
127
- bool zcbor_float32_put(zcbor_state_t *state, float input);
128
- bool zcbor_float32_encode(zcbor_state_t *state, const float *input);
129
- bool zcbor_float64_put(zcbor_state_t *state, double input);
130
- bool zcbor_float64_encode(zcbor_state_t *state, const double *input);
131
48
 
132
- /** Encode a "nil"/"undefined" simple value. @p unused should be NULL.
49
+ /** The following applies to all _put and _encode functions listed directly below.
133
50
  *
134
- * @param[inout] state The current state of the encoding.
135
- * @param[in] unused Unused parameter to maintain signature parity with
136
- * @ref zcbor_encoder_t.
137
- */
138
- bool zcbor_nil_put(zcbor_state_t *state, const void *unused);
139
- bool zcbor_undefined_put(zcbor_state_t *state, const void *unused);
140
-
141
- /** Encode a bstr header.
51
+ * The difference between _put and _encode is only in the argument type,
52
+ * but when a @ref zcbor_encoder_t is needed, such as for @ref zcbor_multi_encode,
53
+ * the _encode variant must be used.
142
54
  *
143
- * The rest of the string can be encoded as CBOR.
144
- * A state backup is created to keep track of the element count.
145
- * Call @ref zcbor_bstr_end_encode when done encoding the contents of the bstr.
146
- *
147
- * @param[inout] state The current state of the encoding.
148
- *
149
- * @retval true Header encoded correctly
150
- * @retval false Header encoded incorrectly, or backup failed.
151
- */
152
- bool zcbor_bstr_start_encode(zcbor_state_t *state);
153
-
154
- /** Finalize encoding a CBOR-encoded bstr.
55
+ * @param[inout] state The current state of the encoding.
56
+ * @param[in] input The value to encode.
155
57
  *
156
- * Restore element count from backup.
157
- */
158
- bool zcbor_bstr_end_encode(zcbor_state_t *state, struct zcbor_string *result);
58
+ * @retval true Everything is ok.
59
+ * @retval false If the payload is exhausted. Or an unexpected error happened.
60
+ * Use zcbor_peek_error() to see the error code.
61
+ */
62
+ bool zcbor_int32_put(zcbor_state_t *state, int32_t input); /* pint/nint */
63
+ bool zcbor_int64_put(zcbor_state_t *state, int64_t input); /* pint/nint */
64
+ bool zcbor_uint32_put(zcbor_state_t *state, uint32_t input); /* pint */
65
+ bool zcbor_uint64_put(zcbor_state_t *state, uint64_t input); /* pint */
66
+ bool zcbor_size_put(zcbor_state_t *state, size_t input); /* pint */
67
+ bool zcbor_tag_put(zcbor_state_t *state, uint32_t tag); /* CBOR tag */
68
+ bool zcbor_simple_put(zcbor_state_t *state, uint8_t input); /* CBOR simple value */
69
+ bool zcbor_bool_put(zcbor_state_t *state, bool input); /* boolean CBOR simple value */
70
+ bool zcbor_nil_put(zcbor_state_t *state, const void *unused); /* 'nil' CBOR simple value */
71
+ bool zcbor_undefined_put(zcbor_state_t *state, const void *unused); /* 'undefined' CBOR simple value */
72
+ bool zcbor_float16_put(zcbor_state_t *state, float input); /* IEEE754 float16 */
73
+ bool zcbor_float16_bytes_put(zcbor_state_t *state, uint16_t input); /* IEEE754 float16 raw bytes */
74
+ bool zcbor_float32_put(zcbor_state_t *state, float input); /* IEEE754 float32 */
75
+ bool zcbor_float64_put(zcbor_state_t *state, double input); /* IEEE754 float64 */
76
+
77
+ bool zcbor_int32_encode(zcbor_state_t *state, const int32_t *input); /* pint/nint */
78
+ bool zcbor_int64_encode(zcbor_state_t *state, const int64_t *input); /* pint/nint */
79
+ bool zcbor_uint32_encode(zcbor_state_t *state, const uint32_t *input); /* pint */
80
+ bool zcbor_uint64_encode(zcbor_state_t *state, const uint64_t *input); /* pint */
81
+ bool zcbor_size_encode(zcbor_state_t *state, const size_t *input); /* pint */
82
+ bool zcbor_int_encode(zcbor_state_t *state, const void *input_int, size_t int_size);
83
+ bool zcbor_uint_encode(zcbor_state_t *state, const void *input_uint, size_t uint_size);
84
+ bool zcbor_bstr_encode(zcbor_state_t *state, const struct zcbor_string *input); /* bstr */
85
+ bool zcbor_tstr_encode(zcbor_state_t *state, const struct zcbor_string *input); /* tstr */
86
+ bool zcbor_tag_encode(zcbor_state_t *state, uint32_t *tag); /* CBOR tag. Note that zcbor_tag_encode()'s argument was changed to be a pointer. See also zcbor_tag_put(). */
87
+ bool zcbor_simple_encode(zcbor_state_t *state, uint8_t *input); /* CBOR simple value */
88
+ bool zcbor_bool_encode(zcbor_state_t *state, const bool *input); /* boolean CBOR simple value */
89
+ bool zcbor_float16_encode(zcbor_state_t *state, const float *input); /* IEEE754 float16 */
90
+ bool zcbor_float16_bytes_encode(zcbor_state_t *state, const uint16_t *input); /* IEEE754 float16 raw bytes */
91
+ bool zcbor_float32_encode(zcbor_state_t *state, const float *input); /* IEEE754 float32 */
92
+ bool zcbor_float64_encode(zcbor_state_t *state, const double *input); /* IEEE754 float64 */
159
93
 
160
94
  /** Encode a list/map header.
161
95
  *
@@ -245,49 +179,59 @@ bool zcbor_list_map_end_force_encode(zcbor_state_t *state);
245
179
  * @retval false If @p encoder failed before having encoded @p min_encode
246
180
  * values.
247
181
  */
248
- bool zcbor_multi_encode(size_t num_encode,
249
- zcbor_encoder_t encoder,
250
- zcbor_state_t *state,
251
- const void *input,
252
- size_t result_len);
182
+ bool zcbor_multi_encode(size_t num_encode, zcbor_encoder_t encoder,
183
+ zcbor_state_t *state, const void *input, size_t result_len);
253
184
 
254
185
  /** Works like @ref zcbor_multi_encode
255
186
  *
256
187
  * But first checks that @p num_encode is between @p min_encode and @p max_encode.
257
188
  */
258
- bool zcbor_multi_encode_minmax(size_t min_encode, size_t max_encode, const size_t *num_encode,
259
- zcbor_encoder_t encoder, zcbor_state_t *state, const void *input,
260
- size_t input_len);
189
+ bool zcbor_multi_encode_minmax(size_t min_encode, size_t max_encode,
190
+ const size_t *num_encode, zcbor_encoder_t encoder,
191
+ zcbor_state_t *state, const void *input, size_t input_len);
261
192
 
262
- /** Runs @p encoder on @p state and @p input if @p present is true.
263
- *
264
- * Calls @ref zcbor_multi_encode under the hood.
265
- */
266
- bool zcbor_present_encode(const bool *present,
267
- zcbor_encoder_t encoder,
268
- zcbor_state_t *state,
269
- const void *input);
270
193
 
271
- /** See @ref zcbor_new_state() */
272
- void zcbor_new_encode_state(zcbor_state_t *state_array, size_t n_states,
273
- uint8_t *payload, size_t payload_len, size_t elem_count);
194
+ /* Supplementary string (bstr/tstr) encoding functions: */
274
195
 
275
- /** Convenience macro for declaring and initializing a state with backups.
196
+ /** Encode a char/uint8_t pointer as a bstr/tstr.
276
197
  *
277
- * This gives you a state variable named @p name. The variable functions like
278
- * a pointer.
198
+ * @param[inout] state The current state of the encoding.
199
+ * @param[in] str The value to encode. A pointer to the string/array.
200
+ * _term() uses strnlen(), so @p str must be null-terminated.
201
+ * _lit() uses sizeof()-1, so @p str must be a (null-terminated) string literal.
202
+ * _arr() uses sizeof(), so @p str must be a uint8_t array (not null-terminated).
203
+ * @param[in] len (if present) The length of the string pointed to by @p str
204
+ * @param[in] maxlen (if present) The maximum length of the string pointed to by @p str.
205
+ * This value is passed to strnlen.
206
+ */
207
+ bool zcbor_bstr_encode_ptr(zcbor_state_t *state, const char *str, size_t len);
208
+ bool zcbor_tstr_encode_ptr(zcbor_state_t *state, const char *str, size_t len);
209
+ bool zcbor_bstr_put_term(zcbor_state_t *state, char const *str, size_t maxlen);
210
+ bool zcbor_tstr_put_term(zcbor_state_t *state, char const *str, size_t maxlen);
211
+ #define zcbor_bstr_put_lit(state, str) zcbor_bstr_encode_ptr(state, str, sizeof(str) - 1)
212
+ #define zcbor_tstr_put_lit(state, str) zcbor_tstr_encode_ptr(state, str, sizeof(str) - 1)
213
+ #define zcbor_bstr_put_arr(state, str) zcbor_bstr_encode_ptr(state, str, sizeof(str))
214
+ #define zcbor_tstr_put_arr(state, str) zcbor_tstr_encode_ptr(state, str, sizeof(str))
215
+
216
+ /** Encode a bstr header.
279
217
  *
280
- * @param[in] name The name of the new state variable.
281
- * @param[in] num_backups The number of backup slots to keep in the state.
282
- * @param[in] payload The payload to work on.
283
- * @param[in] payload_size The size (in bytes) of @p payload.
284
- * @param[in] elem_count The starting elem_count (typically 1).
218
+ * The rest of the string can be encoded as CBOR.
219
+ * A state backup is created to keep track of the element count.
220
+ * Call @ref zcbor_bstr_end_encode when done encoding the contents of the bstr.
221
+ *
222
+ * @param[inout] state The current state of the encoding.
223
+ *
224
+ * @retval true Header encoded correctly
225
+ * @retval false Header encoded incorrectly, or backup failed.
285
226
  */
286
- #define ZCBOR_STATE_E(name, num_backups, payload, payload_size, elem_count) \
287
- zcbor_state_t name[((num_backups) + 2)]; \
288
- do { \
289
- zcbor_new_encode_state(name, ZCBOR_ARRAY_SIZE(name), payload, payload_size, elem_count); \
290
- } while(0)
227
+ bool zcbor_bstr_start_encode(zcbor_state_t *state);
228
+
229
+ /** Finalize encoding a CBOR-encoded bstr.
230
+ *
231
+ * This writes the final size of the bstr to the header.
232
+ * Restore element count from backup.
233
+ */
234
+ bool zcbor_bstr_end_encode(zcbor_state_t *state, struct zcbor_string *result);
291
235
 
292
236
  #ifdef __cplusplus
293
237
  }
@@ -0,0 +1,165 @@
1
+ /*
2
+ * Copyright (c) 2023 Nordic Semiconductor ASA
3
+ *
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ #ifndef ZCBOR_PRINT_H__
8
+ #define ZCBOR_PRINT_H__
9
+
10
+
11
+ #ifdef __cplusplus
12
+ extern "C" {
13
+ #endif
14
+
15
+ #ifndef ZCBOR_PRINT_FUNC
16
+ #include <stdio.h>
17
+ #define zcbor_do_print(...) printf(__VA_ARGS__)
18
+ #else
19
+ #define zcbor_do_print(...) ZCBOR_PRINT_FUNC(__VA_ARGS__)
20
+ #endif
21
+
22
+ #ifdef ZCBOR_VERBOSE
23
+ #define zcbor_trace_raw(state) (zcbor_do_print("rem: %zu, cur: 0x%x, ec: 0x%zx, err: %d",\
24
+ (size_t)state->payload_end - (size_t)state->payload, *state->payload, state->elem_count, \
25
+ state->constant_state ? state->constant_state->error : 0))
26
+ #define zcbor_trace(state, appendix) do { \
27
+ zcbor_trace_raw(state); \
28
+ zcbor_do_print(", %s\n", appendix); \
29
+ } while(0)
30
+ #define zcbor_trace_file(state) do { \
31
+ zcbor_trace_raw(state); \
32
+ zcbor_do_print(", %s:%d\n", __FILE__, __LINE__); \
33
+ } while(0)
34
+
35
+ #define zcbor_log_assert(expr, ...) \
36
+ do { \
37
+ zcbor_do_print("ASSERTION \n \"" #expr \
38
+ "\"\nfailed at %s:%d with message:\n ", \
39
+ __FILE__, __LINE__); \
40
+ zcbor_do_print(__VA_ARGS__);\
41
+ } while(0)
42
+ #define zcbor_log(...) zcbor_do_print(__VA_ARGS__)
43
+ #else
44
+ #define zcbor_trace(state, appendix)
45
+ #define zcbor_trace_file(state) ((void)state)
46
+ #define zcbor_log_assert(...)
47
+ #define zcbor_log(...)
48
+ #endif
49
+
50
+ #ifdef ZCBOR_ASSERTS
51
+ #define zcbor_assert(expr, ...) \
52
+ do { \
53
+ if (!(expr)) { \
54
+ zcbor_log_assert(expr, __VA_ARGS__); \
55
+ ZCBOR_FAIL(); \
56
+ } \
57
+ } while(0)
58
+ #define zcbor_assert_state(expr, ...) \
59
+ do { \
60
+ if (!(expr)) { \
61
+ zcbor_log_assert(expr, __VA_ARGS__); \
62
+ ZCBOR_ERR(ZCBOR_ERR_ASSERTION); \
63
+ } \
64
+ } while(0)
65
+ #else
66
+ #define zcbor_assert(expr, ...)
67
+ #define zcbor_assert_state(expr, ...)
68
+ #endif
69
+
70
+ __attribute__((used))
71
+ static void zcbor_print_compare_lines(const uint8_t *str1, const uint8_t *str2, size_t size)
72
+ {
73
+ for (size_t j = 0; j < size; j++) {
74
+ zcbor_do_print("%x ", str1[j]);
75
+ }
76
+ zcbor_do_print("\r\n");
77
+ for (size_t j = 0; j < size; j++) {
78
+ zcbor_do_print("%x ", str2[j]);
79
+ }
80
+ zcbor_do_print("\r\n");
81
+ for (size_t j = 0; j < size; j++) {
82
+ zcbor_do_print("%x ", str1[j] != str2[j]);
83
+ }
84
+ zcbor_do_print("\r\n");
85
+ zcbor_do_print("\r\n");
86
+ }
87
+
88
+ __attribute__((used))
89
+ static void zcbor_print_compare_strings(const uint8_t *str1, const uint8_t *str2, size_t size)
90
+ {
91
+ const size_t col_width = 16;
92
+
93
+ for (size_t i = 0; i <= size / col_width; i++) {
94
+ zcbor_do_print("line %zu (char %zu)\r\n", i, i*col_width);
95
+ zcbor_print_compare_lines(&str1[i*col_width], &str2[i*col_width],
96
+ MIN(col_width, (size - i*col_width)));
97
+ }
98
+ zcbor_do_print("\r\n");
99
+ }
100
+
101
+ __attribute__((used))
102
+ static void zcbor_print_compare_strings_diff(const uint8_t *str1, const uint8_t *str2, size_t size)
103
+ {
104
+ const size_t col_width = 16;
105
+ bool printed = false;
106
+
107
+ for (size_t i = 0; i <= size / col_width; i++) {
108
+ if (memcmp(&str1[i*col_width], &str2[i*col_width], MIN(col_width, (size - i*col_width))) != 0) {
109
+ zcbor_do_print("line %zu (char %zu)\r\n", i, i*col_width);
110
+ zcbor_print_compare_lines(&str1[i*col_width], &str2[i*col_width],
111
+ MIN(col_width, (size - i*col_width)));
112
+ printed = true;
113
+ }
114
+ }
115
+ if (printed) {
116
+ zcbor_do_print("\r\n");
117
+ }
118
+ }
119
+
120
+ __attribute__((used))
121
+ static const char *zcbor_error_str(int error)
122
+ {
123
+ #define ZCBOR_ERR_CASE(err) case err: \
124
+ return #err; /* The literal is static per C99 6.4.5 paragraph 5. */\
125
+
126
+ switch(error) {
127
+ ZCBOR_ERR_CASE(ZCBOR_SUCCESS)
128
+ ZCBOR_ERR_CASE(ZCBOR_ERR_NO_BACKUP_MEM)
129
+ ZCBOR_ERR_CASE(ZCBOR_ERR_NO_BACKUP_ACTIVE)
130
+ ZCBOR_ERR_CASE(ZCBOR_ERR_LOW_ELEM_COUNT)
131
+ ZCBOR_ERR_CASE(ZCBOR_ERR_HIGH_ELEM_COUNT)
132
+ ZCBOR_ERR_CASE(ZCBOR_ERR_INT_SIZE)
133
+ ZCBOR_ERR_CASE(ZCBOR_ERR_FLOAT_SIZE)
134
+ ZCBOR_ERR_CASE(ZCBOR_ERR_ADDITIONAL_INVAL)
135
+ ZCBOR_ERR_CASE(ZCBOR_ERR_NO_PAYLOAD)
136
+ ZCBOR_ERR_CASE(ZCBOR_ERR_PAYLOAD_NOT_CONSUMED)
137
+ ZCBOR_ERR_CASE(ZCBOR_ERR_WRONG_TYPE)
138
+ ZCBOR_ERR_CASE(ZCBOR_ERR_WRONG_VALUE)
139
+ ZCBOR_ERR_CASE(ZCBOR_ERR_WRONG_RANGE)
140
+ ZCBOR_ERR_CASE(ZCBOR_ERR_ITERATIONS)
141
+ ZCBOR_ERR_CASE(ZCBOR_ERR_ASSERTION)
142
+ ZCBOR_ERR_CASE(ZCBOR_ERR_PAYLOAD_OUTDATED)
143
+ ZCBOR_ERR_CASE(ZCBOR_ERR_ELEM_NOT_FOUND)
144
+ ZCBOR_ERR_CASE(ZCBOR_ERR_MAP_MISALIGNED)
145
+ ZCBOR_ERR_CASE(ZCBOR_ERR_ELEMS_NOT_PROCESSED)
146
+ ZCBOR_ERR_CASE(ZCBOR_ERR_NOT_AT_END)
147
+ ZCBOR_ERR_CASE(ZCBOR_ERR_MAP_FLAGS_NOT_AVAILABLE)
148
+ ZCBOR_ERR_CASE(ZCBOR_ERR_INVALID_VALUE_ENCODING)
149
+ }
150
+ #undef ZCBOR_ERR_CASE
151
+
152
+ return "ZCBOR_ERR_UNKNOWN";
153
+ }
154
+
155
+ __attribute__((used))
156
+ static void zcbor_print_error(int error)
157
+ {
158
+ zcbor_do_print("%s\r\n", zcbor_error_str(error));
159
+ }
160
+
161
+ #ifdef __cplusplus
162
+ }
163
+ #endif
164
+
165
+ #endif /* ZCBOR_PRINT_H__ */
@@ -27,7 +27,7 @@ void main(void)
27
27
  }
28
28
 
29
29
  /* Create zcbor state variable for decoding. */
30
- ZCBOR_STATE_D(decoding_state, 0, cbor_payload, sizeof(cbor_payload), 1);
30
+ ZCBOR_STATE_D(decoding_state, 0, cbor_payload, sizeof(cbor_payload), 1, 0);
31
31
 
32
32
  /* Decode the text string into the cbor_payload buffer */
33
33
  success = zcbor_tstr_decode(decoding_state, &decoded_string);
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  *
6
- * Generated using zcbor version 0.7.0
6
+ * Generated using zcbor version 0.8.1
7
7
  * https://github.com/NordicSemiconductor/zcbor
8
8
  * Generated with a --default-max-qty of 3
9
9
  */
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  *
6
- * Generated using zcbor version 0.7.0
6
+ * Generated using zcbor version 0.8.1
7
7
  * https://github.com/NordicSemiconductor/zcbor
8
8
  * Generated with a --default-max-qty of 3
9
9
  */
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  *
6
- * Generated using zcbor version 0.7.0
6
+ * Generated using zcbor version 0.8.1
7
7
  * https://github.com/NordicSemiconductor/zcbor
8
8
  * Generated with a --default-max-qty of 3
9
9
  */
@@ -34,9 +34,9 @@ struct Pet {
34
34
  size_t names_count;
35
35
  struct zcbor_string birthday;
36
36
  enum {
37
- _Pet_species_cat = 1,
38
- _Pet_species_dog = 2,
39
- _Pet_species_other = 3,
37
+ Pet_species_cat_c = 1,
38
+ Pet_species_dog_c = 2,
39
+ Pet_species_other_c = 3,
40
40
  } species_choice;
41
41
  };
42
42
 
@@ -21,13 +21,13 @@ static void print_pet(const struct Pet *pet)
21
21
  printf("%02x", pet->birthday.value[i]);
22
22
  }
23
23
  switch (pet->species_choice) {
24
- case _Pet_species_cat:
24
+ case Pet_species_cat_c:
25
25
  printf("\nSpecies: Cat\n\n");
26
26
  return;
27
- case _Pet_species_dog:
27
+ case Pet_species_dog_c:
28
28
  printf("\nSpecies: Dog\n\n");
29
29
  return;
30
- case _Pet_species_other:
30
+ case Pet_species_other_c:
31
31
  printf("\nSpecies: Other\n\n");
32
32
  return;
33
33
  }
@@ -101,7 +101,7 @@ static void get_pet3(void)
101
101
  encoded_pet.names_count = 2;
102
102
  encoded_pet.birthday.value = timestamp3;
103
103
  encoded_pet.birthday.len = sizeof(timestamp3);
104
- encoded_pet.species_choice = _Pet_species_other;
104
+ encoded_pet.species_choice = Pet_species_other_c;
105
105
 
106
106
  err = cbor_encode_Pet(pet3, sizeof(pet3), &encoded_pet, NULL);
107
107
 
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  *
6
- * Generated using zcbor version 0.7.0
6
+ * Generated using zcbor version 0.8.1
7
7
  * https://github.com/NordicSemiconductor/zcbor
8
8
  * Generated with a --default-max-qty of 3
9
9
  */
@@ -14,6 +14,7 @@
14
14
  #include <string.h>
15
15
  #include "zcbor_decode.h"
16
16
  #include "pet_decode.h"
17
+ #include "zcbor_print.h"
17
18
 
18
19
  #if DEFAULT_MAX_QTY != 3
19
20
  #error "The type file was generated with a different default_max_qty than this file"
@@ -25,18 +26,22 @@ static bool decode_Pet(zcbor_state_t *state, struct Pet *result);
25
26
  static bool decode_Pet(
26
27
  zcbor_state_t *state, struct Pet *result)
27
28
  {
28
- zcbor_print("%s\r\n", __func__);
29
+ zcbor_log("%s\r\n", __func__);
29
30
 
30
31
  bool tmp_result = (((zcbor_list_start_decode(state) && ((((zcbor_list_start_decode(state) && ((zcbor_multi_decode(1, 3, &(*result).names_count, (zcbor_decoder_t *)zcbor_tstr_decode, state, (&(*result).names), sizeof(struct zcbor_string))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state)))
31
32
  && ((zcbor_bstr_decode(state, (&(*result).birthday)))
32
33
  && ((((((*result).birthday.len >= 8)
33
34
  && ((*result).birthday.len <= 8)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))
34
- && ((((zcbor_int_decode(state, &(*result).species_choice, sizeof((*result).species_choice)))) && ((((((*result).species_choice == _Pet_species_cat) && ((1)))
35
- || (((*result).species_choice == _Pet_species_dog) && ((1)))
36
- || (((*result).species_choice == _Pet_species_other) && ((1)))) || (zcbor_error(state, ZCBOR_ERR_WRONG_VALUE), false)))))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state))));
37
-
38
- if (!tmp_result)
39
- zcbor_trace();
35
+ && ((((zcbor_uint_decode(state, &(*result).species_choice, sizeof((*result).species_choice)))) && ((((((*result).species_choice == Pet_species_cat_c) && ((1)))
36
+ || (((*result).species_choice == Pet_species_dog_c) && ((1)))
37
+ || (((*result).species_choice == Pet_species_other_c) && ((1)))) || (zcbor_error(state, ZCBOR_ERR_WRONG_VALUE), false)))))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state))));
38
+
39
+ if (!tmp_result) {
40
+ zcbor_trace_file(state);
41
+ zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
42
+ } else {
43
+ zcbor_log("%s success\r\n", __func__);
44
+ }
40
45
 
41
46
  return tmp_result;
42
47
  }
@@ -50,20 +55,6 @@ int cbor_decode_Pet(
50
55
  {
51
56
  zcbor_state_t states[4];
52
57
 
53
- zcbor_new_state(states, sizeof(states) / sizeof(zcbor_state_t), payload, payload_len, 1);
54
-
55
- bool ret = decode_Pet(states, result);
56
-
57
- if (ret && (payload_len_out != NULL)) {
58
- *payload_len_out = MIN(payload_len,
59
- (size_t)states[0].payload - (size_t)payload);
60
- }
61
-
62
- if (!ret) {
63
- int err = zcbor_pop_error(states);
64
-
65
- zcbor_print("Return error: %d\r\n", err);
66
- return (err == ZCBOR_SUCCESS) ? ZCBOR_ERR_UNKNOWN : err;
67
- }
68
- return ZCBOR_SUCCESS;
58
+ return zcbor_entry_function(payload, payload_len, (void *)result, payload_len_out, states,
59
+ (zcbor_decoder_t *)decode_Pet, sizeof(states) / sizeof(zcbor_state_t), 1);
69
60
  }