diff options
author | Vadim Yanitskiy <vyanitskiy@sysmocom.de> | 2022-08-29 20:24:44 +0700 |
---|---|---|
committer | Vadim Yanitskiy <vyanitskiy@sysmocom.de> | 2022-09-05 23:15:10 +0700 |
commit | 05d30eb666923a1a9cec08f7c0bced7f297fd02b (patch) | |
tree | 359d240710e6e07834dd809409a94f5adb653c05 /pySim/construct.py | |
parent | 7800f9d356d07728a8763464903d17256b120344 (diff) |
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
Diffstat (limited to 'pySim/construct.py')
-rw-r--r-- | pySim/construct.py | 6 |
1 files changed, 3 insertions, 3 deletions
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.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): |