From 191113baee3431e905194485e74d44f8b99a7f17 Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Thu, 7 May 2026 14:18:16 +0200 Subject: [PATCH] card_key_provider: add a static method to parse --column-keys args The contents of the --column-keys arguments are currently parsed in init_card_key_provider. Let's add a static method in CardKeyFieldCryptor to simplify re-usage of the CardKeyFieldCryptor Related: SYS#6959 --- pySim/card_key_provider.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/pySim/card_key_provider.py b/pySim/card_key_provider.py index ecf8c400..7c89b6b9 100644 --- a/pySim/card_key_provider.py +++ b/pySim/card_key_provider.py @@ -140,6 +140,23 @@ class CardKeyFieldCryptor: arg_parser.add_argument('--csv-column-key', metavar='FIELD:AES_KEY_HEX', default=[], action='append', help=argparse.SUPPRESS, dest='column_key') + @staticmethod + def transport_keys_from_opts(opts: argparse.Namespace) -> dict: + """ + Transport keys are passed via the commandline using the '--column-key' option. Each column requires a + dedicated transport key. This method can be used to extract the column keys parameters from the commandline + options into a dict that can be directly passed to the construtor with the transport_keys argument. + + Args: + opts: parsed commandline options (Namespace) + """ + + transport_keys = {} + for par in opts.column_key: + name, key = par.split(':') + transport_keys[name] = key + return transport_keys + class CardKeyProvider(abc.ABC): """Base class, not containing any concrete implementation.""" @@ -343,10 +360,7 @@ def argparse_add_card_key_provider_args(arg_parser: argparse.ArgumentParser): def init_card_key_provider(opts: argparse.Namespace): """Initialize card key provider depending on the user provided commandline options""" - column_keys = {} - for par in opts.column_key: - name, key = par.split(':') - column_keys[name] = key + transport_keys = CardKeyFieldCryptor.transport_keys_from_opts(opts) card_key_field_cryptor = CardKeyFieldCryptor(transport_keys) if os.path.isfile(os.path.expanduser(opts.csv)): card_key_provider_register(CardKeyProviderCsv(os.path.expanduser(opts.csv), card_key_field_cryptor))