From 05d30eb666923a1a9cec08f7c0bced7f297fd02b Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Mon, 29 Aug 2022 20:24:44 +0700 Subject: [PATCH] construct: use Python's API for int<->bytes conversion Argument 'signed' was added in [1] and become available since v2.10.63. Therefore using bytes2integer() and integer2bytes() from construct.core bumps the minimum required version of construct to v2.10.63. For instance, debian:bullseye currently ships v2.10.58. There is no strict requirement to use construct's API, so let's use Python's API instead. This allows using older construct versions from the v2.9.xx family. Change-Id: I613dbfebe993f9c19003635371941710fc1b1236 Related: [1] 660ddbe2d9a351731ad7976351adbf413809a715 construct.git Related: OS#5666 --- pySim/construct.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pySim/construct.py b/pySim/construct.py index 4910a7fc..97af235a 100644 --- a/pySim/construct.py +++ b/pySim/construct.py @@ -2,7 +2,7 @@ from construct.lib.containers import Container, ListContainer from construct.core import EnumIntegerString import typing from construct import * -from construct.core import evaluate, bytes2integer, integer2bytes, BitwisableString +from construct.core import evaluate, BitwisableString from construct.lib import integertypes from pySim.utils import b2h, h2b, swap_nibbles import gsm0338 @@ -219,7 +219,7 @@ class GreedyInteger(Construct): if evaluate(self.swapped, context): data = swapbytes(data) try: - return bytes2integer(data, self.signed) + return int.from_bytes(data, byteorder='big', signed=self.signed) except ValueError as e: raise IntegerError(str(e), path=path) @@ -248,7 +248,7 @@ class GreedyInteger(Construct): raise IntegerError(f"value {obj} is not an integer", path=path) length = self.__bytes_required(obj, self.minlen) try: - data = integer2bytes(obj, length, self.signed) + data = obj.to_bytes(length, byteorder='big', signed=self.signed) except ValueError as e: raise IntegerError(str(e), path=path) if evaluate(self.swapped, context):