blob: 3e8c202bcea41541de19f059a258c53c0f255027 [file] [log] [blame]
Andrew Geissler595f6302022-01-24 19:11:47 +00001Upstream-Status: Submitted [https://github.com/mcu-tools/mcuboot/pull/1190]
2Signed-off-by: Ross Burton <ross.burton@arm.com>
3
4From f9c6f31b936d34df9a6551609cb16ed9c348be88 Mon Sep 17 00:00:00 2001
5From: Ross Burton <ross.burton@arm.com>
6Date: Tue, 2 Nov 2021 11:12:04 +0000
7Subject: [PATCH] imgtool: prefer cbor2 over cbor
8
9The cbor module is unmaintained, with the last release in 2016[1]. The
10cbor2 module however is under active development and was last released
11just last month[2].
12
13As the APIs are identical, we can import cbor2 and if that fails fall
14back to cbor.
15
16[1] https://pypi.org/project/cbor/#history
17[2] https://pypi.org/project/cbor2/#history
18
19Closes #1189
20
21Signed-off-by: Ross Burton <ross.burton@arm.com>
22---
23 scripts/imgtool.nix | 2 +-
24 scripts/imgtool/boot_record.py | 7 +++++--
25 scripts/requirements.txt | 2 +-
26 scripts/setup.py | 2 +-
27 4 files changed, 8 insertions(+), 5 deletions(-)
28
29diff --git a/scripts/imgtool/boot_record.py b/scripts/imgtool/boot_record.py
30index ac433aa..6f0045e 100644
31--- a/scripts/imgtool/boot_record.py
32+++ b/scripts/imgtool/boot_record.py
33@@ -16,8 +16,11 @@
34 # limitations under the License.
35
36 from enum import Enum
37-import cbor
38
39+try:
40+ from cbor2 import dumps
41+except ImportError:
42+ from cbor import dumps
43
44 class SwComponent(int, Enum):
45 """
46@@ -46,4 +49,4 @@ def create_sw_component_data(sw_type, sw_version, sw_measurement_description,
47 # list because later it will be modified by the bootloader.
48 properties[SwComponent.MEASUREMENT_VALUE] = sw_measurement_value
49
50- return cbor.dumps(properties)
51+ return dumps(properties)
52diff --git a/scripts/setup.py b/scripts/setup.py
53index a228ea3..692cfb7 100644
54--- a/scripts/setup.py
55+++ b/scripts/setup.py
56@@ -17,7 +17,7 @@ setuptools.setup(
57 'cryptography>=2.4.2',
58 'intelhex>=2.2.1',
59 'click',
60- 'cbor>=1.0.0',
61+ 'cbor2',
62 ],
63 entry_points={
64 "console_scripts": ["imgtool=imgtool.main:imgtool"]
65--
662.25.1
67