From a5eb924f9efdfe2bd74f406a7172fd526877a394 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 23 Dec 2023 10:20:20 +0100 Subject: [PATCH] filesystem: use pySim.utils.build_construct() We recently introduced a pySim.utils.build_construct() wrapper around the raw call of the construct.build() method. So far, this wrapper was only used from pySim.tlv, but let's also use it from pySim.filesystem. Basically, whenever we use parse_construct(), we should use build_construct() as the inverse operation. Change-Id: Ibfd61cd87edc72882aa66d6ff17861a3e918affb --- pySim/filesystem.py | 14 +++++++------- pySim/sysmocom_sja2.py | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pySim/filesystem.py b/pySim/filesystem.py index 0e72921a..438e9690 100644 --- a/pySim/filesystem.py +++ b/pySim/filesystem.py @@ -39,7 +39,7 @@ from typing import cast, Optional, Iterable, List, Dict, Tuple, Union from smartcard.util import toBytes from pySim.utils import sw_match, h2b, b2h, i2h, is_hex, auto_int, bertlv_parse_one, Hexstr -from pySim.construct import filter_dict, parse_construct +from pySim.construct import filter_dict, parse_construct, build_construct from pySim.exceptions import * from pySim.jsonpath import js_path_find, js_path_modify from pySim.commands import SimCardCommands @@ -749,7 +749,7 @@ class TransparentEF(CardEF): if callable(method): return h2b(method(abstract_data)) if self._construct: - return self._construct.build(abstract_data) + return build_construct(self._construct, abstract_data) elif self._tlv: t = self._tlv() if inspect.isclass(self._tlv) else self._tlv t.from_dict(abstract_data) @@ -777,7 +777,7 @@ class TransparentEF(CardEF): raw_bin_data = method(abstract_data) return b2h(raw_bin_data) if self._construct: - return b2h(self._construct.build(abstract_data)) + return b2h(build_construct(self._construct, abstract_data)) elif self._tlv: t = self._tlv() if inspect.isclass(self._tlv) else self._tlv t.from_dict(abstract_data) @@ -1025,7 +1025,7 @@ class LinFixedEF(CardEF): raw_bin_data = method(abstract_data, record_nr=record_nr) return b2h(raw_bin_data) if self._construct: - return b2h(self._construct.build(abstract_data)) + return b2h(build_construct(self._construct, abstract_data)) elif self._tlv: t = self._tlv() if inspect.isclass(self._tlv) else self._tlv t.from_dict(abstract_data) @@ -1053,7 +1053,7 @@ class LinFixedEF(CardEF): if callable(method): return h2b(method(abstract_data, record_nr=record_nr)) if self._construct: - return self._construct.build(abstract_data) + return build_construct(self._construct, abstract_data) elif self._tlv: t = self._tlv() if inspect.isclass(self._tlv) else self._tlv t.from_dict(abstract_data) @@ -1169,7 +1169,7 @@ class TransRecEF(TransparentEF): if callable(method): return b2h(method(abstract_data)) if self._construct: - return b2h(filter_dict(self._construct.build(abstract_data))) + return b2h(filter_dict(build_construct(self._construct, abstract_data))) elif self._tlv: t = self._tlv() if inspect.isclass(self._tlv) else self._tlv t.from_dict(abstract_data) @@ -1196,7 +1196,7 @@ class TransRecEF(TransparentEF): if callable(method): return h2b(method(abstract_data)) if self._construct: - return filter_dict(self._construct.build(abstract_data)) + return filter_dict(build_construct(self._construct, abstract_data)) elif self._tlv: t = self._tlv() if inspect.isclass(self._tlv) else self._tlv t.from_dict(abstract_data) diff --git a/pySim/sysmocom_sja2.py b/pySim/sysmocom_sja2.py index 8d3750c4..a25becef 100644 --- a/pySim/sysmocom_sja2.py +++ b/pySim/sysmocom_sja2.py @@ -237,9 +237,9 @@ class EF_USIM_AUTH_KEY(TransparentEF): def _encode_bin(self, abstract_data: dict) -> bytearray: if abstract_data['cfg']['algorithm'] == 'tuak': - return self._constr_tuak.build(abstract_data) + return build_construct(self._constr_tuak, abstract_data) else: - return self._construct.build(abstract_data) + return build_construct(self._construct, abstract_data) class EF_USIM_AUTH_KEY_2G(TransparentEF):