Skip to content

Commit

Permalink
imgtool: Fix custom TLV encoding
Browse files Browse the repository at this point in the history
Encode custom TLV of integer type according to image's byteorder.

Signed-off-by: Rustam Ismayilov <rustam.ismayilov@arm.com>
Change-Id: If5028e57473a66cf9be61c770f45d3c1e32d9632
  • Loading branch information
rustammendel committed Jul 18, 2024
1 parent 1b4ebb2 commit ded02c9
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions scripts/imgtool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import base64
import getpass
import re
import sys

import click
import getpass

import imgtool.keys as keys
import sys
import base64
from imgtool import image, imgtool_version
from imgtool.dumpinfo import dump_imginfo
from imgtool.keys.general import key_types_matching
from imgtool.version import decode_version
from imgtool.dumpinfo import dump_imginfo
from .keys import (
RSAUsageError, ECDSAUsageError, Ed25519UsageError, X25519UsageError)

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

Expand Down

0 comments on commit ded02c9

Please sign in to comment.