mirror of https://gerrit.osmocom.org/pysim
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#5666changes/26/29226/3
parent
7800f9d356
commit
05d30eb666
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue