laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/40120?usp=email )
Change subject: Use osmocom.construct.{Bytes,GreedyBytes} for hexstring input support ......................................................................
Use osmocom.construct.{Bytes,GreedyBytes} for hexstring input support
The upstream construct.{Bytes,GreedyBytes} only support bytes/bytearray input data for the encoder, while the [newly-created] osmocom.construct.{Bytes,GreedyBytes} support alternatively hex-string input.
This is important in the context of encoding construct-based types from JSON, where our osmocom.utils.JsonEncoder will automatically convert any bytes to hex-string, while re-encoding those hex-strings will fail prior to this patch.
Change-Id: I1c8df6350c68aa408ec96ff6cd1e405ceb1a4fbb Closes: OS#6774 --- M pySim/apdu/__init__.py M pySim/apdu/ts_31_102.py M pySim/ara_m.py M pySim/cat.py M pySim/global_platform/http.py M pySim/global_platform/scp.py M pySim/gsm_r.py M pySim/iso7816_4.py M pySim/ota.py M pySim/sms.py M pySim/sysmocom_sja2.py M pySim/ts_31_103.py M pySim/ts_31_103_shared.py M requirements.txt M setup.py 15 files changed, 22 insertions(+), 20 deletions(-)
Approvals: laforge: Looks good to me, approved Jenkins Builder: Verified fixeria: Looks good to me, but someone else must approve
diff --git a/pySim/apdu/__init__.py b/pySim/apdu/__init__.py index 4f08113..84ac83a 100644 --- a/pySim/apdu/__init__.py +++ b/pySim/apdu/__init__.py @@ -29,7 +29,7 @@ import typing from typing import List, Dict, Optional from termcolor import colored -from construct import Byte, GreedyBytes +from construct import Byte from construct import Optional as COptional from osmocom.construct import * from osmocom.utils import * diff --git a/pySim/apdu/ts_31_102.py b/pySim/apdu/ts_31_102.py index fea5038..692cdfd 100644 --- a/pySim/apdu/ts_31_102.py +++ b/pySim/apdu/ts_31_102.py @@ -9,7 +9,7 @@ """ from typing import Dict
-from construct import BitStruct, Enum, BitsInteger, Int8ub, Bytes, this, Struct, If, Switch, Const +from construct import BitStruct, Enum, BitsInteger, Int8ub, this, Struct, If, Switch, Const from construct import Optional as COptional from osmocom.construct import *
diff --git a/pySim/ara_m.py b/pySim/ara_m.py index e10ae10..9079a97 100644 --- a/pySim/ara_m.py +++ b/pySim/ara_m.py @@ -26,7 +26,7 @@ #
-from construct import GreedyBytes, GreedyString, Struct, Enum, Int8ub, Int16ub +from construct import GreedyString, Struct, Enum, Int8ub, Int16ub from construct import Optional as COptional from osmocom.construct import * from osmocom.tlv import * diff --git a/pySim/cat.py b/pySim/cat.py index 448d874..ae4e06e 100644 --- a/pySim/cat.py +++ b/pySim/cat.py @@ -20,11 +20,11 @@
from typing import List from bidict import bidict -from construct import Int8ub, Int16ub, Byte, Bytes, BitsInteger +from construct import Int8ub, Int16ub, Byte, BitsInteger from construct import Struct, Enum, BitStruct, this -from construct import GreedyBytes, Switch, GreedyRange, FlagsEnum +from construct import Switch, GreedyRange, FlagsEnum from osmocom.tlv import TLV_IE, COMPR_TLV_IE, BER_TLV_IE, TLV_IE_Collection -from osmocom.construct import PlmnAdapter, BcdAdapter, HexAdapter, GsmStringAdapter, TonNpi, GsmString +from osmocom.construct import PlmnAdapter, BcdAdapter, HexAdapter, GsmStringAdapter, TonNpi, GsmString, Bytes, GreedyBytes from osmocom.utils import b2h from pySim.utils import dec_xplmn_w_act
diff --git a/pySim/global_platform/http.py b/pySim/global_platform/http.py index dee196d..dbad9ac 100644 --- a/pySim/global_platform/http.py +++ b/pySim/global_platform/http.py @@ -17,9 +17,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from construct import Struct, Int8ub, Int16ub, Bytes, GreedyBytes, GreedyString, BytesInteger +from construct import Struct, Int8ub, Int16ub, GreedyString, BytesInteger from construct import this, len_, Rebuild, Const from construct import Optional as COptional +from osmocom.construct import Bytes, GreedyBytes from osmocom.tlv import BER_TLV_IE
from pySim import cat diff --git a/pySim/global_platform/scp.py b/pySim/global_platform/scp.py index 72aed24..e674766 100644 --- a/pySim/global_platform/scp.py +++ b/pySim/global_platform/scp.py @@ -20,8 +20,9 @@ from typing import Optional from Cryptodome.Cipher import DES3, DES from Cryptodome.Util.strxor import strxor -from construct import Struct, Bytes, Int8ub, Int16ub, Const +from construct import Struct, Int8ub, Int16ub, Const from construct import Optional as COptional +from osmocom.construct import Bytes from osmocom.utils import b2h from osmocom.tlv import bertlv_parse_len, bertlv_encode_len from pySim.utils import parse_command_apdu diff --git a/pySim/gsm_r.py b/pySim/gsm_r.py index bc54c72..5798df7 100644 --- a/pySim/gsm_r.py +++ b/pySim/gsm_r.py @@ -26,7 +26,7 @@
from pySim.utils import * from struct import pack, unpack -from construct import Struct, Bytes, Int8ub, Int16ub, Int24ub, Int32ub, FlagsEnum +from construct import Struct, Int8ub, Int16ub, Int24ub, Int32ub, FlagsEnum from construct import Optional as COptional from osmocom.construct import *
diff --git a/pySim/iso7816_4.py b/pySim/iso7816_4.py index ae0c2c8..e9501aa 100644 --- a/pySim/iso7816_4.py +++ b/pySim/iso7816_4.py @@ -17,7 +17,7 @@ along with this program. If not, see http://www.gnu.org/licenses/. """
-from construct import GreedyBytes, GreedyString +from construct import GreedyString from osmocom.tlv import * from osmocom.construct import *
diff --git a/pySim/ota.py b/pySim/ota.py index 2d1c8d1..a6b563d 100644 --- a/pySim/ota.py +++ b/pySim/ota.py @@ -19,7 +19,7 @@ import abc import struct from typing import Optional, Tuple -from construct import Enum, Int8ub, Int16ub, Struct, Bytes, GreedyBytes, BitsInteger, BitStruct +from construct import Enum, Int8ub, Int16ub, Struct, BitsInteger, BitStruct from construct import Flag, Padding, Switch, this, PrefixedArray, GreedyRange from osmocom.construct import * from osmocom.utils import b2h diff --git a/pySim/sms.py b/pySim/sms.py index 7e5acf1..7c22c75 100644 --- a/pySim/sms.py +++ b/pySim/sms.py @@ -20,10 +20,10 @@ import typing import abc from bidict import bidict -from construct import Int8ub, Byte, Bytes, Bit, Flag, BitsInteger +from construct import Int8ub, Byte, Bit, Flag, BitsInteger from construct import Struct, Enum, Tell, BitStruct, this, Padding -from construct import Prefixed, GreedyRange, GreedyBytes -from osmocom.construct import HexAdapter, BcdAdapter, TonNpi +from construct import Prefixed, GreedyRange +from osmocom.construct import HexAdapter, BcdAdapter, TonNpi, Bytes, GreedyBytes from osmocom.utils import Hexstr, h2b, b2h
from smpp.pdu import pdu_types, operations diff --git a/pySim/sysmocom_sja2.py b/pySim/sysmocom_sja2.py index c145f0f..438df23 100644 --- a/pySim/sysmocom_sja2.py +++ b/pySim/sysmocom_sja2.py @@ -18,7 +18,7 @@ """
from struct import unpack -from construct import FlagsEnum, Byte, Struct, Int8ub, Bytes, Mapping, Enum, Padding, BitsInteger +from construct import FlagsEnum, Byte, Struct, Int8ub, Mapping, Enum, Padding, BitsInteger from construct import Bit, this, Int32ub, Int16ub, Nibble, BytesInteger, GreedyRange, Const from construct import Optional as COptional from osmocom.utils import * diff --git a/pySim/ts_31_103.py b/pySim/ts_31_103.py index c0142bc..b281659 100644 --- a/pySim/ts_31_103.py +++ b/pySim/ts_31_103.py @@ -22,7 +22,7 @@ # along with this program. If not, see http://www.gnu.org/licenses/. #
-from construct import Struct, Switch, this, Bytes, GreedyString +from construct import Struct, Switch, this, GreedyString from osmocom.utils import * from osmocom.tlv import * from osmocom.construct import * diff --git a/pySim/ts_31_103_shared.py b/pySim/ts_31_103_shared.py index 25f3e97..8c56923 100644 --- a/pySim/ts_31_103_shared.py +++ b/pySim/ts_31_103_shared.py @@ -19,9 +19,9 @@ # along with this program. If not, see http://www.gnu.org/licenses/. #
-from construct import Struct, Switch, Bytes, GreedyString, GreedyBytes, Int8ub, Prefixed, Enum, Byte +from construct import Struct, Switch, GreedyString, Int8ub, Prefixed, Enum, Byte from osmocom.tlv import BER_TLV_IE, TLV_IE_Collection -from osmocom.construct import HexAdapter, Utf8Adapter +from osmocom.construct import Bytes, HexAdapter, Utf8Adapter, GreedyBytes from pySim.filesystem import *
# TS 31.103 Section 4.2.16 diff --git a/requirements.txt b/requirements.txt index 11170da..9749d7f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ jsonpath-ng construct>=2.10.70 bidict -pyosmocom>=0.0.8 +pyosmocom>=0.0.9 pyyaml>=5.1 termcolor colorlog diff --git a/setup.py b/setup.py index bf9299c..b33fb67 100644 --- a/setup.py +++ b/setup.py @@ -25,7 +25,7 @@ "jsonpath-ng", "construct >= 2.10.70", "bidict", - "pyosmocom >= 0.0.8", + "pyosmocom >= 0.0.9", "pyyaml >= 5.1", "termcolor", "colorlog",