Skip to content

Commit 4fb4592

Browse files
committed
imgtool: Fix custom TLV encoding
Encode custom TLV of integer type according to image's byteorder. Signed-off-by: Rustam Ismayilov <[email protected]> Change-Id: If5028e57473a66cf9be61c770f45d3c1e32d9632
1 parent 3e88a37 commit 4fb4592

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

scripts/imgtool/main.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@
1717
# See the License for the specific language governing permissions and
1818
# limitations under the License.
1919

20+
import base64
21+
import getpass
2022
import re
23+
import sys
24+
2125
import click
22-
import getpass
26+
2327
import imgtool.keys as keys
24-
import sys
25-
import base64
2628
from imgtool import image, imgtool_version
29+
from imgtool.dumpinfo import dump_imginfo
2730
from imgtool.keys.general import key_types_matching
2831
from imgtool.version import decode_version
29-
from imgtool.dumpinfo import dump_imginfo
3032
from .keys import (
3133
RSAUsageError, ECDSAUsageError, Ed25519UsageError, X25519UsageError)
3234

@@ -455,7 +457,10 @@ def sign(key, public_key_format, align, version, pad_sig, header_size,
455457
if value.startswith('0x'):
456458
if len(value[2:]) % 2:
457459
raise click.UsageError('Custom TLV length is odd.')
458-
custom_tlvs[tag] = bytes.fromhex(value[2:])
460+
ctlv_ba = bytearray.fromhex(value[2:])
461+
# encode integer TLVs as per byteorder
462+
ctlv_ba.reverse() if endian == "little" else None
463+
custom_tlvs[tag] = ctlv_ba
459464
else:
460465
custom_tlvs[tag] = value.encode('utf-8')
461466

0 commit comments

Comments
 (0)