Change in pysim[master]: rename card_data to card_key_provider.

laforge gerrit-no-reply at lists.osmocom.org
Sat Apr 3 09:35:30 UTC 2021


laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/23591 )


Change subject: rename card_data to card_key_provider.
......................................................................

rename card_data to card_key_provider.

"data" is an awfully generic term.  Anything stored on a card is data.

This specific code deals with resolving key/pin material from an
external source.

Change-Id: I4c8e1be3e766f7c0565c07b39d48abf8adc375af
---
M pySim-shell.py
R pySim/card_key_provider.py
2 files changed, 14 insertions(+), 14 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/91/23591/1

diff --git a/pySim-shell.py b/pySim-shell.py
index 931b5ea..d27deb7 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -48,7 +48,7 @@
 from pySim.ts_31_102 import CardApplicationUSIM
 from pySim.ts_31_103 import CardApplicationISIM
 
-from pySim.card_data import CardDataCsv, card_data_register, card_data_get_field
+from pySim.card_key_provider import CardKeyProviderCsv, card_key_provider_register, card_key_provider_get_field
 
 
 class PysimApp(cmd2.Cmd):
@@ -95,7 +95,7 @@
 			pin_adm = sanitize_pin_adm(arg)
 		else:
 			# try to find an ADM-PIN if none is specified
-			result = card_data_get_field('ADM1', key='ICCID', value=self.iccid)
+			result = card_key_provider_get_field('ADM1', key='ICCID', value=self.iccid)
 			pin_adm = sanitize_pin_adm(result)
 			if pin_adm:
 				self.poutput("found ADM-PIN '%s' for ICCID '%s'" % (result, self.iccid))
@@ -148,7 +148,7 @@
 		if str(code).upper() not in auto:
 			return sanitize_pin_adm(code)
 
-		result = card_data_get_field(str(code), key='ICCID', value=self._cmd.iccid)
+		result = card_key_provider_get_field(str(code), key='ICCID', value=self._cmd.iccid)
 		result = sanitize_pin_adm(result)
 		if result:
 			self._cmd.poutput("found %s '%s' for ICCID '%s'" % (code.upper(), result, self._cmd.iccid))
@@ -439,9 +439,9 @@
 	# or from CSV file in home directory
 	csv_default = str(Path.home()) + "/.osmocom/pysim/card_data.csv"
 	if opts.csv:
-		card_data_register(CardDataCsv(opts.csv))
+		card_key_provider_register(CardKeyProviderCsv(opts.csv))
 	if os.path.isfile(csv_default):
-		card_data_register(CardDataCsv(csv_default))
+		card_key_provider_register(CardKeyProviderCsv(csv_default))
 
 	# If the user supplies an ADM PIN at via commandline args authenticate
 	# immediatley so that the user does not have to use the shell commands
diff --git a/pySim/card_data.py b/pySim/card_key_provider.py
similarity index 86%
rename from pySim/card_data.py
rename to pySim/card_key_provider.py
index c6820c1..80f93d0 100644
--- a/pySim/card_data.py
+++ b/pySim/card_key_provider.py
@@ -23,9 +23,9 @@
 
 import csv
 
-card_data_provider = List[CardData]
+card_key_providers = List[CardKeyProvider]
 
-class CardData(object):
+class CardKeyProvider(object):
 
 	VALID_FIELD_NAMES = ['ICCID', 'ADM1', 'IMSI', 'PIN1', 'PIN2', 'PUK1', 'PUK2']
 
@@ -54,7 +54,7 @@
 		"""get fields from CSV file using a specified key/value pair"""
 		pass
 
-class CardDataCsv(CardData):
+class CardKeyProviderCsv(CardKeyProvider):
 	"""card data class that allows the user to query against a specified CSV file"""
 	csv_file = None
 	filename = None
@@ -87,17 +87,17 @@
 		return rc
 
 
-def card_data_register(provider:CardData, provider_list=card_data_provider):
+def card_key_provider_register(provider:CardKeyProvider, provider_list=card_key_providers):
 	"""Register a new card data provider"""
-	if not isinstance(provider, CardData):
+	if not isinstance(provider, CardKeyProvider):
 		raise ValueError("provider is not a card data provier")
 	provider_list.append(provider)
 
 
-def card_data_get(fields, key:str, value:str, provider_list=card_data_provider) -> Dict[str,str]:
+def card_key_provider_get(fields, key:str, value:str, provider_list=card_key_providers) -> Dict[str,str]:
 	"""Query all registered card data providers"""
 	for p in provider_list:
-		if not isinstance(p, CardData):
+		if not isinstance(p, CardKeyProvider):
 			raise ValueError("provider list contains provider, which is not a card data provier")
 		result = p.get(fields, key, value)
 		if result:
@@ -105,10 +105,10 @@
 	return {}
 
 
-def card_data_get_field(field:str, key:str, value:str, provider_list=card_data_provider) -> Optional[str]:
+def card_key_provider_get_field(field:str, key:str, value:str, provider_list=card_key_providers) -> Optional[str]:
 	"""Query all registered card data providers for a single field"""
 	for p in provider_list:
-		if not isinstance(p, CardData):
+		if not isinstance(p, CardKeyProvider):
 			raise ValueError("provider list contains provider, which is not a card data provier")
 		result = p.get_field(field, key, value)
 		if result:

-- 
To view, visit https://gerrit.osmocom.org/c/pysim/+/23591
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I4c8e1be3e766f7c0565c07b39d48abf8adc375af
Gerrit-Change-Number: 23591
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210403/5af6257c/attachment.htm>


More information about the gerrit-log mailing list