Skip to content

Commit 1a0f25a

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 14e2987 commit 1a0f25a

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

@@ -462,7 +464,10 @@ def sign(key, public_key_format, align, version, pad_sig, header_size,
462464
if value.startswith('0x'):
463465
if len(value[2:]) % 2:
464466
raise click.UsageError('Custom TLV length is odd.')
465-
custom_tlvs[tag] = bytes.fromhex(value[2:])
467+
ctlv_ba = bytearray.fromhex(value[2:])
468+
# encode integer TLVs as per byteorder
469+
ctlv_ba.reverse() if endian == "little" else None
470+
custom_tlvs[tag] = ctlv_ba
466471
else:
467472
custom_tlvs[tag] = value.encode('utf-8')
468473

0 commit comments

Comments
 (0)