fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/29226 )
Change subject: construct: use Python's API for int<->bytes conversion ......................................................................
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 --- M pySim/construct.py 1 file changed, 3 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/26/29226/1
diff --git a/pySim/construct.py b/pySim/construct.py index 4910a7f..97af235 100644 --- a/pySim/construct.py +++ b/pySim/construct.py @@ -2,7 +2,7 @@ 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 @@ 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 @@ 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):